1 require 'beaker-rspec/spec_helper'
2 require 'beaker-rspec/helpers/serverspec'
4 # Install Puppet on all Beaker hosts
5 unless ENV['BEAKER_provision'] == 'no'
8 install_puppet_agent_on(host, puppet_collection: "pc1")
12 RSpec.configure do |c|
14 proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
16 # Readable test descriptions
17 c.formatter = :documentation
19 # Configure all nodes in nodeset
21 # Install opendaylight module on any/all Beaker hosts
22 # TODO: Should this be done in host.each loop?
23 puppet_module_install(:source => proj_root, :module_name => 'opendaylight')
25 # Install stdlib, a dependency of the odl mod
26 on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0] }
27 # Install apt, a dependency of the deb install method
28 on host, puppet('module', 'install', 'puppetlabs-apt'), { :acceptable_exit_codes => [0] }
34 # NB: These are a library of helper fns used by the Beaker tests
37 # NB: There are a large number of helper functions used in these tests.
38 # They make this code much more friendly, but may need to be referenced.
39 # The serverspec helpers (`should`, `be_running`...) are documented here:
40 # http://serverspec.org/resource_types.html
42 def install_odl(options = {})
43 # Install params are passed via environment var, set in Rakefile
44 # Changing the installed version of ODL via `puppet apply` is not supported
45 # by puppet-odl, so it's not possible to vary these params in the same
46 # Beaker test run. Do a different run passing different env vars.
47 rpm_repo = ENV['RPM_REPO']
48 deb_repo = ENV['DEB_REPO']
50 # NB: These param defaults should match the ones used by the opendaylight
51 # class, which are defined in opendaylight::params
52 # TODO: Remove this possible source of bugs^^
53 # Extract params if given, defaulting to odl class defaults if not
54 extra_features = options.fetch(:extra_features, ['odl-restconf'])
55 default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
56 odl_rest_port = options.fetch(:odl_rest_port, 8181)
57 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
58 log_levels = options.fetch(:log_levels, {})
59 enable_ha = options.fetch(:enable_ha, false)
60 ha_node_ips = options.fetch(:ha_node_ips, [])
61 ha_node_index = options.fetch(:ha_node_index, 0)
62 ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
63 username = options.fetch(:username, 'admin')
64 password = options.fetch(:password, 'admin')
65 log_max_size = options.fetch(:log_max_size, '10GB')
66 log_max_rollover = options.fetch(:log_max_rollover, 2)
67 snat_mechanism = options.fetch(:snat_mechanism, 'controller')
68 enable_tls = options.fetch(:enable_tls, false)
69 tls_keystore_password = options.fetch(:tls_keystore_password, 'dummypass')
70 log_mechanism = options.fetch(:log_mechanism, 'file')
71 inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
72 stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
74 # Build script for consumption by Puppet apply
75 it 'should work idempotently with no errors' do
77 class { 'opendaylight':
78 rpm_repo => '#{rpm_repo}',
79 deb_repo => '#{deb_repo}',
80 default_features => #{default_features},
81 extra_features => #{extra_features},
82 odl_rest_port => #{odl_rest_port},
83 odl_bind_ip => '#{odl_bind_ip}',
84 enable_ha => #{enable_ha},
85 ha_node_ips => #{ha_node_ips},
86 ha_node_index => #{ha_node_index},
87 ha_db_modules => #{ha_db_modules},
88 log_levels => #{log_levels},
89 username => #{username},
90 password => #{password},
91 log_max_size => '#{log_max_size}',
92 log_max_rollover => #{log_max_rollover},
93 snat_mechanism => #{snat_mechanism},
94 enable_tls => #{enable_tls},
95 tls_keystore_password => #{tls_keystore_password},
96 log_mechanism => #{log_mechanism},
97 inherit_dscp_marking => #{inherit_dscp_marking},
98 stats_polling_enabled => #{stats_polling_enabled},
102 # Apply our Puppet manifest on the Beaker host
103 apply_manifest(pp, :catch_failures => true)
105 # Not checking for idempotence because of false failures
106 # related to package manager cache updates outputting to
107 # stdout and different IDs for the puppet manifest apply.
108 # I think this is a limitation in how Beaker can check
109 # for changes, not a problem with the Puppet module.
113 # Shared function that handles generic validations
114 # These should be common for all odl class param combos
115 def generic_validations(options = {})
116 java_opts = options.fetch(:java_opts, '-Djava.net.preferIPv4Stack=true')
118 # Verify ODL's directory
119 describe file('/opt/opendaylight/') do
120 it { should be_directory }
121 it { should be_owned_by 'odl' }
122 it { should be_grouped_into 'odl' }
125 # Verify ODL's systemd service
126 describe service('opendaylight') do
127 it { should be_enabled }
128 it { should be_enabled.with_level(3) }
129 it { should be_running.under('systemd') }
132 # Creation handled by RPM or Deb
133 describe user('odl') do
135 it { should belong_to_group 'odl' }
136 # NB: This really shouldn't have a slash at the end!
137 # The home dir set by the RPM is `/opt/opendaylight`.
138 # Since we use the trailing slash elsewhere else, this
139 # may look like a style issue. It isn't! It will make
140 # Beaker tests fail if it ends with a `/`. A future
141 # version of the ODL RPM may change this.
142 it { should have_home_directory '/opt/opendaylight' }
145 # Creation handled by RPM or Deb
146 describe group('odl') do
150 # This should not be the odl user's home dir
151 describe file('/home/odl') do
152 # Home dir shouldn't be created for odl user
153 it { should_not be_directory }
156 # OpenDaylight will appear as a Java process
157 describe process('java') do
158 it { should be_running }
161 # Should contain Karaf features config file
162 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
163 it { should be_file }
164 it { should be_owned_by 'odl' }
165 it { should be_grouped_into 'odl' }
168 # Should contain karaf file with Java options set
169 describe file('/opt/opendaylight/bin/karaf') do
170 it { should be_file }
171 it { should be_owned_by 'odl' }
172 it { should be_grouped_into 'odl' }
173 its(:content) { should match /^EXTRA_JAVA_OPTS=#{java_opts}$/ }
176 # Should contain ODL NB port config file
177 describe file('/opt/opendaylight/etc/jetty.xml') do
178 it { should be_file }
179 it { should be_owned_by 'odl' }
180 it { should be_grouped_into 'odl' }
183 # Should contain log level config file
184 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
185 it { should be_file }
186 it { should be_owned_by 'odl' }
187 it { should be_grouped_into 'odl' }
190 if ['centos-7', 'centos-7-docker'].include? ENV['RS_SET']
191 # Validations for modern Red Hat family OSs
193 # Verify ODL systemd .service file
194 describe file('/usr/lib/systemd/system/opendaylight.service') do
195 it { should be_file }
196 it { should be_owned_by 'root' }
197 it { should be_grouped_into 'root' }
198 it { should be_mode '644' }
201 # Java 8 should be installed
202 describe package('java-1.8.0-openjdk') do
203 it { should be_installed }
206 # Ubuntu 16.04 specific validation
207 elsif ['ubuntu-16', 'ubuntu-16-docker'].include? ENV['RS_SET']
209 # Verify ODL systemd .service file
210 describe file('/lib/systemd/system/opendaylight.service') do
211 it { should be_file }
212 it { should be_owned_by 'root' }
213 it { should be_grouped_into 'root' }
214 it { should be_mode '644' }
217 # Java 8 should be installed
218 describe package('openjdk-8-jre-headless') do
219 it { should be_installed }
223 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
227 # Shared function for validations related to log file settings
228 def log_settings_validations(options = {})
229 # Should contain log level config file with correct file size and rollover values
230 log_max_size = options.fetch(:log_max_size, '10GB')
231 log_max_rollover = options.fetch(:log_max_rollover, 2)
232 log_mechanism = options.fetch(:log_mechanism, 'file')
234 if log_mechanism == 'console'
235 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
236 it { should be_file }
237 it { should be_owned_by 'odl' }
238 it { should be_grouped_into 'odl' }
239 its(:content) { should match /^karaf.log.console=INFO/ }
240 its(:content) { should match /^log4j2.appender.console.direct = true/ }
243 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
244 it { should be_file }
245 it { should be_owned_by 'odl' }
246 it { should be_grouped_into 'odl' }
247 its(:content) { should match /^log4j2.appender.rolling.policies.size.size = #{log_max_size}/ }
248 its(:content) { should match /^log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy/ }
249 its(:content) { should match /^log4j2.appender.rolling.strategy.max = #{log_max_rollover}/ }
254 # Shared function for validations related to the Karaf config file
255 def karaf_config_validations(options = {})
256 # NB: These param defaults should match the ones used by the opendaylight
257 # class, which are defined in opendaylight::params
258 # TODO: Remove this possible source of bugs^^
259 extra_features = options.fetch(:extra_features, [])
260 default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
262 # Create one list of all of the features
263 features = default_features + extra_features
265 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
266 it { should be_file }
267 it { should be_owned_by 'odl' }
268 it { should be_grouped_into 'odl' }
269 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
273 # Shared function for validations related to the ODL REST port config file
274 def port_config_validations(options = {})
275 # NB: This param default should match the one used by the opendaylight
276 # class, which is defined in opendaylight::params
277 # TODO: Remove this possible source of bugs^^
278 odl_rest_port = options.fetch(:odl_rest_port, 8181)
280 describe file('/opt/opendaylight/etc/jetty.xml') do
281 it { should be_file }
282 it { should be_owned_by 'odl' }
283 it { should be_grouped_into 'odl' }
284 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
287 describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
288 it { should be_file }
289 it { should be_owned_by 'odl' }
290 it { should be_grouped_into 'odl' }
291 its(:content) { should match /org.osgi.service.http.port = #{odl_rest_port}/ }
295 # Shared function for validations related to the ODL bind IP
296 def odl_bind_ip_validation(options = {})
297 # NB: This param default should match the one used by the opendaylight
298 # class, which is defined in opendaylight::params
299 # TODO: Remove this possible source of bugs^^
300 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
302 if odl_bind_ip != '0.0.0.0'
303 describe file('/opt/opendaylight/etc/org.apache.karaf.shell.cfg') do
304 it { should be_file }
305 it { should be_owned_by 'odl' }
306 it { should be_grouped_into 'odl' }
307 its(:content) { should match /sshHost = #{odl_bind_ip}/ }
310 describe command("loop_count=0; until [[ \$loop_count -ge 30 ]]; do netstat -punta | grep 8101 | grep #{odl_bind_ip} && break; loop_count=\$[\$loop_count+1]; sleep 1; done; echo \"Waited \$loop_count seconds to detect ODL karaf bound to IP\"") do
311 its(:exit_status) { should eq 0 }
316 # Shared function for validations related to custom logging verbosity
317 def log_level_validations(options = {})
318 # NB: This param default should match the one used by the opendaylight
319 # class, which is defined in opendaylight::params
320 # TODO: Remove this possible source of bugs^^
321 log_levels = options.fetch(:log_levels, {})
324 # Should contain log level config file
325 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
326 it { should be_file }
327 it { should be_owned_by 'odl' }
328 it { should be_grouped_into 'odl' }
331 # Should contain log level config file
332 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
333 it { should be_file }
334 it { should be_owned_by 'odl' }
335 it { should be_grouped_into 'odl' }
337 # Verify each custom log level config entry
338 log_levels.each_pair do |logger, level|
339 underscored_version = "#{logger}".gsub('.', '_')
340 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
341 it { should be_file }
342 it { should be_owned_by 'odl' }
343 it { should be_grouped_into 'odl' }
344 its(:content) { should match /^log4j2.logger.#{underscored_version}.level = #{level}/ }
345 its(:content) { should match /^log4j2.logger.#{underscored_version}.name = #{logger}/ }
351 # Shared function for validations related to ODL OVSDB HA config
352 def enable_ha_validations(options = {})
353 # NB: This param default should match the one used by the opendaylight
354 # class, which is defined in opendaylight::params
355 # TODO: Remove this possible source of bugs^^
356 enable_ha = options.fetch(:enable_ha, false)
357 ha_node_ips = options.fetch(:ha_node_ips, [])
358 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
359 ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
361 ha_node_count = ha_node_ips.size
363 if (enable_ha) && (ha_node_count < 2)
364 # Check for HA_NODE_COUNT < 2
365 fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
369 ha_node_index = ha_node_ips.index(odl_bind_ip)
370 describe file('/opt/opendaylight/configuration/initial/akka.conf') do
371 it { should be_file }
372 it { should be_owned_by 'odl' }
373 it { should be_grouped_into 'odl' }
374 its(:content) { should match /roles\s*=\s*\["member-#{ha_node_index}"\]/ }
377 ha_db_modules.each do |mod, urn|
378 describe file('/opt/opendaylight/configuration/initial/module-shards.conf') do
379 it { should be_file }
380 it { should be_owned_by 'odl' }
381 it { should be_grouped_into 'odl' }
382 its(:content) { should match /name = "#{mod}"/ }
386 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
387 it { should be_file }
388 it { should be_owned_by 'odl' }
389 it { should be_grouped_into 'odl' }
392 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
393 it { should be_file }
394 it { should be_owned_by 'odl' }
395 it { should be_grouped_into 'odl' }
396 its(:content) { should match /name = "#{mod}"/ }
397 its(:content) { should match /namespace = "#{urn}"/ }
404 # Shared function that handles validations specific to RPM-type installs
405 def rpm_validations()
406 rpm_repo = ENV['RPM_REPO']
408 describe yumrepo('opendaylight') do
410 it { should be_enabled }
413 describe package('opendaylight') do
414 it { should be_installed }
418 # Shared function that handles validations specific to Deb-type installs
419 def deb_validations()
420 deb_repo = ENV['DEB_REPO']
422 # Docs: http://serverspec.org/resource_types.html#ppa
423 describe ppa(deb_repo) do
425 it { should be_enabled }
428 describe package('opendaylight') do
429 it { should be_installed }
433 # Shared function for validations related to username/password
434 def username_password_validations(options = {})
435 # NB: This param default should match the one used by the opendaylight
436 # class, which is defined in opendaylight::params
437 # TODO: Remove this possible source of bugs^^
438 odl_username = options.fetch(:username, 'admin')
439 odl_password = options.fetch(:password, 'admin')
440 odl_check_url = 'http://127.0.0.1:8181/restconf'
442 describe file('/opt/opendaylight/data/idmlight.db.mv.db') do
443 it { should be_file }
446 describe command("loop_count=0; until [[ \$loop_count -ge 300 ]]; do curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url} && break; loop_count=\$[\$loop_count+1]; sleep 1; done; echo \"Waited \$loop_count seconds for ODL to become active\"") do
447 its(:exit_status) { should eq 0 }
450 describe command("curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
451 its(:exit_status) { should eq 0 }
455 # Shared function for validations related to the SNAT config file
456 def snat_mechanism_validations(options = {})
457 # NB: This param default should match the one used by the opendaylight
458 # class, which is defined in opendaylight::params
459 # TODO: Remove this possible source of bugs^^
460 snat_mechanism = options.fetch(:snat_mechanism, 'controller')
462 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml') do
463 it { should be_file }
464 it { should be_owned_by 'odl' }
465 it { should be_grouped_into 'odl' }
466 its(:content) { should match /<nat-mode>#{snat_mechanism}<\/nat-mode>/ }
470 # Shared function for validations related to SFC
471 def sfc_validations(options = {})
472 # NB: This param default should match the one used by the opendaylight
473 # class, which is defined in opendaylight::params
474 # TODO: Remove this possible source of bugs^^
476 extra_features = options.fetch(:extra_features, [])
477 if extra_features.include? 'odl-netvirt-sfc'
483 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
484 it { should be_file }
485 it { should be_owned_by 'odl' }
486 it { should be_grouped_into 'odl' }
487 its(:content) { should match /<gpe-extension-enabled>#{sfc_enabled}<\/gpe-extension-enabled>/ }
491 # Shared function for validations related to tos value for DSCP marking
492 def dscp_validations(options = {})
493 # NB: This param default should match the one used by the opendaylight
494 # class, which is defined in opendaylight::params
495 # TODO: Remove this possible source of bugs^^
497 inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
499 if inherit_dscp_marking
500 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
501 it { should be_file }
502 it { should be_owned_by 'odl' }
503 it { should be_grouped_into 'odl' }
504 its(:content) { should match /<default-tunnel-tos>inherit<\/default-tunnel-tos>/ }
509 def websocket_address_validations(options = {})
510 # NB: This param default should match the one used by the opendaylight
511 # class, which is defined in opendaylight::params
512 # TODO: Remove this possible source of bugs^^
513 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
515 if not odl_bind_ip.eql? '0.0.0.0'
516 describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
517 it { should be_file }
518 it { should be_owned_by 'odl' }
519 it { should be_grouped_into 'odl' }
520 its(:content) { should match /^websocket-address=#{odl_bind_ip}/ }
523 describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
524 it { should be_file }
529 def tls_validations(options = {})
530 # NB: This param default should match the one used by the opendaylight
531 # class, which is defined in opendaylight::params
532 # TODO: Remove this possible source of bugs^^
533 tls_keystore_password = options.fetch(:tls_keystore_password)
534 odl_rest_port = options.fetch(:odl_rest_port, 8181)
536 describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
537 it { should be_file }
538 it { should be_owned_by 'odl' }
539 it { should be_grouped_into 'odl' }
540 its(:content) { should match /org.osgi.service.http.port.secure = #{odl_rest_port}/ }
541 its(:content) { should match /org.ops4j.pax.web.ssl.keystore = configuration\/ssl\/ctl.jks/ }
542 its(:content) { should match /org.ops4j.pax.web.ssl.password = #{tls_keystore_password}/ }
543 its(:content) { should match /org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}/ }
544 its(:content) { should match /org.osgi.service.http.secure.enabled = true/ }
545 its(:content) { should match /org.osgi.service.http.enabled = false/ }
548 describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
549 it { should be_file }
550 it { should be_owned_by 'odl' }
551 it { should be_grouped_into 'odl' }
552 its(:content) { should match /use-ssl = true/ }
555 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml') do
556 it { should be_file }
557 it { should be_owned_by 'odl' }
558 it { should be_grouped_into 'odl' }
559 its(:content) { should match /<keystore-password>#{tls_keystore_password}<\/keystore-password>/ }
560 its(:content) { should match /<truststore-password>#{tls_keystore_password}<\/truststore-password>/ }
561 its(:content) { should match /<transport-protocol>TLS<\/transport-protocol>/ }
564 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml') do
565 it { should be_file }
566 it { should be_owned_by 'odl' }
567 it { should be_grouped_into 'odl' }
568 its(:content) { should match /<store-password>#{tls_keystore_password}<\/store-password>/ }
569 its(:content) { should match /<use-mdsal>false<\/use-mdsal>/ }
572 describe file('/opt/opendaylight/etc/jetty.xml') do
573 it { should be_file }
574 it { should be_owned_by 'odl' }
575 it { should be_grouped_into 'odl' }
576 its(:content) { should match /<Property name="jetty.secure.port" default="#{odl_rest_port}" \/>/ }
580 # Shared function for validations related to OVS statistics polling
581 def stats_polling_validations(options = {})
582 # NB: This param default should match the one used by the opendaylight
583 # class, which is defined in opendaylight::params
584 # TODO: Remove this possible source of bugs^^
586 stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
587 describe file('/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg') do
588 it { should be_file }
589 it { should be_owned_by 'odl' }
590 it { should be_grouped_into 'odl' }
591 its(:content) { should match /is-statistics-polling-on=#{stats_polling_enabled}/ }