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')
72 # Build script for consumption by Puppet apply
73 it 'should work idempotently with no errors' do
75 class { 'opendaylight':
76 rpm_repo => '#{rpm_repo}',
77 deb_repo => '#{deb_repo}',
78 default_features => #{default_features},
79 extra_features => #{extra_features},
80 odl_rest_port => #{odl_rest_port},
81 odl_bind_ip => '#{odl_bind_ip}',
82 enable_ha => #{enable_ha},
83 ha_node_ips => #{ha_node_ips},
84 ha_node_index => #{ha_node_index},
85 ha_db_modules => #{ha_db_modules},
86 log_levels => #{log_levels},
87 username => #{username},
88 password => #{password},
89 log_max_size => '#{log_max_size}',
90 log_max_rollover => #{log_max_rollover},
91 snat_mechanism => #{snat_mechanism},
92 enable_tls => #{enable_tls},
93 tls_keystore_password => #{tls_keystore_password},
94 log_mechanism => #{log_mechanism},
98 # Apply our Puppet manifest on the Beaker host
99 apply_manifest(pp, :catch_failures => true)
101 # Not checking for idempotence because of false failures
102 # related to package manager cache updates outputting to
103 # stdout and different IDs for the puppet manifest apply.
104 # I think this is a limitation in how Beaker can check
105 # for changes, not a problem with the Puppet module.
109 # Shared function that handles generic validations
110 # These should be common for all odl class param combos
111 def generic_validations(options = {})
112 java_opts = options.fetch(:java_opts, '-Djava.net.preferIPv4Stack=true')
114 # Verify ODL's directory
115 describe file('/opt/opendaylight/') do
116 it { should be_directory }
117 it { should be_owned_by 'odl' }
118 it { should be_grouped_into 'odl' }
121 # Verify ODL's systemd service
122 describe service('opendaylight') do
123 it { should be_enabled }
124 it { should be_enabled.with_level(3) }
125 it { should be_running.under('systemd') }
128 # Creation handled by RPM or Deb
129 describe user('odl') do
131 it { should belong_to_group 'odl' }
132 # NB: This really shouldn't have a slash at the end!
133 # The home dir set by the RPM is `/opt/opendaylight`.
134 # Since we use the trailing slash elsewhere else, this
135 # may look like a style issue. It isn't! It will make
136 # Beaker tests fail if it ends with a `/`. A future
137 # version of the ODL RPM may change this.
138 it { should have_home_directory '/opt/opendaylight' }
141 # Creation handled by RPM or Deb
142 describe group('odl') do
146 # This should not be the odl user's home dir
147 describe file('/home/odl') do
148 # Home dir shouldn't be created for odl user
149 it { should_not be_directory }
152 # OpenDaylight will appear as a Java process
153 describe process('java') do
154 it { should be_running }
157 # Should contain Karaf features config file
158 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
159 it { should be_file }
160 it { should be_owned_by 'odl' }
161 it { should be_grouped_into 'odl' }
164 # Should contain karaf file with Java options set
165 describe file('/opt/opendaylight/bin/karaf') do
166 it { should be_file }
167 it { should be_owned_by 'odl' }
168 it { should be_grouped_into 'odl' }
169 its(:content) { should match /^EXTRA_JAVA_OPTS=#{java_opts}$/ }
172 # Should contain ODL NB port config file
173 describe file('/opt/opendaylight/etc/jetty.xml') do
174 it { should be_file }
175 it { should be_owned_by 'odl' }
176 it { should be_grouped_into 'odl' }
179 # Should contain log level config file
180 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
181 it { should be_file }
182 it { should be_owned_by 'odl' }
183 it { should be_grouped_into 'odl' }
186 if ['centos-7', 'centos-7-docker'].include? ENV['RS_SET']
187 # Validations for modern Red Hat family OSs
189 # Verify ODL systemd .service file
190 describe file('/usr/lib/systemd/system/opendaylight.service') do
191 it { should be_file }
192 it { should be_owned_by 'root' }
193 it { should be_grouped_into 'root' }
194 it { should be_mode '644' }
197 # Java 8 should be installed
198 describe package('java-1.8.0-openjdk') do
199 it { should be_installed }
202 # Ubuntu 16.04 specific validation
203 elsif ['ubuntu-16', 'ubuntu-16-docker'].include? ENV['RS_SET']
205 # Verify ODL systemd .service file
206 describe file('/lib/systemd/system/opendaylight.service') do
207 it { should be_file }
208 it { should be_owned_by 'root' }
209 it { should be_grouped_into 'root' }
210 it { should be_mode '644' }
213 # Java 8 should be installed
214 describe package('openjdk-8-jre-headless') do
215 it { should be_installed }
219 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
223 # Shared function for validations related to log file settings
224 def log_settings_validations(options = {})
225 # Should contain log level config file with correct file size and rollover values
226 log_max_size = options.fetch(:log_max_size, '10GB')
227 log_max_rollover = options.fetch(:log_max_rollover, 2)
228 log_mechanism = options.fetch(:log_mechanism, 'file')
230 if log_mechanism == 'console'
231 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
232 it { should be_file }
233 it { should be_owned_by 'odl' }
234 it { should be_grouped_into 'odl' }
235 its(:content) { should match /^karaf.log.console=INFO/ }
236 its(:content) { should match /^log4j2.appender.console.direct = true/ }
239 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
240 it { should be_file }
241 it { should be_owned_by 'odl' }
242 it { should be_grouped_into 'odl' }
243 its(:content) { should match /^log4j2.appender.rolling.policies.size.size = #{log_max_size}/ }
244 its(:content) { should match /^log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy/ }
245 its(:content) { should match /^log4j2.appender.rolling.strategy.max = #{log_max_rollover}/ }
250 # Shared function for validations related to the Karaf config file
251 def karaf_config_validations(options = {})
252 # NB: These param defaults should match the ones used by the opendaylight
253 # class, which are defined in opendaylight::params
254 # TODO: Remove this possible source of bugs^^
255 extra_features = options.fetch(:extra_features, [])
256 default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
258 # Create one list of all of the features
259 features = default_features + extra_features
261 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
262 it { should be_file }
263 it { should be_owned_by 'odl' }
264 it { should be_grouped_into 'odl' }
265 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
269 # Shared function for validations related to the ODL REST port config file
270 def port_config_validations(options = {})
271 # NB: This param default should match the one used by the opendaylight
272 # class, which is defined in opendaylight::params
273 # TODO: Remove this possible source of bugs^^
274 odl_rest_port = options.fetch(:odl_rest_port, 8181)
276 describe file('/opt/opendaylight/etc/jetty.xml') do
277 it { should be_file }
278 it { should be_owned_by 'odl' }
279 it { should be_grouped_into 'odl' }
280 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
283 describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
284 it { should be_file }
285 it { should be_owned_by 'odl' }
286 it { should be_grouped_into 'odl' }
287 its(:content) { should match /org.osgi.service.http.port = #{odl_rest_port}/ }
291 # Shared function for validations related to custom logging verbosity
292 def log_level_validations(options = {})
293 # NB: This param default should match the one used by the opendaylight
294 # class, which is defined in opendaylight::params
295 # TODO: Remove this possible source of bugs^^
296 log_levels = options.fetch(:log_levels, {})
299 # Should contain log level config file
300 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
301 it { should be_file }
302 it { should be_owned_by 'odl' }
303 it { should be_grouped_into 'odl' }
306 # Should contain log level config file
307 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
308 it { should be_file }
309 it { should be_owned_by 'odl' }
310 it { should be_grouped_into 'odl' }
312 # Verify each custom log level config entry
313 log_levels.each_pair do |logger, level|
314 underscored_version = "#{logger}".gsub('.', '_')
315 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
316 it { should be_file }
317 it { should be_owned_by 'odl' }
318 it { should be_grouped_into 'odl' }
319 its(:content) { should match /^log4j2.logger.#{underscored_version}.level = #{level}/ }
320 its(:content) { should match /^log4j2.logger.#{underscored_version}.name = #{logger}/ }
326 # Shared function for validations related to ODL OVSDB HA config
327 def enable_ha_validations(options = {})
328 # NB: This param default should match the one used by the opendaylight
329 # class, which is defined in opendaylight::params
330 # TODO: Remove this possible source of bugs^^
331 enable_ha = options.fetch(:enable_ha, false)
332 ha_node_ips = options.fetch(:ha_node_ips, [])
333 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
334 ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
336 ha_node_count = ha_node_ips.size
338 if (enable_ha) && (ha_node_count < 2)
339 # Check for HA_NODE_COUNT < 2
340 fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
344 ha_node_index = ha_node_ips.index(odl_bind_ip)
345 describe file('/opt/opendaylight/configuration/initial/akka.conf') do
346 it { should be_file }
347 it { should be_owned_by 'odl' }
348 it { should be_grouped_into 'odl' }
349 its(:content) { should match /roles\s*=\s*\["member-#{ha_node_index}"\]/ }
352 ha_db_modules.each do |mod, urn|
353 describe file('/opt/opendaylight/configuration/initial/module-shards.conf') do
354 it { should be_file }
355 it { should be_owned_by 'odl' }
356 it { should be_grouped_into 'odl' }
357 its(:content) { should match /name = "#{mod}"/ }
361 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
362 it { should be_file }
363 it { should be_owned_by 'odl' }
364 it { should be_grouped_into 'odl' }
367 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
368 it { should be_file }
369 it { should be_owned_by 'odl' }
370 it { should be_grouped_into 'odl' }
371 its(:content) { should match /name = "#{mod}"/ }
372 its(:content) { should match /namespace = "#{urn}"/ }
379 # Shared function that handles validations specific to RPM-type installs
380 def rpm_validations()
381 rpm_repo = ENV['RPM_REPO']
383 describe yumrepo('opendaylight') do
385 it { should be_enabled }
388 describe package('opendaylight') do
389 it { should be_installed }
393 # Shared function that handles validations specific to Deb-type installs
394 def deb_validations()
395 deb_repo = ENV['DEB_REPO']
397 # Docs: http://serverspec.org/resource_types.html#ppa
398 describe ppa(deb_repo) do
400 it { should be_enabled }
403 describe package('opendaylight') do
404 it { should be_installed }
408 # Shared function for validations related to username/password
409 def username_password_validations(options = {})
410 # NB: This param default should match the one used by the opendaylight
411 # class, which is defined in opendaylight::params
412 # TODO: Remove this possible source of bugs^^
413 odl_username = options.fetch(:username, 'admin')
414 odl_password = options.fetch(:password, 'admin')
415 odl_check_url = 'http://127.0.0.1:8181/restconf'
417 describe file('/opt/opendaylight/data/idmlight.db.mv.db') do
418 it { should be_file }
421 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
422 its(:exit_status) { should eq 0 }
425 describe command("curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
426 its(:exit_status) { should eq 0 }
430 # Shared function for validations related to the SNAT config file
431 def snat_mechanism_validations(options = {})
432 # NB: This param default should match the one used by the opendaylight
433 # class, which is defined in opendaylight::params
434 # TODO: Remove this possible source of bugs^^
435 snat_mechanism = options.fetch(:snat_mechanism, 'controller')
437 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml') do
438 it { should be_file }
439 it { should be_owned_by 'odl' }
440 it { should be_grouped_into 'odl' }
441 its(:content) { should match /<nat-mode>#{snat_mechanism}<\/nat-mode>/ }
445 # Shared function for validations related to SFC
446 def sfc_validations()
447 # NB: This param default should match the one used by the opendaylight
448 # class, which is defined in opendaylight::params
449 # TODO: Remove this possible source of bugs^^
451 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml') do
452 it { should be_file }
453 it { should be_owned_by 'odl' }
454 it { should be_grouped_into 'odl' }
455 its(:content) { should match /<use-of-tunnels>true<\/use-of-tunnels>/ }
458 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
459 it { should be_file }
460 it { should be_owned_by 'odl' }
461 it { should be_grouped_into 'odl' }
462 its(:content) { should match /<gpe-extension-enabled>true<\/gpe-extension-enabled>/ }
466 def websocket_address_validations(options = {})
467 # NB: This param default should match the one used by the opendaylight
468 # class, which is defined in opendaylight::params
469 # TODO: Remove this possible source of bugs^^
470 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
472 if not odl_bind_ip.eql? '0.0.0.0'
473 describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
474 it { should be_file }
475 it { should be_owned_by 'odl' }
476 it { should be_grouped_into 'odl' }
477 its(:content) { should match /^websocket-address=#{odl_bind_ip}/ }
480 describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
481 it { should be_file }
486 def tls_validations(options = {})
487 # NB: This param default should match the one used by the opendaylight
488 # class, which is defined in opendaylight::params
489 # TODO: Remove this possible source of bugs^^
490 tls_keystore_password = options.fetch(:tls_keystore_password)
491 odl_rest_port = options.fetch(:odl_rest_port, 8181)
493 describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
494 it { should be_file }
495 it { should be_owned_by 'odl' }
496 it { should be_grouped_into 'odl' }
497 its(:content) { should match /org.osgi.service.http.port.secure = #{odl_rest_port}/ }
498 its(:content) { should match /org.ops4j.pax.web.ssl.keystore = configuration\/ssl\/ctl.jks/ }
499 its(:content) { should match /org.ops4j.pax.web.ssl.password = #{tls_keystore_password}/ }
500 its(:content) { should match /org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}/ }
501 its(:content) { should match /org.osgi.service.http.secure.enabled = true/ }
502 its(:content) { should match /org.osgi.service.http.enabled = false/ }
505 describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
506 it { should be_file }
507 it { should be_owned_by 'odl' }
508 it { should be_grouped_into 'odl' }
509 its(:content) { should match /use-ssl = true/ }
512 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml') do
513 it { should be_file }
514 it { should be_owned_by 'odl' }
515 it { should be_grouped_into 'odl' }
516 its(:content) { should match /<keystore-password>#{tls_keystore_password}<\/keystore-password>/ }
517 its(:content) { should match /<truststore-password>#{tls_keystore_password}<\/truststore-password>/ }
518 its(:content) { should match /<transport-protocol>TLS<\/transport-protocol>/ }
521 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml') do
522 it { should be_file }
523 it { should be_owned_by 'odl' }
524 it { should be_grouped_into 'odl' }
525 its(:content) { should match /<store-password>#{tls_keystore_password}<\/store-password>/ }
526 its(:content) { should match /<use-mdsal>false<\/use-mdsal>/ }
529 describe file('/opt/opendaylight/etc/jetty.xml') do
530 it { should be_file }
531 it { should be_owned_by 'odl' }
532 it { should be_grouped_into 'odl' }
533 its(:content) { should match /<Property name="jetty.secure.port" default="#{odl_rest_port}" \/>/ }