1 require 'puppetlabs_spec_helper/module_spec_helper'
3 # Customize filters to ignore 3rd-party code
4 # If the coverage report shows not-our-code results, add it here
8 'Anchor[java::begin:]',
9 'Archive::Download[opendaylight.tar.gz]',
10 'Archive::Download[opendaylight-systemd.tar.gz]',
11 'Archive::Extract[opendaylight]',
12 'Archive::Extract[opendaylight-systemd]',
13 'Class[Java::Config]',
14 'Class[Java::Params]',
15 'Class[Stdlib::Stages]',
17 'Exec[download archive opendaylight.tar.gz and check sum]',
18 'Exec[download archive opendaylight-systemd.tar.gz and check sum]',
19 'Exec[opendaylight unpack]',
20 'Exec[opendaylight-systemd unpack]',
21 'Exec[rm-on-error-opendaylight.tar.gz]',
22 'Exec[rm-on-error-opendaylight-systemd.tar.gz]',
23 'Exec[update-java-alternatives]',
27 'Stage[deploy_infra]',
32 RSpec::Puppet::Coverage.filters.push(*custom_filters)
35 # NB: This is a library of helper fns used by the rspec-puppet tests
38 # Tests that are common to all possible configurations
40 # Confirm that module compiles
42 it { should compile.with_all_deps }
44 # Confirm presence of classes
45 it { should contain_class('opendaylight') }
46 it { should contain_class('opendaylight::params') }
47 it { should contain_class('opendaylight::install') }
48 it { should contain_class('opendaylight::config') }
49 it { should contain_class('opendaylight::service') }
51 # Confirm relationships between classes
52 it { should contain_class('opendaylight::install').that_comes_before('opendaylight::config') }
53 it { should contain_class('opendaylight::config').that_requires('opendaylight::install') }
54 it { should contain_class('opendaylight::config').that_notifies('opendaylight::service') }
55 it { should contain_class('opendaylight::service').that_subscribes_to('opendaylight::config') }
56 it { should contain_class('opendaylight::service').that_comes_before('opendaylight') }
57 it { should contain_class('opendaylight').that_requires('opendaylight::service') }
59 # Confirm presence of generic resources
60 it { should contain_service('opendaylight') }
61 it { should contain_file('org.apache.karaf.features.cfg') }
63 # Confirm properties of generic resources
64 # NB: These hashes don't work with Ruby 1.8.7, but we
65 # don't support 1.8.7 so that's okay. See issue #36.
67 should contain_service('opendaylight').with(
68 'ensure' => 'running',
70 'hasstatus' => 'true',
71 'hasrestart' => 'true',
75 should contain_file('org.apache.karaf.features.cfg').with(
77 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
84 # Shared tests that specialize in testing Karaf feature installs
85 def karaf_feature_tests(options = {})
87 # NB: This default list should be the same as the one in opendaylight::params
88 # TODO: Remove this possible source of bugs^^
89 default_features = options.fetch(:default_features, ['config', 'standard', 'region', 'package', 'kar', 'ssh', 'management'])
90 extra_features = options.fetch(:extra_features, [])
92 # The order of this list concat matters
93 features = default_features + extra_features
94 features_csv = features.join(',')
96 # Confirm properties of Karaf features config file
97 # NB: These hashes don't work with Ruby 1.8.7, but we
98 # don't support 1.8.7 so that's okay. See issue #36.
100 should contain_file('org.apache.karaf.features.cfg').with(
102 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
108 should contain_file_line('featuresBoot').with(
109 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
110 'line' => "featuresBoot=#{features_csv}",
111 'match' => '^featuresBoot=.*$',
116 # Shared tests that specialize in testing ODL's REST port config
117 def odl_rest_port_tests(options = {})
119 # NB: This default value should be the same as one in opendaylight::params
120 # TODO: Remove this possible source of bugs^^
121 odl_rest_port = options.fetch(:odl_rest_port, 8080)
123 # Confirm properties of ODL REST port config file
124 # NB: These hashes don't work with Ruby 1.8.7, but we
125 # don't support 1.8.7 so that's okay. See issue #36.
127 should contain_file('jetty.xml').with(
129 'path' => '/opt/opendaylight/etc/jetty.xml',
132 'content' => /Property name="jetty.port" default="#{odl_rest_port}"/
137 def log_level_tests(options = {})
139 # NB: This default value should be the same as one in opendaylight::params
140 # TODO: Remove this possible source of bugs^^
141 log_levels = options.fetch(:log_levels, {})
144 # Should contain log level config file
146 should contain_file('org.ops4j.pax.logging.cfg').with(
148 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
153 # Should not contain custom log level config
155 should_not contain_file('org.ops4j.pax.logging.cfg').with(
157 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
160 'content' => /# Log level config added by puppet-opendaylight/
164 # Should contain log level config file
166 should contain_file('org.ops4j.pax.logging.cfg').with(
168 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
173 # Should contain custom log level config
175 should contain_file('org.ops4j.pax.logging.cfg').with(
177 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
180 'content' => /# Log level config added by puppet-opendaylight/
183 # Verify each custom log level config entry
184 log_levels.each_pair do |logger, level|
186 should contain_file('org.ops4j.pax.logging.cfg').with(
188 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
191 'content' => /^log4j.logger.#{logger} = #{level}/
198 # Shared tests that specialize in testing enabling L3 via ODL OVSDB
199 def enable_l3_tests(options = {})
201 # NB: This default value should be the same as one in opendaylight::params
202 # TODO: Remove this possible source of bugs^^
203 enable_l3 = options.fetch(:enable_l3, 'no')
205 if [true, 'yes'].include? enable_l3
206 # Confirm ODL OVSDB L3 is enabled
208 should contain_file('custom.properties').with(
210 'path' => '/opt/opendaylight/etc/custom.properties',
213 'content' => /^ovsdb.l3.fwd.enabled=yes/
216 elsif [false, 'no'].include? enable_l3
217 # Confirm ODL OVSDB L3 is disabled
219 should contain_file('custom.properties').with(
221 'path' => '/opt/opendaylight/etc/custom.properties',
224 'content' => /^ovsdb.l3.fwd.enabled=no/
230 def tarball_install_tests(options = {})
232 # NB: These default values should be the same as ones in opendaylight::params
233 # TODO: Remove this possible source of bugs^^
234 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')
235 unitfile_url = options.fetch(:unitfile_url, 'https://github.com/dfarrell07/opendaylight-systemd/archive/master/opendaylight-unitfile.tar.gz')
236 osfamily = options.fetch(:osfamily, 'RedHat')
238 # Confirm presence of tarball-related resources
239 it { should contain_archive('opendaylight') }
240 it { should contain_class('java') }
241 it { should contain_file('/opt/opendaylight/') }
242 it { should contain_user('odl') }
243 it { should contain_group('odl') }
245 # Confirm relationships between tarball-related resources
246 it { should contain_archive('opendaylight').that_comes_before('File[/opt/opendaylight/]') }
247 it { should contain_archive('opendaylight').that_comes_before('User[odl]') }
248 it { should contain_file('/opt/opendaylight/').that_requires('Archive[opendaylight]') }
249 it { should contain_file('/opt/opendaylight/').that_requires('Group[odl]') }
250 it { should contain_file('/opt/opendaylight/').that_requires('User[odl]') }
251 it { should contain_user('odl').that_comes_before('File[/opt/opendaylight/]') }
252 it { should contain_user('odl').that_requires('Archive[opendaylight]') }
253 it { should contain_user('odl').that_requires('Group[odl]') }
254 it { should contain_group('odl').that_comes_before('File[/opt/opendaylight/]') }
255 it { should contain_group('odl').that_comes_before('User[odl]') }
257 # Confirm properties of tarball-related resources
258 # NB: These hashes don't work with Ruby 1.8.7, but we
259 # don't support 1.8.7 so that's okay. See issue #36.
261 should contain_archive('opendaylight').with(
262 'ensure' => 'present',
263 'url' => tarball_url,
264 'target' => '/opt/opendaylight/',
266 'strip_components' => 1,
271 should contain_file('/opt/opendaylight/').with(
272 'ensure' => 'directory',
279 should contain_user('odl').with(
281 'ensure' => 'present',
282 'home' => '/opt/opendaylight/',
283 'membership' => 'minimum',
288 should contain_group('odl').with(
290 'ensure' => 'present',
294 # OS-specific validations
297 # Validations specific to Red Hat family OSs (RHEL/CentOS/Fedora)
298 it { should contain_archive('opendaylight-systemd') }
299 it { should contain_file('/usr/lib/systemd/system/opendaylight.service') }
300 it { should contain_archive('opendaylight-systemd').that_comes_before('File[/usr/lib/systemd/system/opendaylight.service]') }
301 it { should contain_file('/usr/lib/systemd/system/opendaylight.service').that_requires('Archive[opendaylight-systemd]') }
303 # NB: These hashes don't work with Ruby 1.8.7, but we
304 # don't support 1.8.7 so that's okay. See issue #36.
306 should contain_package('java').with(
307 'name' => 'java-1.7.0-openjdk',
311 should contain_archive('opendaylight-systemd').with(
312 'ensure' => 'present',
313 'url' => unitfile_url,
314 'target' => '/usr/lib/systemd/system/',
315 'root_dir' => 'opendaylight.service',
317 'strip_components' => 1,
318 'follow_redirects' => true,
322 should contain_file('/usr/lib/systemd/system/opendaylight.service').with(
330 # Validations specific to Debain family OSs (Ubuntu)
332 should contain_package('java').with(
333 'name' => 'openjdk-7-jdk',
337 should contain_file('/etc/init/opendaylight.conf').with(
344 expected_msg = 'Debian has limited support, is less stable, less tested.'
347 # This could be any check, most (all?) will raise warning
348 should contain_file('/etc/init/opendaylight.conf').to(
349 raise_warning(Puppet::Warning, /#{expected_msg}/)
354 fail("Unexpected osfamily #{osfamily}")
357 # Verify that there are no unexpected resources from RPM-type installs
358 it { should_not contain_yumrepo('opendaylight-4-testing') }
359 it { should_not contain_package('opendaylight') }
362 def rpm_install_tests(options = {})
364 # Choose Yum URL based on OS (CentOS vs Fedora)
365 # NB: Currently using the CentOS CBS for both Fedora and CentOS
366 operatingsystem = options.fetch(:operatingsystem, 'CentOS')
369 yum_repo = 'http://cbs.centos.org/repos/nfv7-opendaylight-4-testing/$basearch/os/'
371 yum_repo = 'http://cbs.centos.org/repos/nfv7-opendaylight-4-testing/$basearch/os/'
373 fail("Unknown operatingsystem: #{operatingsystem}")
376 # Default to CentOS 7 Yum repo URL
378 # Confirm presence of RPM-related resources
379 it { should contain_yumrepo('opendaylight-4-testing') }
380 it { should contain_package('opendaylight') }
382 # Confirm relationships between RPM-related resources
383 it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight-4-testing]') }
384 it { should contain_yumrepo('opendaylight-4-testing').that_comes_before('Package[opendaylight]') }
386 # Confirm properties of RPM-related resources
387 # NB: These hashes don't work with Ruby 1.8.7, but we
388 # don't support 1.8.7 so that's okay. See issue #36.
390 should contain_yumrepo('opendaylight-4-testing').with(
393 'descr' => 'CentOS CBS OpenDaylight Berillium testing repository',
394 'baseurl' => yum_repo,
398 should contain_package('opendaylight').with(
399 'ensure' => 'present',
404 # Shared tests for unsupported OSs
405 def unsupported_os_tests(options = {})
407 expected_msg = options.fetch(:expected_msg)
409 # Confirm that classes fail on unsupported OSs
410 it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
411 it { expect { should contain_class('opendaylight::install') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
412 it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
413 it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
415 # Confirm that other resources fail on unsupported OSs
416 it { expect { should contain_yumrepo('opendaylight-4-testing') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
417 it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
418 it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
419 it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /#{expected_msg}/) }