require 'puppetlabs_spec_helper/module_spec_helper'
+require 'rspec-puppet-facts'
+include RspecPuppetFacts
# Customize filters to ignore 3rd-party code
# If the coverage report shows not-our-code results, add it here
'Exec[opendaylight-systemd unpack]',
'Exec[rm-on-error-opendaylight.tar.gz]',
'Exec[rm-on-error-opendaylight-systemd.tar.gz]',
+ 'Exec[reload_systemd_units]',
'Exec[update-java-alternatives]',
'Package[curl]',
'Stage[deploy]',
it { should contain_class('opendaylight::service') }
# Confirm relationships between classes
- it { should contain_class('opendaylight::install').that_comes_before('opendaylight::config') }
- it { should contain_class('opendaylight::config').that_requires('opendaylight::install') }
- it { should contain_class('opendaylight::config').that_notifies('opendaylight::service') }
- it { should contain_class('opendaylight::service').that_subscribes_to('opendaylight::config') }
- it { should contain_class('opendaylight::service').that_comes_before('opendaylight') }
- it { should contain_class('opendaylight').that_requires('opendaylight::service') }
+ it { should contain_class('opendaylight::install').that_comes_before('Class[opendaylight::config]') }
+ it { should contain_class('opendaylight::config').that_requires('Class[opendaylight::install]') }
+ it { should contain_class('opendaylight::config').that_notifies('Class[opendaylight::service]') }
+ it { should contain_class('opendaylight::service').that_subscribes_to('Class[opendaylight::config]') }
+ it { should contain_class('opendaylight::service').that_comes_before('Class[opendaylight]') }
+ it { should contain_class('opendaylight').that_requires('Class[opendaylight::service]') }
# Confirm presence of generic resources
it { should contain_service('opendaylight') }
if log_levels.empty?
# Should contain log level config file
it {
- should contain_file('org.ops4j.pax.logging.cfg').with(
- 'ensure' => 'file',
- 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
- 'owner' => 'odl',
- 'group' => 'odl',
- )
- }
- # Should not contain custom log level config
- it {
- should_not contain_file('org.ops4j.pax.logging.cfg').with(
- 'ensure' => 'file',
- 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
- 'owner' => 'odl',
- 'group' => 'odl',
- 'content' => /# Log level config added by puppet-opendaylight/
- )
+ should_not contain_file_line('logger-org.opendaylight.ovsdb')
}
else
- # Should contain log level config file
- it {
- should contain_file('org.ops4j.pax.logging.cfg').with(
- 'ensure' => 'file',
- 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
- 'owner' => 'odl',
- 'group' => 'odl',
- )
- }
- # Should contain custom log level config
- it {
- should contain_file('org.ops4j.pax.logging.cfg').with(
- 'ensure' => 'file',
- 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
- 'owner' => 'odl',
- 'group' => 'odl',
- 'content' => /# Log level config added by puppet-opendaylight/
- )
- }
# Verify each custom log level config entry
log_levels.each_pair do |logger, level|
it {
- should contain_file('org.ops4j.pax.logging.cfg').with(
- 'ensure' => 'file',
- 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
- 'owner' => 'odl',
- 'group' => 'odl',
- 'content' => /^log4j.logger.#{logger} = #{level}/
+ should contain_file_line("logger-#{logger}").with(
+ 'ensure' => 'present',
+ 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+ 'line' => "log4j.logger.#{logger}=#{level}",
)
}
end
end
end
-# Shared tests that specialize in testing enabling L3 via ODL OVSDB
-def enable_l3_tests(options = {})
+def enable_ha_tests(options = {})
# Extract params
- # NB: This default value should be the same as one in opendaylight::params
- # TODO: Remove this possible source of bugs^^
- enable_l3 = options.fetch(:enable_l3, 'no')
+ enable_ha = options.fetch(:enable_ha, false)
+ odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
+ ha_node_ips = options.fetch(:ha_node_ips, [])
+ ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
+ # HA_NODE_IPS size
+ ha_node_count = ha_node_ips.size
- if [true, 'yes'].include? enable_l3
- # Confirm ODL OVSDB L3 is enabled
- it {
- should contain_file('custom.properties').with(
- 'ensure' => 'file',
- 'path' => '/opt/opendaylight/etc/custom.properties',
- 'owner' => 'odl',
- 'group' => 'odl',
- 'content' => /^ovsdb.l3.fwd.enabled=yes/
- )
- }
- elsif [false, 'no'].include? enable_l3
- # Confirm ODL OVSDB L3 is disabled
- it {
- should contain_file('custom.properties').with(
- 'ensure' => 'file',
- 'path' => '/opt/opendaylight/etc/custom.properties',
- 'owner' => 'odl',
- 'group' => 'odl',
- 'content' => /^ovsdb.l3.fwd.enabled=no/
- )
- }
+ if (enable_ha) && (ha_node_count < 2)
+ # Check for HA_NODE_COUNT < 2
+ fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
end
-end
-
-def tarball_install_tests(options = {})
- # Extract params
- # NB: These default values should be the same as ones in opendaylight::params
- # TODO: Remove this possible source of bugs^^
- tarball_url = options.fetch(:tarball_url, 'https://nexus.opendaylight.org/content/repositories/staging/org/opendaylight/integration/distribution-karaf/0.4.0-Beryllium-RC2/distribution-karaf-0.4.0-Beryllium-RC2.tar.gz')
- unitfile_url = options.fetch(:unitfile_url, 'https://github.com/dfarrell07/opendaylight-systemd/archive/master/opendaylight-unitfile.tar.gz')
- osfamily = options.fetch(:osfamily, 'RedHat')
-
- # Confirm presence of tarball-related resources
- it { should contain_archive('opendaylight') }
- it { should contain_class('java') }
- it { should contain_file('/opt/opendaylight/') }
- it { should contain_user('odl') }
- it { should contain_group('odl') }
-
- # Confirm relationships between tarball-related resources
- it { should contain_archive('opendaylight').that_comes_before('File[/opt/opendaylight/]') }
- it { should contain_archive('opendaylight').that_comes_before('User[odl]') }
- it { should contain_file('/opt/opendaylight/').that_requires('Archive[opendaylight]') }
- it { should contain_file('/opt/opendaylight/').that_requires('Group[odl]') }
- it { should contain_file('/opt/opendaylight/').that_requires('User[odl]') }
- it { should contain_user('odl').that_comes_before('File[/opt/opendaylight/]') }
- it { should contain_user('odl').that_requires('Archive[opendaylight]') }
- it { should contain_user('odl').that_requires('Group[odl]') }
- it { should contain_group('odl').that_comes_before('File[/opt/opendaylight/]') }
- it { should contain_group('odl').that_comes_before('User[odl]') }
-
- # Confirm properties of tarball-related resources
- # NB: These hashes don't work with Ruby 1.8.7, but we
- # don't support 1.8.7 so that's okay. See issue #36.
- it {
- should contain_archive('opendaylight').with(
- 'ensure' => 'present',
- 'url' => tarball_url,
- 'target' => '/opt/opendaylight/',
- 'checksum' => false,
- 'strip_components' => 1,
- 'timeout' => 600,
- )
- }
- it {
- should contain_file('/opt/opendaylight/').with(
- 'ensure' => 'directory',
- 'recurse' => true,
- 'owner' => 'odl',
- 'group' => 'odl',
- )
- }
- it {
- should contain_user('odl').with(
- 'name' => 'odl',
- 'ensure' => 'present',
- 'home' => '/opt/opendaylight/',
- 'membership' => 'minimum',
- 'groups' => 'odl',
- )
- }
- it {
- should contain_group('odl').with(
- 'name' => 'odl',
- 'ensure' => 'present',
- )
- }
-
- # OS-specific validations
- case osfamily
- when 'RedHat'
- # Validations specific to Red Hat family OSs (RHEL/CentOS/Fedora)
- it { should contain_archive('opendaylight-systemd') }
- it { should contain_file('/usr/lib/systemd/system/opendaylight.service') }
- it { should contain_archive('opendaylight-systemd').that_comes_before('File[/usr/lib/systemd/system/opendaylight.service]') }
- it { should contain_file('/usr/lib/systemd/system/opendaylight.service').that_requires('Archive[opendaylight-systemd]') }
- # NB: These hashes don't work with Ruby 1.8.7, but we
- # don't support 1.8.7 so that's okay. See issue #36.
+ if enable_ha
+ ha_node_index = ha_node_ips.index(odl_bind_ip)
it {
- should contain_package('java').with(
- 'name' => 'java-1.7.0-openjdk',
- )
- }
- it {
- should contain_archive('opendaylight-systemd').with(
- 'ensure' => 'present',
- 'url' => unitfile_url,
- 'target' => '/usr/lib/systemd/system/',
- 'root_dir' => 'opendaylight.service',
- 'checksum' => false,
- 'strip_components' => 1,
- 'follow_redirects' => true,
- )
- }
- it {
- should contain_file('/usr/lib/systemd/system/opendaylight.service').with(
+ should contain_file('akka.conf').with(
+ 'path' => '/opt/opendaylight/configuration/initial/akka.conf',
'ensure' => 'file',
- 'owner' => 'root',
- 'group' => 'root',
- 'mode' => '0644',
- )
- }
- when 'Debian'
- # Validations specific to Debain family OSs (Ubuntu)
- it {
- should contain_package('java').with(
- 'name' => 'openjdk-7-jdk',
+ 'owner' => 'odl',
+ 'group' => 'odl',
+ 'content' => /roles\s*=\s*\["member-#{ha_node_index}"\]/
)
}
- it {
- should contain_file('/etc/init/opendaylight.conf').with(
+
+ ha_db_modules.each do |mod, urn|
+ it { should contain_file('module-shards.conf').with(
+ 'path' => '/opt/opendaylight/configuration/initial/module-shards.conf',
'ensure' => 'file',
- 'owner' => 'root',
- 'group' => 'root',
- 'mode' => '0644',
- )
- }
- expected_msg = 'Debian has limited support, is less stable, less tested.'
+ 'owner' => 'odl',
+ 'group' => 'odl',
+ 'content' => /name = "#{mod}"/
+ )}
+ if mod == 'default'
+ it { should contain_file('modules.conf').with(
+ 'path' => '/opt/opendaylight/configuration/initial/modules.conf',
+ 'ensure' => 'file',
+ 'owner' => 'odl',
+ 'group' => 'odl'
+ )}
+ else
+ it { should contain_file('modules.conf').with(
+ 'path' => '/opt/opendaylight/configuration/initial/modules.conf',
+ 'ensure' => 'file',
+ 'owner' => 'odl',
+ 'group' => 'odl',
+ 'content' => /name = "#{mod}"/,
+ )}
+ end
+ end
+ else
it {
- expect {
- # This could be any check, most (all?) will raise warning
- should contain_file('/etc/init/opendaylight.conf').to(
- raise_warning(Puppet::Warning, /#{expected_msg}/)
- )
+ should_not contain_file('akka.conf')
+ should_not contain_file('module-shards.conf')
+ should_not contain_file('modules.conf')
}
- }
- else
- fail("Unexpected osfamily #{osfamily}")
end
-
- # Verify that there are no unexpected resources from RPM-type installs
- it { should_not contain_yumrepo('opendaylight-4-testing') }
- it { should_not contain_package('opendaylight') }
end
def rpm_install_tests(options = {})
# Extract params
- # Choose Yum URL based on OS (CentOS vs Fedora)
- # NB: Currently using the CentOS CBS for both Fedora and CentOS
- operatingsystem = options.fetch(:operatingsystem, 'CentOS')
- case operatingsystem
- when 'CentOS'
- yum_repo = 'http://cbs.centos.org/repos/nfv7-opendaylight-4-testing/$basearch/os/'
- when 'Fedora'
- yum_repo = 'http://cbs.centos.org/repos/nfv7-opendaylight-4-testing/$basearch/os/'
- else
- fail("Unknown operatingsystem: #{operatingsystem}")
- end
+ rpm_repo = options.fetch(:rpm_repo, 'opendaylight-6-testing')
+ java_opts = options.fetch(:java_opts, '-Djava.net.preferIPv4Stack=true')
# Default to CentOS 7 Yum repo URL
# Confirm presence of RPM-related resources
- it { should contain_yumrepo('opendaylight-4-testing') }
+ it { should contain_yumrepo(rpm_repo) }
it { should contain_package('opendaylight') }
# Confirm relationships between RPM-related resources
- it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight-4-testing]') }
- it { should contain_yumrepo('opendaylight-4-testing').that_comes_before('Package[opendaylight]') }
+ it { should contain_package('opendaylight').that_requires("Yumrepo[#{rpm_repo}]") }
+ it { should contain_yumrepo(rpm_repo).that_comes_before('Package[opendaylight]') }
# Confirm properties of RPM-related resources
# NB: These hashes don't work with Ruby 1.8.7, but we
# don't support 1.8.7 so that's okay. See issue #36.
it {
- should contain_yumrepo('opendaylight-4-testing').with(
+ should contain_yumrepo(rpm_repo).with(
'enabled' => '1',
'gpgcheck' => '0',
- 'descr' => 'CentOS CBS OpenDaylight Berillium testing repository',
- 'baseurl' => yum_repo,
+ 'descr' => 'OpenDaylight SDN Controller',
+ 'baseurl' => "http://cbs.centos.org/repos/nfv7-#{rpm_repo}/$basearch/os/",
+ )
+ }
+ it {
+ should contain_package('opendaylight').with(
+ 'ensure' => 'present',
)
}
+
+ it {
+ should contain_file_line('java_options_systemd').with(
+ 'ensure' => 'present',
+ 'path' => '/usr/lib/systemd/system/opendaylight.service',
+ 'line' => "Environment=_JAVA_OPTIONS=\'#{java_opts}\'",
+ 'after' => 'ExecStart=/opt/opendaylight/bin/start',
+ )
+ }
+end
+
+def deb_install_tests(options = {})
+ # Extract params
+ deb_repo = options.fetch(:deb_repo, 'ppa:odl-team/carbon')
+
+ # Confirm the presence of Deb-related resources
+ it { should contain_apt__ppa(deb_repo) }
+ it { should contain_package('opendaylight') }
+
+ # Confirm relationships between Deb-related resources
+ it { should contain_package('opendaylight').that_requires("Apt::Ppa[#{deb_repo}]") }
+ it { should contain_apt__ppa(deb_repo).that_comes_before('Package[opendaylight]') }
+
+ # Confirm presence of Deb-related resources
it {
should contain_package('opendaylight').with(
'ensure' => 'present',
def unsupported_os_tests(options = {})
# Extract params
expected_msg = options.fetch(:expected_msg)
+ rpm_repo = options.fetch(:rpm_repo, 'opendaylight-6-testing')
# Confirm that classes fail on unsupported OSs
it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
# Confirm that other resources fail on unsupported OSs
- it { expect { should contain_yumrepo('opendaylight-4-testing') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
+ it { expect { should contain_yumrepo(rpm_repo) }.to raise_error(Puppet::Error, /#{expected_msg}/) }
it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
end
+
+# Shared tests that specialize in testing security group mode
+def enable_sg_tests(sg_mode='stateful', os_release)
+ # Extract params
+ # NB: This default value should be the same as one in opendaylight::params
+ # TODO: Remove this possible source of bugs^^
+
+ it { should contain_file('/opt/opendaylight/etc/opendaylight') }
+ it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore')}
+ it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial')}
+ it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial/config')}
+
+ if os_release != '7.3' and sg_mode == 'stateful'
+ # Confirm sg_mode becomes learn
+ it {
+ should contain_file('netvirt-aclservice-config.xml').with(
+ 'ensure' => 'file',
+ 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-aclservice-config.xml',
+ 'owner' => 'odl',
+ 'group' => 'odl',
+ 'content' => /learn/
+ )
+ }
+ else
+ # Confirm other sg_mode is passed correctly
+ it {
+ should contain_file('netvirt-aclservice-config.xml').with(
+ 'ensure' => 'file',
+ 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-aclservice-config.xml',
+ 'owner' => 'odl',
+ 'group' => 'odl',
+ 'content' => /#{sg_mode}/
+ )
+ }
+ end
+end
+
+# Shared tests that specialize in testing VPP routing node config
+def vpp_routing_node_tests(options = {})
+ # Extract params
+ # NB: This default list should be the same as the one in opendaylight::params
+ # TODO: Remove this possible source of bugs^^
+ routing_node = options.fetch(:routing_node, '')
+
+ if routing_node.empty?
+ it { should_not contain_file('org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg') }
+ it { should_not contain_file_line('routing-node') }
+ else
+ # Confirm properties of Karaf config file
+ # NB: These hashes don't work with Ruby 1.8.7, but we
+ # don't support 1.8.7 so that's okay. See issue #36.
+ it {
+ should contain_file('org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg').with(
+ 'ensure' => 'file',
+ 'path' => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
+ 'owner' => 'odl',
+ 'group' => 'odl',
+ )
+ }
+ it {
+ should contain_file_line('routing-node').with(
+ 'path' => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
+ 'line' => "routing-node=#{routing_node}",
+ 'match' => '^routing-node=.*$',
+ )
+ }
+ end
+end
+
+# ODL username/password tests
+def username_password_tests(username, password)
+
+ it {
+ should contain_odl_user(username).with(
+ :password => password
+ )
+ }
+end