Merge "Support multiple argumets for EXTRA_JAVA_OPTS"
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper.rb
1 require 'puppetlabs_spec_helper/module_spec_helper'
2 require 'rspec-puppet-facts'
3 include RspecPuppetFacts
4
5 # Customize filters to ignore 3rd-party code
6 # If the rspec coverage report shows not-our-code results, add it here
7 custom_filters = [
8 ]
9 RSpec::Puppet::Coverage.filters.push(*custom_filters)
10
11 #
12 # NB: This is a library of helper fns used by the rspec-puppet tests
13 #
14
15 # Tests that are common to all possible configurations
16 def generic_tests(options = {})
17   java_opts = options.fetch(:java_opts, '')
18   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
19   inactivity_probe = options.fetch(:inactivity_probe, :undef)
20
21   # Confirm that module compiles
22   it { should compile }
23   it { should compile.with_all_deps }
24
25   # Confirm presence of classes
26   it { should contain_class('opendaylight') }
27   it { should contain_class('opendaylight::params') }
28   it { should contain_class('opendaylight::install') }
29   it { should contain_class('opendaylight::config') }
30   it { should contain_class('opendaylight::post_config') }
31   it { should contain_class('opendaylight::service') }
32
33   # Confirm relationships between classes
34   it { should contain_class('opendaylight::install').that_comes_before('Class[opendaylight::config]') }
35   it { should contain_class('opendaylight::config').that_requires('Class[opendaylight::install]') }
36   it { should contain_class('opendaylight::config').that_notifies('Class[opendaylight::service]') }
37   it { should contain_class('opendaylight::service').that_subscribes_to('Class[opendaylight::config]') }
38   it { should contain_class('opendaylight::service').that_comes_before('Class[opendaylight]') }
39   it { should contain_class('opendaylight::post_config').that_requires('Class[opendaylight::service]') }
40   it { should contain_class('opendaylight::post_config').that_comes_before('Class[opendaylight]') }
41   it { should contain_class('opendaylight').that_requires('Class[opendaylight::service]') }
42
43   # Confirm presence of generic resources
44   it { should contain_service('opendaylight') }
45   it { should contain_file('org.apache.karaf.features.cfg') }
46
47   # Confirm properties of generic resources
48   # NB: These hashes don't work with Ruby 1.8.7, but we
49   #   don't support 1.8.7 so that's okay. See issue #36.
50   it {
51     should contain_service('opendaylight').with(
52       'ensure'      => 'running',
53       'enable'      => 'true',
54       'hasstatus'   => 'true',
55       'hasrestart'  => 'true',
56     )
57   }
58   it {
59     should contain_file('org.apache.karaf.features.cfg').with(
60       'ensure'      => 'file',
61       'path'        => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
62       'owner'   => 'odl',
63       'group'   => 'odl',
64     )
65   }
66
67   it {
68     if odl_bind_ip =~ /.*:.*/
69         java_options = '-Djava.net.preferIPv6Addresses=true'
70     else
71         java_options = '-Djava.net.preferIPv4Stack=true'
72     end
73
74     should contain_file_line('Karaf Java Options').with(
75       'ensure' => 'present',
76       'path'   => '/opt/opendaylight/bin/karaf',
77       'line'   => "EXTRA_JAVA_OPTS=\"#{java_options}\"",
78       'match'  => '^EXTRA_JAVA_OPTS=.*$',
79       'after'  => '^PROGNAME=.*$'
80     )
81   }
82
83   it {
84     should contain_file('org.opendaylight.ovsdb.library.cfg').with(
85       'ensure'  => 'file',
86       'path'    => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
87       'owner'   => 'odl',
88       'group'   => 'odl',
89       'content' =>  /ovsdb-listener-ip = #{odl_bind_ip}/
90     )
91   }
92
93   it {
94     should contain_file('default-openflow-connection-config.xml').with(
95       'ensure'  => 'file',
96       'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml',
97       'owner'   => 'odl',
98       'group'   => 'odl',
99       'content' =>  /<address>#{odl_bind_ip}<\/address>/
100     )
101   }
102
103   unless inactivity_probe == :undef
104     it {
105       should contain_file('Configure inactivity probe timer').with(
106         'ensure'  => 'file',
107         'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml',
108         'owner'   => 'odl',
109         'group'   => 'odl',
110         'content' =>  /<controller-inactivity-probe>#{inactivity_probe}<\/controller-inactivity-probe>/
111       )
112     }
113   end
114
115 end
116
117 # Shared tests that specialize in testing log file size and rollover
118 def log_settings(options = {})
119   # Extraxt params. The dafault value should be same as in opendaylight::params
120   log_max_size = options.fetch(:log_max_size, '10GB')
121   log_max_rollover = options.fetch(:log_max_rollover, 2)
122   log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
123   log_mechanism = options.fetch(:log_mechanism, 'file')
124
125   if log_mechanism == 'console'
126     it {
127       should contain_file_line('consoleappender').with(
128         'path'  => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
129         'line'  => 'karaf.log.console=INFO',
130         'after' => 'log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter',
131         'match' => '^karaf.log.console.*$'
132       )
133     }
134     it {
135       should contain_file_line('direct').with(
136         'path'  => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
137         'line'  => 'log4j2.appender.console.direct = true',
138         'after' => 'karaf.log.console=INFO',
139         'match' => '^log4j2.appender.console.direct.*$'
140       )
141     }
142   else
143
144     it {
145       should contain_file_line('logmaxsize').with(
146         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
147         'line'   => "log4j2.appender.rolling.policies.size.size = #{log_max_size}",
148         'match'  => '^log4j2.appender.rolling.policies.size.size.*$',
149       )
150     }
151     it {
152       should contain_file_line('rolloverstrategy').with(
153         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
154         'line'   => 'log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy'
155       )
156     }
157     it {
158       should contain_file_line('logmaxrollover').with(
159         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
160         'line'   => "log4j2.appender.rolling.strategy.max = #{log_max_rollover}",
161         'match'  => '^log4j2.appender.rolling.strategy.max.*$',
162       )
163     }
164     it {
165       should contain_file_line('logrolloverfileindex').with(
166         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
167         'line'   => "log4j2.appender.rolling.strategy.fileIndex = #{log_rollover_fileindex}",
168         'match'  => '^log4j2.appender.rolling.strategy.fileIndex.*$',
169       )
170     }
171   end
172 end
173
174 # Shared tests that specialize in testing Karaf feature installs
175 def karaf_feature_tests(options = {})
176   # Extract params
177   # NB: This default list should be the same as the one in opendaylight::params
178   # TODO: Remove this possible source of bugs^^
179   default_features = options.fetch(:default_features, ['standard', 'wrap', 'ssh'])
180   extra_features = options.fetch(:extra_features, [])
181
182   # The order of this list concat matters
183   features = default_features + extra_features
184   features_csv = features.join(',')
185
186   # Confirm properties of Karaf features config file
187   # NB: These hashes don't work with Ruby 1.8.7, but we
188   #   don't support 1.8.7 so that's okay. See issue #36.
189   it {
190     should contain_file('org.apache.karaf.features.cfg').with(
191       'ensure'      => 'file',
192       'path'        => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
193       'owner'   => 'odl',
194       'group'   => 'odl',
195     )
196   }
197   it {
198     should contain_file_line('featuresBoot').with(
199       'path'  => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
200       'line'  => "featuresBoot=#{features_csv}",
201       'match' => '^featuresBoot=.*$',
202     )
203   }
204 end
205
206 # Shared tests that specialize in testing ODL's REST port config
207 def odl_rest_port_tests(options = {})
208   # Extract params
209   # NB: This default value should be the same as one in opendaylight::params
210   # TODO: Remove this possible source of bugs^^
211   odl_rest_port = options.fetch(:odl_rest_port, 8181)
212   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
213   # Confirm properties of ODL REST port config file
214   # NB: These hashes don't work with Ruby 1.8.7, but we
215   #   don't support 1.8.7 so that's okay. See issue #36.
216   it {
217     should contain_augeas('ODL REST Port')
218   }
219
220   if not odl_bind_ip.eql? '0.0.0.0'
221     it {
222       should contain_augeas('ODL REST IP')
223       should contain_file_line('set pax bind IP').with(
224         'ensure'  => 'present',
225         'path'    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
226         'line'    => "org.ops4j.pax.web.listening.addresses = #{odl_bind_ip}",
227         'require' => 'File[org.ops4j.pax.web.cfg]'
228       )
229       should contain_file_line('set karaf IP').with(
230         'ensure' => 'present',
231         'path'   => '/opt/opendaylight/etc/org.apache.karaf.shell.cfg',
232         'line'   => "sshHost = #{odl_bind_ip}",
233         'match'  => '^sshHost\s*=.*$',
234       )
235     }
236   else
237     it {
238       should_not contain_augeas('ODL REST IP')
239     }
240   end
241
242   it {
243     should contain_file_line('set pax bind port').with(
244         'ensure'  => 'present',
245         'path'    => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
246         'line'    => "org.osgi.service.http.port = #{odl_rest_port}",
247         'match'   => '^#?org.osgi.service.http.port\s.*$',
248         'require' => 'File[org.ops4j.pax.web.cfg]'
249     )
250   }
251 end
252
253 def log_level_tests(options = {})
254   # Extract params
255   # NB: This default value should be the same as one in opendaylight::params
256   # TODO: Remove this possible source of bugs^^
257   log_levels = options.fetch(:log_levels, {})
258
259   if log_levels.empty?
260     # Should contain log level config file
261     it {
262       should_not contain_file_line('logger-org.opendaylight.ovsdb-level')
263     }
264     it {
265       should_not contain_file_line('logger-org.opendaylight.ovsdb-name')
266     }
267   else
268     # Verify each custom log level config entry
269     log_levels.each_pair do |logger, level|
270       underscored_version = "#{logger}".gsub('.', '_')
271       it {
272         should contain_file_line("logger-#{logger}-level").with(
273           'ensure' => 'present',
274           'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
275           'line' => "log4j2.logger.#{underscored_version}.level = #{level}",
276           'match'  => "log4j2.logger.#{underscored_version}.level = .*$"
277         )
278         should contain_file_line("logger-#{logger}-name").with(
279           'ensure' => 'present',
280           'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
281           'line' => "log4j2.logger.#{underscored_version}.name = #{logger}",
282           'match'  => "log4j2.logger.#{underscored_version}.name = .*$"
283         )
284       }
285     end
286   end
287 end
288
289 def enable_ha_tests(options = {})
290   # Extract params
291   enable_ha = options.fetch(:enable_ha, false)
292   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
293   ha_node_ips = options.fetch(:ha_node_ips, [])
294   ha_db_modules = options.fetch(:ha_db_modules, { 'default' => false })
295   # HA_NODE_IPS size
296   ha_node_count = ha_node_ips.size
297
298   if (enable_ha) && (ha_node_count < 2)
299     # Check for HA_NODE_COUNT < 2
300     fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
301   end
302
303   if enable_ha
304     ha_node_index = ha_node_ips.index(odl_bind_ip)
305     it {
306       should contain_file('akka.conf').with(
307         'path'    => '/opt/opendaylight/configuration/initial/akka.conf',
308         'ensure'  => 'file',
309         'owner'   => 'odl',
310         'group'   => 'odl',
311         'content' => /roles\s*=\s*\["member-#{ha_node_index}"\]/
312       )
313     }
314
315     ha_db_modules.each do |mod, urn|
316       it { should contain_file('module-shards.conf').with(
317         'path'    => '/opt/opendaylight/configuration/initial/module-shards.conf',
318         'ensure'  => 'file',
319         'owner'   => 'odl',
320         'group'   => 'odl',
321         'content' => /name = "#{mod}"/
322       )}
323       if mod == 'default'
324         it { should contain_file('modules.conf').with(
325           'path'    => '/opt/opendaylight/configuration/initial/modules.conf',
326           'ensure'  => 'file',
327           'owner'   => 'odl',
328           'group'   => 'odl'
329         )}
330       else
331         it { should contain_file('modules.conf').with(
332           'path'    => '/opt/opendaylight/configuration/initial/modules.conf',
333           'ensure'  => 'file',
334           'owner'   => 'odl',
335           'group'   => 'odl',
336           'content' => /name = "#{mod}"/,
337         )}
338       end
339     end
340   else
341     it {
342       should_not contain_file('akka.conf')
343       should_not contain_file('module-shards.conf')
344       should_not contain_file('modules.conf')
345       }
346   end
347 end
348
349 def rpm_install_tests(options = {})
350   # Extract params
351   rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-fluorine-epel-7-$basearch-devel')
352
353
354   # Default to CentOS 7 Yum repo URL
355
356   # Confirm presence of RPM-related resources
357   it { should contain_yumrepo('opendaylight') }
358   it { should contain_package('opendaylight') }
359
360   # Confirm relationships between RPM-related resources
361   it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') }
362   it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') }
363
364   # Confirm properties of RPM-related resources
365   # NB: These hashes don't work with Ruby 1.8.7, but we
366   #   don't support 1.8.7 so that's okay. See issue #36.
367   it {
368     should contain_yumrepo('opendaylight').with(
369       'enabled'     => '1',
370       'gpgcheck'    => '0',
371       'descr'       => 'OpenDaylight SDN Controller',
372       'baseurl'     => "#{rpm_repo}",
373     )
374   }
375   it {
376     should contain_package('opendaylight').with(
377       'ensure'   => 'present',
378     )
379   }
380 end
381
382 def deb_install_tests(options = {})
383   # Extract params
384   deb_repo = options.fetch(:deb_repo, 'ppa:odl-team/nitrogen')
385
386   # Confirm the presence of Deb-related resources
387   it { should contain_apt__ppa(deb_repo) }
388   it { should contain_package('opendaylight') }
389
390   # Confirm relationships between Deb-related resources
391   it { should contain_package('opendaylight').that_requires("Apt::Ppa[#{deb_repo}]") }
392   it { should contain_apt__ppa(deb_repo).that_comes_before('Package[opendaylight]') }
393
394   # Confirm presence of Deb-related resources
395   it {
396     should contain_package('opendaylight').with(
397       'ensure'   => 'present',
398     )
399   }
400 end
401
402 # Shared tests for unsupported OSs
403 def unsupported_os_tests(options = {})
404   # Extract params
405   expected_msg = options.fetch(:expected_msg)
406   rpm_repo = options.fetch(:rpm_repo, 'https://nexus.opendaylight.org/content/repositories/opendaylight-fluorine-epel-7-$basearch-devel')
407
408   # Confirm that classes fail on unsupported OSs
409   it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
410   it { expect { should contain_class('opendaylight::install') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
411   it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
412   it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
413
414   # Confirm that other resources fail on unsupported OSs
415   it { expect { should contain_yumrepo('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
416   it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
417   it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
418   it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
419 end
420
421 # Shared tests that specialize in testing SNAT mechanism
422 def snat_mechanism_tests(snat_mechanism='controller')
423   it { should contain_file('/opt/opendaylight/etc/opendaylight') }
424   it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore')}
425   it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial')}
426   it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial/config')}
427
428   # Confirm snat_mechanism
429   it {
430     should contain_file('netvirt-natservice-config.xml').with(
431       'ensure'      => 'file',
432       'path'        => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
433       'owner'   => 'odl',
434       'group'   => 'odl',
435       'content'     =>  /<nat-mode>#{snat_mechanism}<\/nat-mode>/
436       )
437     }
438 end
439
440 # Shared tests that specialize in testing SFC Config
441 def sfc_tests(options = {})
442   extra_features = options.fetch(:extra_features, [])
443
444   if extra_features.include? 'odl-netvirt-sfc'
445     sfc_enabled = true
446   else
447     sfc_enabled = false
448   end
449
450   it { should contain_file('/opt/opendaylight/etc/opendaylight') }
451   it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore')}
452   it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial')}
453   it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial/config')}
454
455   it {
456     should contain_file('genius-itm-config.xml').with(
457       'ensure'  => 'file',
458       'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
459       'owner'   => 'odl',
460       'group'   => 'odl',
461       'content' => /<gpe-extension-enabled>#{sfc_enabled}<\/gpe-extension-enabled>/
462       )
463     }
464 end
465
466 # Shared tests that specialize in testing DSCP marking config
467 def dscp_tests(options = {})
468   inherit_dscp_marking = options.fetch(:inherit_dscp_marking, false)
469
470   if inherit_dscp_marking
471     it {
472       should contain_file('genius-itm-config.xml').with(
473         'ensure'  => 'file',
474         'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
475         'owner'   => 'odl',
476         'group'   => 'odl',
477         'content' => /<default-tunnel-tos>inherit<\/default-tunnel-tos>/
478       )
479     }
480   else
481     it {
482       should contain_file('genius-itm-config.xml').with(
483         'ensure'  => 'file',
484         'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/genius-itm-config.xml',
485         'owner'   => 'odl',
486         'group'   => 'odl',
487         'content' => /<default-tunnel-tos>0<\/default-tunnel-tos>/
488       )
489     }
490   end
491 end
492
493 # Shared tests that specialize in testing VPP routing node config
494 def vpp_routing_node_tests(options = {})
495   # Extract params
496   # NB: This default list should be the same as the one in opendaylight::params
497   # TODO: Remove this possible source of bugs^^
498   routing_node = options.fetch(:routing_node, '')
499
500   if routing_node.empty?
501     it { should_not contain_file('org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg') }
502     it { should_not contain_file_line('routing-node') }
503   else
504     # Confirm properties of Karaf config file
505     # NB: These hashes don't work with Ruby 1.8.7, but we
506     #   don't support 1.8.7 so that's okay. See issue #36.
507     it {
508       should contain_file('org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg').with(
509         'ensure'      => 'file',
510         'path'        => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
511         'owner'   => 'odl',
512         'group'   => 'odl',
513       )
514     }
515     it {
516       should contain_file_line('routing-node').with(
517         'path'  => '/opt/opendaylight/etc/org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg',
518         'line'  => "routing-node=#{routing_node}",
519         'match' => '^routing-node=.*$',
520       )
521     }
522   end
523 end
524
525 # ODL username/password tests
526 def username_password_tests(username, password)
527
528   it {
529     should contain_odl_user(username).with(
530       :password => password
531     )
532   }
533 end
534
535 # ODL websocket address tests
536 def odl_websocket_address_tests(options = {})
537   # Extract params
538   # NB: This default value should be the same as one in opendaylight::params
539   # TODO: Remove this possible source of bugs^^
540   odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
541   # Confirm properties of ODL REST port config file
542   # NB: These hashes don't work with Ruby 1.8.7, but we
543   #   don't support 1.8.7 so that's okay. See issue #36.
544
545   if not odl_bind_ip.eql? '0.0.0.0'
546     it {
547       should contain_file('/opt/opendaylight/etc/org.opendaylight.restconf.cfg').with(
548         'ensure'      => 'file',
549         'path'        => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
550         'owner'   => 'odl',
551         'group'   => 'odl',
552       )
553     }
554     it {
555         should contain_file_line('websocket-address').with(
556           'path'    => '/opt/opendaylight/etc/org.opendaylight.restconf.cfg',
557           'line'    => "websocket-address=#{odl_bind_ip}",
558           'match'   => '^websocket-address=.*$',
559       )
560     }
561   else
562     it {
563       should_not contain_file_line('websocket-address')
564     }
565   end
566 end
567
568 def odl_tls_tests(options = {})
569   enable_tls = options.fetch(:enable_tls, false)
570   tls_keystore_password = options.fetch(:tls_keystore_password, nil)
571   tls_trusted_certs = options.fetch(:tls_trusted_certs, [])
572   tls_keystore_password = options.fetch(:tls_keystore_password, nil)
573   tls_key_file = options.fetch(:tls_key_file, nil)
574   tls_cert_file = options.fetch(:tls_cert_file, nil)
575   tls_ca_cert_file = options.fetch(:tls_ca_cert_file, nil)
576   odl_rest_port = options.fetch(:odl_rest_port, 8181)
577
578   if enable_tls
579     if tls_keystore_password.nil?
580       it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::PreformattedError) }
581       return
582     end
583
584     if tls_key_file or tls_cert_file
585       if tls_key_file and tls_cert_file
586         it {
587           should contain_odl_keystore('controller')
588         }
589       else
590         it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::PreformattedError) }
591       end
592     end
593     it {
594       should contain_augeas('Remove HTTP ODL REST Port')
595       should contain_augeas('ODL SSL REST Port')
596       should contain_file_line('set pax TLS port').with(
597         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
598         'line'   => "org.osgi.service.http.port.secure = #{odl_rest_port}",
599         'match'  => '^#?org.osgi.service.http.port.secure.*$',
600       )
601       should contain_file_line('set pax TLS keystore location').with(
602         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
603         'line'   => 'org.ops4j.pax.web.ssl.keystore = configuration/ssl/ctl.jks',
604         'match'  => '^#?org.ops4j.pax.web.ssl.keystore.*$',
605       )
606       should contain_file_line('set pax TLS keystore integrity password').with(
607         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
608         'line'   => "org.ops4j.pax.web.ssl.password = #{tls_keystore_password}",
609         'match'  => '^#?org.ops4j.pax.web.ssl.password.*$',
610       )
611       should contain_file_line('set pax TLS keystore password').with(
612         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
613         'line'   => "org.ops4j.pax.web.ssl.keypassword = #{tls_keystore_password}",
614         'match'  => '^#?org.ops4j.pax.web.ssl.keypassword.*$',
615       )
616       should contain_file('aaa-cert-config.xml').with(
617         'ensure'  => 'file',
618         'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/aaa-cert-config.xml',
619         'owner'   => 'odl',
620         'group'   => 'odl',
621       )
622       should contain_file('org.opendaylight.ovsdb.library.cfg').with(
623         'ensure'  => 'file',
624         'path'    => '/opt/opendaylight/etc/org.opendaylight.ovsdb.library.cfg',
625         'owner'   => 'odl',
626         'group'   => 'odl',
627         'content' =>  /use-ssl = true/
628       )
629       should contain_file('/opt/opendaylight/configuration/ssl').with(
630         'ensure' => 'directory',
631         'path'   => '/opt/opendaylight/configuration/ssl',
632         'owner'  => 'odl',
633         'group'  => 'odl',
634         'mode'   => '0755'
635       )
636       should contain_file_line('enable pax TLS').with(
637         'ensure' => 'present',
638         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
639         'line'   => 'org.osgi.service.http.secure.enabled = true',
640         'match'  => '^#?org.osgi.service.http.secure.enabled.*$',
641       )
642       should contain_file_line('disable pax HTTP').with(
643         'ensure' => 'present',
644         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
645         'line'   => 'org.osgi.service.http.enabled = false',
646         'match'  => '^#?org.osgi.service.http.enabled.*$',
647       )
648       should contain_file('org.ops4j.pax.web.cfg').with(
649         'ensure' => 'file',
650         'path'   => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg',
651         'owner'  => 'odl',
652         'group'  => 'odl',
653       )
654       should contain_file('default-openflow-connection-config.xml').with(
655         'ensure'  => 'file',
656         'path'    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/default-openflow-connection-config.xml',
657         'owner'   => 'odl',
658         'group'   => 'odl',
659         'content' =>  /<transport-protocol>TLS<\/transport-protocol>/
660       )
661     }
662   end
663 end
664
665 def stats_polling_enablement_tests(options = {})
666   # Extract params
667   # NB: This default value should be the same as one in opendaylight::params
668   # TODO: Remove this possible source of bugs^^
669   stats_polling_enabled = options.fetch(:stats_polling_enabled, false)
670   # Confirm properties of ODL REST port config file
671   # NB: These hashes don't work with Ruby 1.8.7, but we
672   #   don't support 1.8.7 so that's okay. See issue #36.
673   it {
674     should contain_file('openflowplugin.cfg').with(
675       'ensure' => 'file',
676       'path'   => '/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg',
677       'owner'  => 'odl',
678       'group'  => 'odl',
679     )
680     should contain_file_line('stats-polling').with(
681       'ensure' => 'present',
682       'path'   => '/opt/opendaylight/etc/org.opendaylight.openflowplugin.cfg',
683       'line'   => "is-statistics-polling-on=#{stats_polling_enabled}",
684       'match'  => '^is-statistics-polling-on=.*$',
685     )
686   }
687 end