Merge "Bump Puppet version 4.x to 5.x"
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper_acceptance.rb
1 require 'beaker-rspec/spec_helper'
2 require 'beaker-rspec/helpers/serverspec'
3 require 'beaker-puppet'
4
5 include Beaker::DSL::InstallUtils::FOSSUtils
6 include Beaker::DSL::InstallUtils::ModuleUtils
7 include Beaker::DSL::Helpers::PuppetHelpers
8
9 # Install Puppet on all Beaker hosts
10 unless ENV['BEAKER_provision'] == 'no'
11   hosts.each do |host|
12     # Install Puppet
13     install_puppet_agent_on(host, {:puppet_collection => "pc1"})
14   end
15 end
16
17 RSpec.configure do |c|
18   # Project root
19   proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
20
21   # Readable test descriptions
22   c.formatter = :documentation
23
24   # Configure all nodes in nodeset
25   c.before :suite do
26     # Install opendaylight module on any/all Beaker hosts
27     # TODO: Should this be done in host.each loop?
28     puppet_module_install(:source => proj_root, :module_name => 'opendaylight')
29     hosts.each do |host|
30       # Install stdlib, a dependency of the odl mod
31       on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0] }
32       # Install apt, a dependency of the deb install method
33       on host, puppet('module', 'install', 'puppetlabs-apt'), { :acceptable_exit_codes => [0] }
34     end
35   end
36 end
37
38 #
39 # NB: These are a library of helper fns used by the Beaker tests
40 #
41
42 # NB: There are a large number of helper functions used in these tests.
43 # They make this code much more friendly, but may need to be referenced.
44 # The serverspec helpers (`should`, `be_running`...) are documented here:
45 #   http://serverspec.org/resource_types.html
46
47 def install_odl(options = {})
48   # Install params are passed via environment var, set in Rakefile
49   # Changing the installed version of ODL via `puppet apply` is not supported
50   # by puppet-odl, so it's not possible to vary these params in the same
51   # Beaker test run. Do a different run passing different env vars.
52   rpm_repo = ENV['RPM_REPO']
53   deb_repo = ENV['DEB_REPO']
54
55   # NB: These param defaults should match the ones used by the opendaylight
56   #   class, which are defined in opendaylight::params
57   # Extract params if given, defaulting to odl class defaults if not
58   extra_features = options.fetch(:extra_features, ['odl-restconf'])
59   default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
60   odl_rest_port = options.fetch(:odl_rest_port, 8181)
61   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
62   log_levels = options.fetch(:log_levels, {})
63   enable_ha = options.fetch(:enable_ha, false)
64   ha_node_ips = options.fetch(:ha_node_ips, [])
65   ha_node_index = options.fetch(:ha_node_index, 0)
66   ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
67   username = options.fetch(:username, 'admin')
68   password = options.fetch(:password, 'admin')
69   log_max_size = options.fetch(:log_max_size, '500MB')
70   log_max_rollover = options.fetch(:log_max_rollover, 4)
71   log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
72   log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
73   enable_paxosgi_logger = options.fetch(:enable_paxosgi_logger, false)
74   snat_mechanism = options.fetch(:snat_mechanism, 'controller')
75   enable_tls = options.fetch(:enable_tls, false)
76   tls_keystore_password = options.fetch(:tls_keystore_password, 'dummypass')
77   log_mechanism = options.fetch(:log_mechanism, 'file')
78   inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
79   stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
80   inactivity_probe = options.fetch(:inactivity_probe, :undef)
81   java_opts = options.fetch(:java_opts, '')
82
83   # Build script for consumption by Puppet apply
84   it 'should work idempotently with no errors' do
85     pp = <<-EOS
86     class { 'opendaylight':
87       rpm_repo => '#{rpm_repo}',
88       deb_repo => '#{deb_repo}',
89       default_features => #{default_features},
90       extra_features => #{extra_features},
91       odl_rest_port => #{odl_rest_port},
92       odl_bind_ip => '#{odl_bind_ip}',
93       enable_ha => #{enable_ha},
94       ha_node_ips => #{ha_node_ips},
95       ha_node_index => #{ha_node_index},
96       ha_db_modules => #{ha_db_modules},
97       log_levels => #{log_levels},
98       username => #{username},
99       password => #{password},
100       log_max_size => '#{log_max_size}',
101       log_max_rollover => #{log_max_rollover},
102       log_pattern => '#{log_pattern}',
103       log_rollover_fileindex => #{log_rollover_fileindex},
104       enable_paxosgi_logger => #{enable_paxosgi_logger},
105       snat_mechanism => #{snat_mechanism},
106       enable_tls => #{enable_tls},
107       tls_keystore_password => #{tls_keystore_password},
108       log_mechanism => #{log_mechanism},
109       inherit_dscp_marking => #{inherit_dscp_marking},
110       stats_polling_enabled => #{stats_polling_enabled},
111       inactivity_probe => #{inactivity_probe},
112       java_opts => '#{java_opts}',
113     }
114     EOS
115
116     # Apply our Puppet manifest on the Beaker host
117     apply_manifest(pp, :catch_failures => true)
118
119     # Not checking for idempotence because of false failures
120     # related to package manager cache updates outputting to
121     # stdout and different IDs for the puppet manifest apply.
122     # I think this is a limitation in how Beaker can check
123     # for changes, not a problem with the Puppet module.
124     end
125 end
126
127 # Shared function that handles generic validations
128 # These should be common for all odl class param combos
129 def generic_validations(options = {})
130   # Verify ODL's directory
131   describe file('/opt/opendaylight/') do
132     it { should be_directory }
133     it { should be_owned_by 'odl' }
134     it { should be_grouped_into 'odl' }
135   end
136
137   # Verify ODL's systemd service
138   describe service('opendaylight') do
139     it { should be_enabled }
140     it { should be_enabled.with_level(3) }
141     it { should be_running.under('systemd') }
142   end
143
144   # Creation handled by RPM or Deb
145   describe user('odl') do
146     it { should exist }
147     it { should belong_to_group 'odl' }
148     # NB: This really shouldn't have a slash at the end!
149     #     The home dir set by the RPM is `/opt/opendaylight`.
150     #     Since we use the trailing slash elsewhere else, this
151     #     may look like a style issue. It isn't! It will make
152     #     Beaker tests fail if it ends with a `/`. A future
153     #     version of the ODL RPM may change this.
154     it { should have_home_directory '/opt/opendaylight' }
155   end
156
157   # Creation handled by RPM or Deb
158   describe group('odl') do
159     it { should exist }
160   end
161
162   # This should not be the odl user's home dir
163   describe file('/home/odl') do
164     # Home dir shouldn't be created for odl user
165     it { should_not be_directory }
166   end
167
168   # OpenDaylight will appear as a Java process
169   describe process('java') do
170     it { should be_running }
171   end
172
173   # Should contain Karaf features config file
174   describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
175     it { should be_file }
176     it { should be_owned_by 'odl' }
177     it { should be_grouped_into 'odl' }
178   end
179
180   java_opts = options.fetch(:java_opts, '')
181   odl_bind_ip = options.fetch(:odl_bind_ip, '127.0.0.1')
182   if odl_bind_ip == '127.0.0.1'
183     java_options = ['-Djava.net.preferIPv4Stack=true', java_opts].join(' ').strip
184   else
185     java_options = ['-Djava.net.preferIPv6Addresses=true', java_opts].join(' ').strip
186   end
187
188   # Should contain karaf file with Java options set
189   describe file('/opt/opendaylight/bin/karaf') do
190     it { should be_file }
191     it { should be_owned_by 'odl' }
192     it { should be_grouped_into 'odl' }
193     its(:content) { should match /^EXTRA_JAVA_OPTS=\"#{java_options}\"/ }
194   end
195
196   describe command do ("ps -ef | grep opendaylight | grep #{java_options}")
197     its(:exit_status) { should eq 0 }
198   end
199
200   # Should contain ODL NB port config file
201   describe file('/opt/opendaylight/etc/jetty.xml') do
202     it { should be_file }
203     it { should be_owned_by 'odl' }
204     it { should be_grouped_into 'odl' }
205   end
206
207   # Should contain log level config file
208   describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
209     it { should be_file }
210     it { should be_owned_by 'odl' }
211     it { should be_grouped_into 'odl' }
212   end
213
214   if ['centos-7', 'centos-7-docker'].include? ENV['RS_SET']
215     # Validations for modern Red Hat family OSs
216
217     # Verify ODL systemd .service file
218     describe file('/usr/lib/systemd/system/opendaylight.service') do
219       it { should be_file }
220       it { should be_owned_by 'root' }
221       it { should be_grouped_into 'root' }
222       it { should be_mode '644' }
223     end
224
225     # Java 8 should be installed
226     describe package('java-1.8.0-openjdk') do
227       it { should be_installed }
228     end
229
230   # Ubuntu 16.04 specific validation
231   elsif ['ubuntu-16', 'ubuntu-16-docker'].include? ENV['RS_SET']
232
233     # Verify ODL systemd .service file
234     describe file('/lib/systemd/system/opendaylight.service') do
235       it { should be_file }
236       it { should be_owned_by 'root' }
237       it { should be_grouped_into 'root' }
238       it { should be_mode '644' }
239     end
240
241     # Java 8 should be installed
242     describe package('openjdk-8-jre-headless') do
243       it { should be_installed }
244     end
245
246   else
247     fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
248   end
249 end
250
251 # Shared function for validations related to log file settings
252 def log_settings_validations(options = {})
253   # Should contain log level config file with correct file size and rollover values
254   log_max_size = options.fetch(:log_max_size, '500MB')
255   log_max_rollover = options.fetch(:log_max_rollover, 4)
256   log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
257   log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
258   log_mechanism = options.fetch(:log_mechanism, 'file')
259   enable_paxosgi_logger = options.fetch(:enable_paxosgi_logger, false)
260
261   if log_mechanism == 'console'
262     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
263       it { should be_file }
264       it { should be_owned_by 'odl' }
265       it { should be_grouped_into 'odl' }
266       its(:content) { should match /^karaf.log.console=INFO/ }
267       its(:content) { should match /^log4j2.appender.console.direct = true/ }
268     end
269   else
270     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
271       it { should be_file }
272       it { should be_owned_by 'odl' }
273       it { should be_grouped_into 'odl' }
274       its(:content) { should match /^log4j2.appender.rolling.policies.size.size = #{log_max_size}/ }
275       its(:content) { should match /^log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy/ }
276       its(:content) { should match /^log4j2.appender.rolling.strategy.max = #{log_max_rollover}/ }
277       its(:content) { should match /^log4j2.appender.rolling.strategy.fileIndex = #{log_rollover_fileindex}/ }
278     end
279   end
280   describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
281     its(:content) { should match /^log4j2.pattern = #{log_pattern}/ }
282     if enable_paxosgi_logger == true
283         its(:content) { should match /^log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi/ }
284         its(:content) { should match /^# OSGi appender/ }
285         its(:content) { should match /^log4j2.appender.osgi.type = PaxOsgi/ }
286         its(:content) { should match /^log4j2.appender.osgi.name = PaxOsgi/ }
287         its(:content) { should match /^log4j2.appender.osgi.filter = */ }
288     else
289         its(:content) { should_not match /^log4j2.rootLogger.appenderRef.PaxOsgi.ref = PaxOsgi/ }
290         its(:content) { should_not match /^# OSGi appender/ }
291         its(:content) { should_not match /^log4j2.appender.osgi.type = PaxOsgi/ }
292         its(:content) { should_not match /^log4j2.appender.osgi.name = PaxOsgi/ }
293         its(:content) { should_not match /^log4j2.appender.osgi.filter = */ }
294     end
295   end
296 end
297
298 # Shared function for validations related to the Karaf config file
299 def karaf_config_validations(options = {})
300   # NB: These param defaults should match the ones used by the opendaylight
301   #   class, which are defined in opendaylight::params
302   extra_features = options.fetch(:extra_features, [])
303   default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
304
305   # Create one list of all of the features
306   features = default_features + extra_features
307
308   describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
309     it { should be_file }
310     it { should be_owned_by 'odl' }
311     it { should be_grouped_into 'odl' }
312     its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
313   end
314 end
315
316 # Shared function for validations related to the ODL REST port config file
317 def port_config_validations(options = {})
318   # NB: This param default should match the one used by the opendaylight
319   #   class, which is defined in opendaylight::params
320   odl_rest_port = options.fetch(:odl_rest_port, 8181)
321
322   describe file('/opt/opendaylight/etc/jetty.xml') do
323     it { should be_file }
324     it { should be_owned_by 'odl' }
325     it { should be_grouped_into 'odl' }
326     its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
327   end
328
329   describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
330     it { should be_file }
331     it { should be_owned_by 'odl' }
332     it { should be_grouped_into 'odl' }
333     its(:content) { should match /org.osgi.service.http.port = #{odl_rest_port}/ }
334   end
335 end
336
337 # Shared function for validations related to the ODL bind IP
338 def odl_bind_ip_validation(options = {})
339   # NB: This param default should match the one used by the opendaylight
340   #   class, which is defined in opendaylight::params
341   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
342
343   if odl_bind_ip != '0.0.0.0'
344     describe file('/opt/opendaylight/etc/org.apache.karaf.shell.cfg') 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 /sshHost = #{odl_bind_ip}/ }
349     end
350
351     describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
352       it { should be_file }
353       it { should be_owned_by 'odl' }
354       it { should be_grouped_into 'odl' }
355       its(:content) { should match /ovsdb-listener-ip = #{odl_bind_ip}/ }
356     end
357
358     describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml') do
359       it { should be_file }
360       it { should be_owned_by 'odl' }
361       it { should be_grouped_into 'odl' }
362       its(:content) { should match /<address>#{odl_bind_ip}<\/address>/ }
363     end
364
365     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
366       its(:exit_status) { should eq 0 }
367     end
368
369     describe command("loop_count=0; until [[ \$loop_count -ge 60 ]]; do netstat -punta | grep 6653 | 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
370       its(:exit_status) { should eq 0 }
371     end
372
373     describe command("loop_count=0; until [[ \$loop_count -ge 60 ]]; do netstat -punta | grep 6640 | 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
374       its(:exit_status) { should eq 0 }
375     end
376   end
377 end
378
379 # Shared function for validations related to custom logging verbosity
380 def log_level_validations(options = {})
381   # NB: This param default should match the one used by the opendaylight
382   #   class, which is defined in opendaylight::params
383   log_levels = options.fetch(:log_levels, {})
384
385   if log_levels.empty?
386     # Should contain log level config file
387     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
388       it { should be_file }
389       it { should be_owned_by 'odl' }
390       it { should be_grouped_into 'odl' }
391     end
392   else
393     # Should contain log level config file
394     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
395       it { should be_file }
396       it { should be_owned_by 'odl' }
397       it { should be_grouped_into 'odl' }
398     end
399     # Verify each custom log level config entry
400     log_levels.each_pair do |logger, level|
401       underscored_version = "#{logger}".gsub('.', '_')
402       describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
403         it { should be_file }
404         it { should be_owned_by 'odl' }
405         it { should be_grouped_into 'odl' }
406         its(:content) { should match /^log4j2.logger.#{underscored_version}.level = #{level}/ }
407         its(:content) { should match /^log4j2.logger.#{underscored_version}.name = #{logger}/ }
408       end
409     end
410   end
411 end
412
413 # Shared function for validations related to ODL OVSDB HA config
414 def enable_ha_validations(options = {})
415   # NB: This param default should match the one used by the opendaylight
416   #   class, which is defined in opendaylight::params
417   enable_ha = options.fetch(:enable_ha, false)
418   ha_node_ips = options.fetch(:ha_node_ips, [])
419   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
420   ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
421   # HA_NODE_IPS size
422   ha_node_count = ha_node_ips.size
423
424   if (enable_ha) && (ha_node_count < 2)
425     # Check for HA_NODE_COUNT < 2
426     fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
427   end
428
429   if enable_ha
430     ha_node_index = ha_node_ips.index(odl_bind_ip)
431     describe file('/opt/opendaylight/configuration/initial/akka.conf') do
432       it { should be_file }
433       it { should be_owned_by 'odl' }
434       it { should be_grouped_into 'odl' }
435       its(:content) { should match /roles\s*=\s*\["member-#{ha_node_index}"\]/ }
436     end
437
438     ha_db_modules.each do |mod, urn|
439       describe file('/opt/opendaylight/configuration/initial/module-shards.conf') do
440         it { should be_file }
441         it { should be_owned_by 'odl' }
442         it { should be_grouped_into 'odl' }
443         its(:content) { should match /name = "#{mod}"/ }
444       end
445
446       if mod == 'default'
447         describe file('/opt/opendaylight/configuration/initial/modules.conf') do
448           it { should be_file }
449           it { should be_owned_by 'odl' }
450           it { should be_grouped_into 'odl' }
451         end
452       else
453         describe file('/opt/opendaylight/configuration/initial/modules.conf') do
454           it { should be_file }
455           it { should be_owned_by 'odl' }
456           it { should be_grouped_into 'odl' }
457           its(:content) { should match /name = "#{mod}"/ }
458           its(:content) { should match /namespace = "#{urn}"/ }
459         end
460       end
461     end
462   end
463 end
464
465 # Shared function that handles validations specific to RPM-type installs
466 def rpm_validations()
467   rpm_repo = ENV['RPM_REPO']
468
469   describe yumrepo('opendaylight') do
470     it { should exist }
471     it { should be_enabled }
472   end
473
474   describe package('opendaylight') do
475     it { should be_installed }
476   end
477 end
478
479 # Shared function that handles validations specific to Deb-type installs
480 def deb_validations()
481   deb_repo = ENV['DEB_REPO']
482   # Check ppa
483   # Docs: http://serverspec.org/resource_types.html#ppa
484   describe ppa(deb_repo) do
485     it { should exist }
486     it { should be_enabled }
487   end
488
489   describe package('opendaylight') do
490     it { should be_installed }
491   end
492 end
493
494 # Shared function for validations related to username/password
495 def username_password_validations(options = {})
496   # NB: This param default should match the one used by the opendaylight
497   #   class, which is defined in opendaylight::params
498   odl_username = options.fetch(:username, 'admin')
499   odl_password = options.fetch(:password, 'admin')
500   odl_check_url = 'http://127.0.0.1:8181/restconf'
501
502   describe file('/opt/opendaylight/data/idmlight.db.mv.db') do
503     it { should be_file }
504   end
505
506   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
507     its(:exit_status) { should eq 0 }
508   end
509
510   describe command("curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do
511     its(:exit_status) { should eq 0 }
512   end
513 end
514
515 # Shared function for validations related to the SNAT config file
516 def snat_mechanism_validations(options = {})
517   # NB: This param default should match the one used by the opendaylight
518   #   class, which is defined in opendaylight::params
519   snat_mechanism = options.fetch(:snat_mechanism, 'controller')
520
521   describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-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 /<nat-mode>#{snat_mechanism}<\/nat-mode>/ }
526   end
527 end
528
529 # Shared function for validations related to SFC
530 def sfc_validations(options = {})
531   # NB: This param default should match the one used by the opendaylight
532   #   class, which is defined in opendaylight::params
533
534   extra_features = options.fetch(:extra_features, [])
535   if extra_features.include? 'odl-netvirt-sfc'
536     sfc_enabled = true
537   else
538     sfc_enabled = false
539   end
540
541   describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
542     it { should be_file }
543     it { should be_owned_by 'odl' }
544     it { should be_grouped_into 'odl' }
545     its(:content) { should match /<gpe-extension-enabled>#{sfc_enabled}<\/gpe-extension-enabled>/ }
546   end
547 end
548
549 # Shared function for validations related to tos value for DSCP marking
550 def dscp_validations(options = {})
551   # NB: This param default should match the one used by the opendaylight
552   #   class, which is defined in opendaylight::params
553
554   inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
555
556   if inherit_dscp_marking
557     describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml') do
558       it { should be_file }
559       it { should be_owned_by 'odl' }
560       it { should be_grouped_into 'odl' }
561       its(:content) { should match /<default-tunnel-tos>inherit<\/default-tunnel-tos>/ }
562     end
563   end
564 end
565
566 def websocket_address_validations(options = {})
567   # NB: This param default should match the one used by the opendaylight
568   #   class, which is defined in opendaylight::params
569   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
570
571   if not odl_bind_ip.eql? '0.0.0.0'
572     describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') 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 /^websocket-address=#{odl_bind_ip}/ }
577     end
578   else
579     describe file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg') do
580       it { should be_file }
581     end
582   end
583 end
584
585 def tls_validations(options = {})
586   # NB: This param default should match the one used by the opendaylight
587   #   class, which is defined in opendaylight::params
588   tls_keystore_password = options.fetch(:tls_keystore_password)
589   odl_rest_port = options.fetch(:odl_rest_port, 8181)
590
591   describe file('/opt/opendaylight/etc/org.ops4j.pax.web.cfg') do
592     it { should be_file }
593     it { should be_owned_by 'odl' }
594     it { should be_grouped_into 'odl' }
595     its(:content) { should match /org.osgi.service.http.port.secure = #{odl_rest_port}/ }
596     its(:content) { should match /org.ops4j.pax.web.ssl.keystore = configuration\/ssl\/ctl.jks/ }
597     its(:content) { should match /org.ops4j.pax.web.ssl.password = #{tls_keystore_password}/ }
598     its(:content) { should match /org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}/ }
599     its(:content) { should match /org.osgi.service.http.secure.enabled = true/ }
600     its(:content) { should match /org.osgi.service.http.enabled = false/ }
601   end
602
603   describe file('/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg') do
604     it { should be_file }
605     it { should be_owned_by 'odl' }
606     it { should be_grouped_into 'odl' }
607     its(:content) { should match /use-ssl = true/ }
608   end
609
610   describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml') do
611     it { should be_file }
612     it { should be_owned_by 'odl' }
613     it { should be_grouped_into 'odl' }
614     its(:content) { should match /<keystore-password>#{tls_keystore_password}<\/keystore-password>/ }
615     its(:content) { should match /<truststore-password>#{tls_keystore_password}<\/truststore-password>/ }
616     its(:content) { should match /<transport-protocol>TLS<\/transport-protocol>/ }
617   end
618
619   describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml') do
620     it { should be_file }
621     it { should be_owned_by 'odl' }
622     it { should be_grouped_into 'odl' }
623     its(:content) { should match /<store-password>#{tls_keystore_password}<\/store-password>/ }
624     its(:content) { should match /<use-mdsal>false<\/use-mdsal>/ }
625   end
626
627   describe file('/opt/opendaylight/etc/jetty.xml') do
628     it { should be_file }
629     it { should be_owned_by 'odl' }
630     it { should be_grouped_into 'odl' }
631     its(:content) { should match /<Property name="jetty.secure.port" default="#{odl_rest_port}" \/>/ }
632   end
633 end
634
635 # Shared function for validations related to OVS statistics polling
636 def stats_polling_validations(options = {})
637   # NB: This param default should match the one used by the opendaylight
638   #   class, which is defined in opendaylight::params
639
640   stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
641   describe file('/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg') do
642     it { should be_file }
643     it { should be_owned_by 'odl' }
644     it { should be_grouped_into 'odl' }
645     its(:content) { should match /is-statistics-polling-on=#{stats_polling_enabled}/ }
646   end
647 end
648
649 # Shared function for validations related to inactivity probe
650 def inactivity_probe_validations(options = {})
651   # NB: This param default should match the one used by the opendaylight
652   #   class, which is defined in opendaylight::params
653
654   inactivity_probe = options.fetch(:inactivity_probe, :undef)
655   unless inactivity_probe == :undef
656     describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml') do
657       it { should be_file }
658       it { should be_owned_by 'odl' }
659       it { should be_grouped_into 'odl' }
660       its(:content) { should match /<controller-inactivity-probe>#{inactivity_probe}/ }
661     end
662   end
663 end