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, 8080)
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')
71 # Build script for consumption by Puppet apply
72 it 'should work idempotently with no errors' do
74 class { 'opendaylight':
75 rpm_repo => '#{rpm_repo}',
76 deb_repo => '#{deb_repo}',
77 default_features => #{default_features},
78 extra_features => #{extra_features},
79 odl_rest_port => #{odl_rest_port},
80 odl_bind_ip => '#{odl_bind_ip}',
81 enable_ha => #{enable_ha},
82 ha_node_ips => #{ha_node_ips},
83 ha_node_index => #{ha_node_index},
84 ha_db_modules => #{ha_db_modules},
85 log_levels => #{log_levels},
86 username => #{username},
87 password => #{password},
88 log_max_size => '#{log_max_size}',
89 log_max_rollover => #{log_max_rollover},
90 snat_mechanism => #{snat_mechanism},
91 enable_tls => #{enable_tls},
92 tls_keystore_password => #{tls_keystore_password},
96 # Apply our Puppet manifest on the Beaker host
97 apply_manifest(pp, :catch_failures => true)
99 # Not checking for idempotence because of false failures
100 # related to package manager cache updates outputting to
101 # stdout and different IDs for the puppet manifest apply.
102 # I think this is a limitation in how Beaker can check
103 # for changes, not a problem with the Puppet module.
107 # Shared function that handles generic validations
108 # These should be common for all odl class param combos
109 def generic_validations()
110 # Verify ODL's directory
111 describe file('/opt/opendaylight/') do
112 it { should be_directory }
113 it { should be_owned_by 'odl' }
114 it { should be_grouped_into 'odl' }
117 # Verify ODL's systemd service
118 describe service('opendaylight') do
119 it { should be_enabled }
120 it { should be_enabled.with_level(3) }
121 it { should be_running.under('systemd') }
124 # Creation handled by RPM or Deb
125 describe user('odl') do
127 it { should belong_to_group 'odl' }
128 # NB: This really shouldn't have a slash at the end!
129 # The home dir set by the RPM is `/opt/opendaylight`.
130 # Since we use the trailing slash elsewhere else, this
131 # may look like a style issue. It isn't! It will make
132 # Beaker tests fail if it ends with a `/`. A future
133 # version of the ODL RPM may change this.
134 it { should have_home_directory '/opt/opendaylight' }
137 # Creation handled by RPM or Deb
138 describe group('odl') do
142 # This should not be the odl user's home dir
143 describe file('/home/odl') do
144 # Home dir shouldn't be created for odl user
145 it { should_not be_directory }
148 # OpenDaylight will appear as a Java process
149 describe process('java') do
150 it { should be_running }
153 # Should contain Karaf features config file
154 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
155 it { should be_file }
156 it { should be_owned_by 'odl' }
157 it { should be_grouped_into 'odl' }
160 # Should contain ODL NB port config file
161 describe file('/opt/opendaylight/etc/jetty.xml') do
162 it { should be_file }
163 it { should be_owned_by 'odl' }
164 it { should be_grouped_into 'odl' }
167 # Should contain log level config file
168 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
169 it { should be_file }
170 it { should be_owned_by 'odl' }
171 it { should be_grouped_into 'odl' }
174 if ['centos-7', 'centos-7-docker'].include? ENV['RS_SET']
175 # Validations for modern Red Hat family OSs
177 # Verify ODL systemd .service file
178 describe file('/usr/lib/systemd/system/opendaylight.service') do
179 it { should be_file }
180 it { should be_owned_by 'root' }
181 it { should be_grouped_into 'root' }
182 it { should be_mode '644' }
185 # Java 8 should be installed
186 describe package('java-1.8.0-openjdk') do
187 it { should be_installed }
190 # Ubuntu 16.04 specific validation
191 elsif ['ubuntu-16', 'ubuntu-16-docker'].include? ENV['RS_SET']
193 # Verify ODL systemd .service file
194 describe file('/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('openjdk-8-jre-headless') do
203 it { should be_installed }
207 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
211 # Shared function for validations related to log file settings
212 def log_file_settings_validations(options = {})
213 # Should contain log level config file with correct file size and rollover values
214 log_max_size = options.fetch(:log_max_size, '10GB')
215 log_max_rollover = options.fetch(:log_max_rollover, 2)
217 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
218 it { should be_file }
219 it { should be_owned_by 'odl' }
220 it { should be_grouped_into 'odl' }
221 its(:content) { should match /^log4j.appender.out.maxFileSize=#{log_max_size}/ }
222 its(:content) { should match /^log4j.appender.out.maxBackupIndex=#{log_max_rollover}/ }
226 # Shared function for validations related to the Karaf config file
227 def karaf_config_validations(options = {})
228 # NB: These param defaults should match the ones used by the opendaylight
229 # class, which are defined in opendaylight::params
230 # TODO: Remove this possible source of bugs^^
231 extra_features = options.fetch(:extra_features, [])
232 default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
234 # Create one list of all of the features
235 features = default_features + extra_features
237 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
238 it { should be_file }
239 it { should be_owned_by 'odl' }
240 it { should be_grouped_into 'odl' }
241 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
245 # Shared function for validations related to the ODL REST port config file
246 def port_config_validations(options = {})
247 # NB: This param default should match the one used by the opendaylight
248 # class, which is defined in opendaylight::params
249 # TODO: Remove this possible source of bugs^^
250 odl_rest_port = options.fetch(:odl_rest_port, 8080)
252 describe file('/opt/opendaylight/etc/jetty.xml') do
253 it { should be_file }
254 it { should be_owned_by 'odl' }
255 it { should be_grouped_into 'odl' }
256 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
260 # Shared function for validations related to custom logging verbosity
261 def log_level_validations(options = {})
262 # NB: This param default should match the one used by the opendaylight
263 # class, which is defined 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
269 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
270 it { should be_file }
271 it { should be_owned_by 'odl' }
272 it { should be_grouped_into 'odl' }
275 # Should contain log level config file
276 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
277 it { should be_file }
278 it { should be_owned_by 'odl' }
279 it { should be_grouped_into 'odl' }
281 # Verify each custom log level config entry
282 log_levels.each_pair do |logger, level|
283 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.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 /^log4j.logger.#{logger}=#{level}/ }
293 # Shared function for validations related to ODL OVSDB HA config
294 def enable_ha_validations(options = {})
295 # NB: This param default should match the one used by the opendaylight
296 # class, which is defined in opendaylight::params
297 # TODO: Remove this possible source of bugs^^
298 enable_ha = options.fetch(:enable_ha, false)
299 ha_node_ips = options.fetch(:ha_node_ips, [])
300 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
301 ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
303 ha_node_count = ha_node_ips.size
305 if (enable_ha) && (ha_node_count < 2)
306 # Check for HA_NODE_COUNT < 2
307 fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
311 ha_node_index = ha_node_ips.index(odl_bind_ip)
312 describe file('/opt/opendaylight/configuration/initial/akka.conf') do
313 it { should be_file }
314 it { should be_owned_by 'odl' }
315 it { should be_grouped_into 'odl' }
316 its(:content) { should match /roles\s*=\s*\["member-#{ha_node_index}"\]/ }
319 ha_db_modules.each do |mod, urn|
320 describe file('/opt/opendaylight/configuration/initial/module-shards.conf') do
321 it { should be_file }
322 it { should be_owned_by 'odl' }
323 it { should be_grouped_into 'odl' }
324 its(:content) { should match /name = "#{mod}"/ }
328 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
329 it { should be_file }
330 it { should be_owned_by 'odl' }
331 it { should be_grouped_into 'odl' }
334 describe file('/opt/opendaylight/configuration/initial/modules.conf') do
335 it { should be_file }
336 it { should be_owned_by 'odl' }
337 it { should be_grouped_into 'odl' }
338 its(:content) { should match /name = "#{mod}"/ }
339 its(:content) { should match /namespace = "#{urn}"/ }
346 # Shared function that handles validations specific to RPM-type installs
347 def rpm_validations()
348 rpm_repo = ENV['RPM_REPO']
350 describe yumrepo('opendaylight') do
352 it { should be_enabled }
355 describe package('opendaylight') do
356 it { should be_installed }
360 # Shared function that handles validations specific to Deb-type installs
361 def deb_validations()
362 deb_repo = ENV['DEB_REPO']
364 # Docs: http://serverspec.org/resource_types.html#ppa
365 describe ppa(deb_repo) do
367 it { should be_enabled }
370 describe package('opendaylight') do
371 it { should be_installed }
375 # Shared function for validations related to username/password
376 def username_password_validations(options = {})
377 # NB: This param default should match the one used by the opendaylight
378 # class, which is defined in opendaylight::params
379 # TODO: Remove this possible source of bugs^^
380 odl_username = options.fetch(:username, 'admin')
381 odl_password = options.fetch(:password, 'admin')
382 odl_check_url = 'http://127.0.0.1:8080/restconf'
384 describe file('/opt/opendaylight/data/idmlight.db.mv.db') do
385 it { should be_file }
388 describe command("sleep 180 && curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
389 its(:exit_status) { should eq 0 }
393 # Shared function for validations related to the SNAT config file
394 def snat_mechanism_validations(options = {})
395 # NB: This param default should match the one used by the opendaylight
396 # class, which is defined in opendaylight::params
397 # TODO: Remove this possible source of bugs^^
398 snat_mechanism = options.fetch(:snat_mechanism, 'controller')
400 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml') do
401 it { should be_file }
402 it { should be_owned_by 'odl' }
403 it { should be_grouped_into 'odl' }
404 its(:content) { should match /<nat-mode>#{snat_mechanism}<\/nat-mode>/ }
408 # Shared function for validations related to SFC
409 def sfc_validations()
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^^
414 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml') do
415 it { should be_file }
416 it { should be_owned_by 'odl' }
417 it { should be_grouped_into 'odl' }
418 its(:content) { should match /<use-of-tunnels>true<\/use-of-tunnels>/ }
421 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
422 it { should be_file }
423 it { should be_owned_by 'odl' }
424 it { should be_grouped_into 'odl' }
425 its(:content) { should match /<gpe-extension-enabled>true<\/gpe-extension-enabled>/ }
429 def websocket_address_validations(options = {})
430 # NB: This param default should match the one used by the opendaylight
431 # class, which is defined in opendaylight::params
432 # TODO: Remove this possible source of bugs^^
433 odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
435 describe file('/opt/opendaylight/etc/opendaylight/karaf/10-rest-connector.xml') do
436 it { should be_file }
437 it { should be_owned_by 'odl' }
438 it { should be_grouped_into 'odl' }
439 its(:content) { should match /<websocket-address>#{odl_bind_ip}<\/websocket-address>/ }
443 def tls_validations(options = {})
444 # NB: This param default should match the one used by the opendaylight
445 # class, which is defined in opendaylight::params
446 # TODO: Remove this possible source of bugs^^
447 tls_keystore_password = options.fetch(:tls_keystore_password)
448 odl_rest_port = options.fetch(:odl_rest_port, 8080)
450 describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') 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 /org.osgi.service.http.port.secure = #{odl_rest_port}/ }
455 its(:content) { should match /org.ops4j.pax.web.ssl.keystore = configuration\/ssl\/ctl.jks/ }
456 its(:content) { should match /org.ops4j.pax.web.ssl.password = #{tls_keystore_password}/ }
457 its(:content) { should match /org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}/ }
458 its(:content) { should match /org.osgi.service.http.secure.enabled = true/ }
461 describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
462 it { should be_file }
463 it { should be_owned_by 'odl' }
464 it { should be_grouped_into 'odl' }
465 its(:content) { should match /use-ssl = true/ }
468 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml') do
469 it { should be_file }
470 it { should be_owned_by 'odl' }
471 it { should be_grouped_into 'odl' }
472 its(:content) { should match /<keystore-password>#{tls_keystore_password}<\/keystore-password>/ }
473 its(:content) { should match /<truststore-password>#{tls_keystore_password}<\/truststore-password>/ }
474 its(:content) { should match /<transport-protocol>TLS<\/transport-protocol>/ }
477 describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml') do
478 it { should be_file }
479 it { should be_owned_by 'odl' }
480 it { should be_grouped_into 'odl' }
481 its(:content) { should match /<store-password>#{tls_keystore_password}<\/store-password>/ }
482 its(:content) { should match /<use-mdsal>false<\/use-mdsal>/ }
485 describe file('/opt/opendaylight/etc/jetty.xml') do
486 it { should be_file }
487 it { should be_owned_by 'odl' }
488 it { should be_grouped_into 'odl' }
489 its(:content) { should match /<Property name="jetty.secure.port" default="#{odl_rest_port}" \/>/ }