1 require 'puppetlabs_spec_helper/module_spec_helper'
2 require 'rspec-puppet-facts'
3 include RspecPuppetFacts
5 # Customize filters to ignore 3rd-party code
6 # If the rspec coverage report shows not-our-code results, add it here
9 RSpec::Puppet::Coverage.filters.push(*custom_filters)
12 # NB: This is a library of helper fns used by the rspec-puppet tests
15 # Tests that are common to all possible configurations
16 def generic_tests(options = {})
17 java_opts = options.fetch(:java_opts, '')
18 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
19 inactivity_probe = options.fetch(:inactivity_probe, :undef)
21 # Confirm that module compiles
23 it { should compile.with_all_deps }
25 # Confirm presence of classes
26 it { should contain_class('opendaylight') }
27 it { should contain_class('opendaylight::params') }
28 it { should contain_class('opendaylight::install') }
29 it { should contain_class('opendaylight::config') }
30 it { should contain_class('opendaylight::post_config') }
31 it { should contain_class('opendaylight::service') }
33 # Confirm relationships between classes
34 it { should contain_class('opendaylight::install').that_comes_before('Class[opendaylight::config]') }
35 it { should contain_class('opendaylight::config').that_requires('Class[opendaylight::install]') }
36 it { should contain_class('opendaylight::config').that_notifies('Class[opendaylight::service]') }
37 it { should contain_class('opendaylight::service').that_subscribes_to('Class[opendaylight::config]') }
38 it { should contain_class('opendaylight::service').that_comes_before('Class[opendaylight]') }
39 it { should contain_class('opendaylight::post_config').that_requires('Class[opendaylight::service]') }
40 it { should contain_class('opendaylight::post_config').that_comes_before('Class[opendaylight]') }
41 it { should contain_class('opendaylight').that_requires('Class[opendaylight::service]') }
43 # Confirm presence of generic resources
44 it { should contain_service('opendaylight') }
45 it { should contain_file('org.apache.karaf.features.cfg') }
47 # Confirm properties of generic resources
48 # NB: These hashes don't work with Ruby 1.8.7, but we
49 # don't support 1.8.7 so that's okay. See issue #36.
51 should contain_service('opendaylight').with(
52 'ensure' => 'running',
54 'hasstatus' => 'true',
55 'hasrestart' => 'true',
59 should contain_file('org.apache.karaf.features.cfg').with(
61 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
68 if odl_bind_ip =~ /.*:.*/
69 java_options = '-Djava.net.preferIPv6Addresses=true'
71 java_options = '-Djava.net.preferIPv4Stack=true'
74 should contain_file_line('Karaf Java Options').with(
75 'ensure' => 'present',
76 'path' => '/opt/opendaylight/bin/karaf',
77 'line' => "EXTRA_JAVA_OPTS=\"#{java_options}\"",
78 'match' => '^EXTRA_JAVA_OPTS=.*$',
79 'after' => '^PROGNAME=.*$'
84 should contain_file('org.opendaylight.ovsdb.library.cfg').with(
86 'path' => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
89 'content' => /ovsdb-listener-ip = #{odl_bind_ip}/
94 should contain_file('default-openflow-connection-config.xml').with(
96 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml',
99 'content' => /<address>#{odl_bind_ip}<\/address>/
103 unless inactivity_probe == :undef
105 should contain_file('Configure inactivity probe timer').with(
107 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml',
110 'content' => /<controller-inactivity-probe>#{inactivity_probe}<\/controller-inactivity-probe>/
117 # Shared tests that specialize in testing log file size and rollover
118 def log_settings(options = {})
119 # Extraxt params. The dafault value should be same as in opendaylight::params
120 log_max_size = options.fetch(:log_max_size, '10GB')
121 log_max_rollover = options.fetch(:log_max_rollover, 2)
122 log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
123 log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
124 log_mechanism = options.fetch(:log_mechanism, 'file')
126 if log_mechanism == 'console'
128 should contain_file_line('consoleappender').with(
129 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
130 'line' => 'karaf.log.console=INFO',
131 'after' => 'log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter',
132 'match' => '^karaf.log.console.*$'
136 should contain_file_line('direct').with(
137 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
138 'line' => 'log4j2.appender.console.direct = true',
139 'after' => 'karaf.log.console=INFO',
140 'match' => '^log4j2.appender.console.direct.*$'
146 should contain_file_line('logmaxsize').with(
147 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
148 'line' => "log4j2.appender.rolling.policies.size.size = #{log_max_size}",
149 'match' => '^log4j2.appender.rolling.policies.size.size.*$',
153 should contain_file_line('rolloverstrategy').with(
154 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
155 'line' => 'log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy'
159 should contain_file_line('logmaxrollover').with(
160 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
161 'line' => "log4j2.appender.rolling.strategy.max = #{log_max_rollover}",
162 'match' => '^log4j2.appender.rolling.strategy.max.*$',
166 should contain_file_line('logrolloverfileindex').with(
167 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
168 'line' => "log4j2.appender.rolling.strategy.fileIndex = #{log_rollover_fileindex}",
169 'match' => '^log4j2.appender.rolling.strategy.fileIndex.*$',
174 should contain_file_line('logpattern').with(
175 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
176 'line' => "log4j2.pattern = #{log_pattern}",
177 'match' => '^log4j2.pattern.*$',
182 # Shared tests that specialize in testing Karaf feature installs
183 def karaf_feature_tests(options = {})
185 # NB: This default list should be the same as the one in opendaylight::params
186 # TODO: Remove this possible source of bugs^^
187 default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
188 extra_features = options.fetch(:extra_features, [])
190 # The order of this list concat matters
191 features = default_features + extra_features
192 features_csv = features.join(',')
194 # Confirm properties of Karaf features config file
195 # NB: These hashes don't work with Ruby 1.8.7, but we
196 # don't support 1.8.7 so that's okay. See issue #36.
198 should contain_file('org.apache.karaf.features.cfg').with(
200 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
206 should contain_file_line('featuresBoot').with(
207 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
208 'line' => "featuresBoot=#{features_csv}",
209 'match' => '^featuresBoot=.*$',
214 # Shared tests that specialize in testing ODL's REST port config
215 def odl_rest_port_tests(options = {})
217 # NB: This default value should be the same as one in opendaylight::params
218 # TODO: Remove this possible source of bugs^^
219 odl_rest_port = options.fetch(:odl_rest_port, 8181)
220 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
221 # Confirm properties of ODL REST port config file
222 # NB: These hashes don't work with Ruby 1.8.7, but we
223 # don't support 1.8.7 so that's okay. See issue #36.
225 should contain_augeas('ODL REST Port')
228 if not odl_bind_ip.eql? '0.0.0.0'
230 should contain_augeas('ODL REST IP')
231 should contain_file_line('set pax bind IP').with(
232 'ensure' => 'present',
233 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
234 'line' => "org.ops4j.pax.web.listening.addresses = #{odl_bind_ip}",
235 'require' => 'File[org.ops4j.pax.web.cfg]'
237 should contain_file_line('set karaf IP').with(
238 'ensure' => 'present',
239 'path' => '/opt/opendaylight/etc/org.apache.karaf.shell.cfg',
240 'line' => "sshHost = #{odl_bind_ip}",
241 'match' => '^sshHost\s*=.*$',
246 should_not contain_augeas('ODL REST IP')
251 should contain_file_line('set pax bind port').with(
252 'ensure' => 'present',
253 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
254 'line' => "org.osgi.service.http.port = #{odl_rest_port}",
255 'match' => '^#?org.osgi.service.http.port\s.*$',
256 'require' => 'File[org.ops4j.pax.web.cfg]'
261 def log_level_tests(options = {})
263 # NB: This default value should be the same as one in opendaylight::params
264 # TODO: Remove this possible source of bugs^^
265 log_levels = options.fetch(:log_levels, {})
268 # Should contain log level config file
270 should_not contain_file_line('logger-org.opendaylight.ovsdb-level')
273 should_not contain_file_line('logger-org.opendaylight.ovsdb-name')
276 # Verify each custom log level config entry
277 log_levels.each_pair do |logger, level|
278 underscored_version = "#{logger}".gsub('.', '_')
280 should contain_file_line("logger-#{logger}-level").with(
281 'ensure' => 'present',
282 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
283 'line' => "log4j2.logger.#{underscored_version}.level = #{level}",
284 'match' => "log4j2.logger.#{underscored_version}.level = .*$"
286 should contain_file_line("logger-#{logger}-name").with(
287 'ensure' => 'present',
288 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
289 'line' => "log4j2.logger.#{underscored_version}.name = #{logger}",
290 'match' => "log4j2.logger.#{underscored_version}.name = .*$"
297 def enable_ha_tests(options = {})
299 enable_ha = options.fetch(:enable_ha, false)
300 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
301 ha_node_ips = options.fetch(:ha_node_ips, [])
302 ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
304 ha_node_count = ha_node_ips.size
306 if (enable_ha) && (ha_node_count < 2)
307 # Check for HA_NODE_COUNT < 2
308 fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
312 ha_node_index = ha_node_ips.index(odl_bind_ip)
314 should contain_file('akka.conf').with(
315 'path' => '/opt/opendaylight/configuration/initial/akka.conf',
319 'content' => /roles\s*=\s*\["member-#{ha_node_index}"\]/
323 ha_db_modules.each do |mod, urn|
324 it { should contain_file('module-shards.conf').with(
325 'path' => '/opt/opendaylight/configuration/initial/module-shards.conf',
329 'content' => /name = "#{mod}"/
332 it { should contain_file('modules.conf').with(
333 'path' => '/opt/opendaylight/configuration/initial/modules.conf',
339 it { should contain_file('modules.conf').with(
340 'path' => '/opt/opendaylight/configuration/initial/modules.conf',
344 'content' => /name = "#{mod}"/,
350 should_not contain_file('akka.conf')
351 should_not contain_file('module-shards.conf')
352 should_not contain_file('modules.conf')
357 def rpm_install_tests(options = {})
359 rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-neon-epel-7-$basearch-devel')
362 # Default to CentOS 7 Yum repo URL
364 # Confirm presence of RPM-related resources
365 it { should contain_yumrepo('opendaylight') }
366 it { should contain_package('opendaylight') }
368 # Confirm relationships between RPM-related resources
369 it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') }
370 it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') }
372 # Confirm properties of RPM-related resources
373 # NB: These hashes don't work with Ruby 1.8.7, but we
374 # don't support 1.8.7 so that's okay. See issue #36.
376 should contain_yumrepo('opendaylight').with(
379 'descr' => 'OpenDaylight SDN Controller',
380 'baseurl' => "#{rpm_repo}",
384 should contain_package('opendaylight').with(
385 'ensure' => 'present',
390 def deb_install_tests(options = {})
392 deb_repo = options.fetch(:deb_repo, 'ppa:odl-team/nitrogen')
394 # Confirm the presence of Deb-related resources
395 it { should contain_apt__ppa(deb_repo) }
396 it { should contain_package('opendaylight') }
398 # Confirm relationships between Deb-related resources
399 it { should contain_package('opendaylight').that_requires("Apt::Ppa[#{deb_repo}]") }
400 it { should contain_apt__ppa(deb_repo).that_comes_before('Package[opendaylight]') }
402 # Confirm presence of Deb-related resources
404 should contain_package('opendaylight').with(
405 'ensure' => 'present',
410 # Shared tests for unsupported OSs
411 def unsupported_os_tests(options = {})
413 expected_msg = options.fetch(:expected_msg)
414 rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-neon-epel-7-$basearch-devel')
416 # Confirm that classes fail on unsupported OSs
417 it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
418 it { expect { should contain_class('opendaylight::install') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
419 it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
420 it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
422 # Confirm that other resources fail on unsupported OSs
423 it { expect { should contain_yumrepo('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
424 it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
425 it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
426 it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
429 # Shared tests that specialize in testing SNAT mechanism
430 def snat_mechanism_tests(snat_mechanism='controller')
431 it { should contain_file('/opt/opendaylight/etc/opendaylight') }
432 it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore')}
433 it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial')}
434 it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial/config')}
436 # Confirm snat_mechanism
438 should contain_file('netvirt-natservice-config.xml').with(
440 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
443 'content' => /<nat-mode>#{snat_mechanism}<\/nat-mode>/
448 # Shared tests that specialize in testing SFC Config
449 def sfc_tests(options = {})
450 extra_features = options.fetch(:extra_features, [])
452 if extra_features.include? 'odl-netvirt-sfc'
458 it { should contain_file('/opt/opendaylight/etc/opendaylight') }
459 it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore')}
460 it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial')}
461 it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial/config')}
464 should contain_file('genius-itm-config.xml').with(
466 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
469 'content' => /<gpe-extension-enabled>#{sfc_enabled}<\/gpe-extension-enabled>/
474 # Shared tests that specialize in testing DSCP marking config
475 def dscp_tests(options = {})
476 inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
478 if inherit_dscp_marking
480 should contain_file('genius-itm-config.xml').with(
482 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
485 'content' => /<default-tunnel-tos>inherit<\/default-tunnel-tos>/
490 should contain_file('genius-itm-config.xml').with(
492 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
495 'content' => /<default-tunnel-tos>0<\/default-tunnel-tos>/
501 # Shared tests that specialize in testing VPP routing node config
502 def vpp_routing_node_tests(options = {})
504 # NB: This default list should be the same as the one in opendaylight::params
505 # TODO: Remove this possible source of bugs^^
506 routing_node = options.fetch(:routing_node, '')
508 if routing_node.empty?
509 it { should_not contain_file('org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg') }
510 it { should_not contain_file_line('routing-node') }
512 # Confirm properties of Karaf config file
513 # NB: These hashes don't work with Ruby 1.8.7, but we
514 # don't support 1.8.7 so that's okay. See issue #36.
516 should contain_file('org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg').with(
518 'path' => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
524 should contain_file_line('routing-node').with(
525 'path' => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
526 'line' => "routing-node=#{routing_node}",
527 'match' => '^routing-node=.*$',
533 # ODL username/password tests
534 def username_password_tests(username, password)
537 should contain_odl_user(username).with(
538 :password => password
543 # ODL websocket address tests
544 def odl_websocket_address_tests(options = {})
546 # NB: This default value should be the same as one in opendaylight::params
547 # TODO: Remove this possible source of bugs^^
548 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
549 # Confirm properties of ODL REST port config file
550 # NB: These hashes don't work with Ruby 1.8.7, but we
551 # don't support 1.8.7 so that's okay. See issue #36.
553 if not odl_bind_ip.eql? '0.0.0.0'
555 should contain_file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg').with(
557 'path' => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
563 should contain_file_line('websocket-address').with(
564 'path' => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
565 'line' => "websocket-address=#{odl_bind_ip}",
566 'match' => '^websocket-address=.*$',
571 should_not contain_file_line('websocket-address')
576 def odl_tls_tests(options = {})
577 enable_tls = options.fetch(:enable_tls, false)
578 tls_keystore_password = options.fetch(:tls_keystore_password, nil)
579 tls_trusted_certs = options.fetch(:tls_trusted_certs, [])
580 tls_keystore_password = options.fetch(:tls_keystore_password, nil)
581 tls_key_file = options.fetch(:tls_key_file, nil)
582 tls_cert_file = options.fetch(:tls_cert_file, nil)
583 tls_ca_cert_file = options.fetch(:tls_ca_cert_file, nil)
584 odl_rest_port = options.fetch(:odl_rest_port, 8181)
587 if tls_keystore_password.nil?
588 it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::PreformattedError) }
592 if tls_key_file or tls_cert_file
593 if tls_key_file and tls_cert_file
595 should contain_odl_keystore('controller')
598 it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::PreformattedError) }
602 should contain_augeas('Remove HTTP ODL REST Port')
603 should contain_augeas('ODL SSL REST Port')
604 should contain_file_line('set pax TLS port').with(
605 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
606 'line' => "org.osgi.service.http.port.secure = #{odl_rest_port}",
607 'match' => '^#?org.osgi.service.http.port.secure.*$',
609 should contain_file_line('set pax TLS keystore location').with(
610 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
611 'line' => 'org.ops4j.pax.web.ssl.keystore = configuration/ssl/ctl.jks',
612 'match' => '^#?org.ops4j.pax.web.ssl.keystore.*$',
614 should contain_file_line('set pax TLS keystore integrity password').with(
615 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
616 'line' => "org.ops4j.pax.web.ssl.password = #{tls_keystore_password}",
617 'match' => '^#?org.ops4j.pax.web.ssl.password.*$',
619 should contain_file_line('set pax TLS keystore password').with(
620 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
621 'line' => "org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}",
622 'match' => '^#?org.ops4j.pax.web.ssl.keypassword.*$',
624 should contain_file('aaa-cert-config.xml').with(
626 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml',
630 should contain_file('org.opendaylight.ovsdb.library.cfg').with(
632 'path' => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
635 'content' => /use-ssl = true/
637 should contain_file('/opt/opendaylight/configuration/ssl').with(
638 'ensure' => 'directory',
639 'path' => '/opt/opendaylight/configuration/ssl',
644 should contain_file_line('enable pax TLS').with(
645 'ensure' => 'present',
646 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
647 'line' => 'org.osgi.service.http.secure.enabled = true',
648 'match' => '^#?org.osgi.service.http.secure.enabled.*$',
650 should contain_file_line('disable pax HTTP').with(
651 'ensure' => 'present',
652 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
653 'line' => 'org.osgi.service.http.enabled = false',
654 'match' => '^#?org.osgi.service.http.enabled.*$',
656 should contain_file('org.ops4j.pax.web.cfg').with(
658 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
662 should contain_file('default-openflow-connection-config.xml').with(
664 'path' => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml',
667 'content' => /<transport-protocol>TLS<\/transport-protocol>/
673 def stats_polling_enablement_tests(options = {})
675 # NB: This default value should be the same as one in opendaylight::params
676 # TODO: Remove this possible source of bugs^^
677 stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
678 # Confirm properties of ODL REST port config file
679 # NB: These hashes don't work with Ruby 1.8.7, but we
680 # don't support 1.8.7 so that's okay. See issue #36.
682 should contain_file('openflowplugin.cfg').with(
684 'path' => '/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg',
688 should contain_file_line('stats-polling').with(
689 'ensure' => 'present',
690 'path' => '/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg',
691 'line' => "is-statistics-polling-on=#{stats_polling_enabled}",
692 'match' => '^is-statistics-polling-on=.*$',