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