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/ }
238 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
239 it { should be_file }
240 it { should be_owned_by 'odl' }
241 it { should be_grouped_into 'odl' }
242 its(:content) { should match /^log4j2.appender.rolling.policies.size.size = #{log_max_size}/ }
243 its(:content) { should match /^log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy/ }
244 its(:content) { should match /^log4j2.appender.rolling.strategy.max = #{log_max_rollover}/ }
249 # Shared function for validations related to the Karaf config file
250 def karaf_config_validations(options = {})
251 # NB: These param defaults should match the ones used by the opendaylight
252 # class, which are defined in opendaylight::params
253 # TODO: Remove this possible source of bugs^^
254 extra_features = options.fetch(:extra_features, [])
255 default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
257 # Create one list of all of the features
258 features = default_features + extra_features
260 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
261 it { should be_file }
262 it { should be_owned_by 'odl' }
263 it { should be_grouped_into 'odl' }
264 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
268 # Shared function for validations related to the ODL REST port config file
269 def port_config_validations(options = {})
270 # NB: This param default should match the one used by the opendaylight
271 # class, which is defined in opendaylight::params
272 # TODO: Remove this possible source of bugs^^
273 odl_rest_port = options.fetch(:odl_rest_port, 8181)
275 describe file('/opt/opendaylight/etc/jetty.xml') do
276 it { should be_file }
277 it { should be_owned_by 'odl' }
278 it { should be_grouped_into 'odl' }
279 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
282 describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
283 it { should be_file }
284 it { should be_owned_by 'odl' }
285 it { should be_grouped_into 'odl' }
286 its(:content) { should match /org.osgi.service.http.port = #{odl_rest_port}/ }
290 # Shared function for validations related to custom logging verbosity
291 def log_level_validations(options = {})
292 # NB: This param default should match the one used by the opendaylight
293 # class, which is defined in opendaylight::params
294 # TODO: Remove this possible source of bugs^^
295 log_levels = options.fetch(:log_levels, {})
298 # Should contain log level config file
299 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
300 it { should be_file }
301 it { should be_owned_by 'odl' }
302 it { should be_grouped_into 'odl' }
305 # Should contain log level config file
306 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
307 it { should be_file }
308 it { should be_owned_by 'odl' }
309 it { should be_grouped_into 'odl' }
311 # Verify each custom log level config entry
312 log_levels.each_pair do |logger, level|
313 underscored_version = "#{logger}".gsub('.', '_')
314 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
315 it { should be_file }
316 it { should be_owned_by 'odl' }
317 it { should be_grouped_into 'odl' }
318 its(:content) { should match /^log4j2.logger.#{underscored_version}.level = #{level}/ }
319 its(:content) { should match /^log4j2.logger.#{underscored_version}.name = #{logger}/ }
325 # Shared function for validations related to ODL OVSDB HA config
326 def enable_ha_validations(options = {})
327 # NB: This param default should match the one used by the opendaylight
328 # class, which is defined in opendaylight::params
329 # TODO: Remove this possible source of bugs^^
330 enable_ha = options.fetch(:enable_ha, false)
331 ha_node_ips = options.fetch(:ha_node_ips, [])
332 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
333 ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
335 ha_node_count = ha_node_ips.size
337 if (enable_ha) && (ha_node_count < 2)
338 # Check for HA_NODE_COUNT < 2
339 fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
343 ha_node_index = ha_node_ips.index(odl_bind_ip)
344 describe file('/opt/opendaylight/configuration/initial/akka.conf') do
345 it { should be_file }
346 it { should be_owned_by 'odl' }
347 it { should be_grouped_into 'odl' }
348 its(:content) { should match /roles\s*=\s*\["member-#{ha_node_index}"\]/ }
351 ha_db_modules.each do |mod, urn|
352 describe file('/opt/opendaylight/configuration/initial/module-shards.conf') do
353 it { should be_file }
354 it { should be_owned_by 'odl' }
355 it { should be_grouped_into 'odl' }
356 its(:content) { should match /name = "#{mod}"/ }
360 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
361 it { should be_file }
362 it { should be_owned_by 'odl' }
363 it { should be_grouped_into 'odl' }
366 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
367 it { should be_file }
368 it { should be_owned_by 'odl' }
369 it { should be_grouped_into 'odl' }
370 its(:content) { should match /name = "#{mod}"/ }
371 its(:content) { should match /namespace = "#{urn}"/ }
378 # Shared function that handles validations specific to RPM-type installs
379 def rpm_validations()
380 rpm_repo = ENV['RPM_REPO']
382 describe yumrepo('opendaylight') do
384 it { should be_enabled }
387 describe package('opendaylight') do
388 it { should be_installed }
392 # Shared function that handles validations specific to Deb-type installs
393 def deb_validations()
394 deb_repo = ENV['DEB_REPO']
396 # Docs: http://serverspec.org/resource_types.html#ppa
397 describe ppa(deb_repo) do
399 it { should be_enabled }
402 describe package('opendaylight') do
403 it { should be_installed }
407 # Shared function for validations related to username/password
408 def username_password_validations(options = {})
409 # NB: This param default should match the one used by the opendaylight
410 # class, which is defined in opendaylight::params
411 # TODO: Remove this possible source of bugs^^
412 odl_username = options.fetch(:username, 'admin')
413 odl_password = options.fetch(:password, 'admin')
414 odl_check_url = 'http://127.0.0.1:8181/restconf'
416 describe file('/opt/opendaylight/data/idmlight.db.mv.db') do
417 it { should be_file }
420 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
421 its(:exit_status) { should eq 0 }
424 describe command("curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
425 its(:exit_status) { should eq 0 }
429 # Shared function for validations related to the SNAT config file
430 def snat_mechanism_validations(options = {})
431 # NB: This param default should match the one used by the opendaylight
432 # class, which is defined in opendaylight::params
433 # TODO: Remove this possible source of bugs^^
434 snat_mechanism = options.fetch(:snat_mechanism, 'controller')
436 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml') do
437 it { should be_file }
438 it { should be_owned_by 'odl' }
439 it { should be_grouped_into 'odl' }
440 its(:content) { should match /<nat-mode>#{snat_mechanism}<\/nat-mode>/ }
444 # Shared function for validations related to SFC
445 def sfc_validations()
446 # NB: This param default should match the one used by the opendaylight
447 # class, which is defined in opendaylight::params
448 # TODO: Remove this possible source of bugs^^
450 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml') do
451 it { should be_file }
452 it { should be_owned_by 'odl' }
453 it { should be_grouped_into 'odl' }
454 its(:content) { should match /<use-of-tunnels>true<\/use-of-tunnels>/ }
457 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
458 it { should be_file }
459 it { should be_owned_by 'odl' }
460 it { should be_grouped_into 'odl' }
461 its(:content) { should match /<gpe-extension-enabled>true<\/gpe-extension-enabled>/ }
465 def websocket_address_validations(options = {})
466 # NB: This param default should match the one used by the opendaylight
467 # class, which is defined in opendaylight::params
468 # TODO: Remove this possible source of bugs^^
469 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
471 if not odl_bind_ip.eql? '0.0.0.0'
472 describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
473 it { should be_file }
474 it { should be_owned_by 'odl' }
475 it { should be_grouped_into 'odl' }
476 its(:content) { should match /^websocket-address=#{odl_bind_ip}/ }
479 describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
480 it { should be_file }
485 def tls_validations(options = {})
486 # NB: This param default should match the one used by the opendaylight
487 # class, which is defined in opendaylight::params
488 # TODO: Remove this possible source of bugs^^
489 tls_keystore_password = options.fetch(:tls_keystore_password)
490 odl_rest_port = options.fetch(:odl_rest_port, 8181)
492 describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
493 it { should be_file }
494 it { should be_owned_by 'odl' }
495 it { should be_grouped_into 'odl' }
496 its(:content) { should match /org.osgi.service.http.port.secure = #{odl_rest_port}/ }
497 its(:content) { should match /org.ops4j.pax.web.ssl.keystore = configuration\/ssl\/ctl.jks/ }
498 its(:content) { should match /org.ops4j.pax.web.ssl.password = #{tls_keystore_password}/ }
499 its(:content) { should match /org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}/ }
500 its(:content) { should match /org.osgi.service.http.secure.enabled = true/ }
501 its(:content) { should match /org.osgi.service.http.enabled = false/ }
504 describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
505 it { should be_file }
506 it { should be_owned_by 'odl' }
507 it { should be_grouped_into 'odl' }
508 its(:content) { should match /use-ssl = true/ }
511 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml') do
512 it { should be_file }
513 it { should be_owned_by 'odl' }
514 it { should be_grouped_into 'odl' }
515 its(:content) { should match /<keystore-password>#{tls_keystore_password}<\/keystore-password>/ }
516 its(:content) { should match /<truststore-password>#{tls_keystore_password}<\/truststore-password>/ }
517 its(:content) { should match /<transport-protocol>TLS<\/transport-protocol>/ }
520 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml') do
521 it { should be_file }
522 it { should be_owned_by 'odl' }
523 it { should be_grouped_into 'odl' }
524 its(:content) { should match /<store-password>#{tls_keystore_password}<\/store-password>/ }
525 its(:content) { should match /<use-mdsal>false<\/use-mdsal>/ }
528 describe file('/opt/opendaylight/etc/jetty.xml') do
529 it { should be_file }
530 it { should be_owned_by 'odl' }
531 it { should be_grouped_into 'odl' }
532 its(:content) { should match /<Property name="jetty.secure.port" default="#{odl_rest_port}" \/>/ }