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'
16 RSpec.configure do |c|
18 proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
20 # Readable test descriptions
21 c.formatter = :documentation
23 # Configure all nodes in nodeset
25 # Install opendaylight module on any/all Beaker hosts
26 # TODO: Should this be done in host.each loop?
27 puppet_module_install(:source => proj_root, :module_name => 'opendaylight')
29 # Install stdlib, a dependency of the odl mod
30 on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0] }
31 # Install archive, a dependency of the odl mod use for tarball-type installs
32 on host, puppet('module', 'install', 'camptocamp-archive'), { :acceptable_exit_codes => [0] }
33 # Install Java Puppet mod, a dependency of the tarball install method
34 on host, puppet('module', 'install', 'puppetlabs-java'), { :acceptable_exit_codes => [0] }
40 # NB: These are a library of helper fns used by the Beaker tests
43 # NB: There are a large number of helper functions used in these tests.
44 # They make this code much more friendly, but may need to be referenced.
45 # The serverspec helpers (`should`, `be_running`...) are documented here:
46 # http://serverspec.org/resource_types.html
48 def install_odl(options = {})
49 # NB: These param defaults should match the ones used by the opendaylight
50 # class, which are defined in opendaylight::params
51 # TODO: Remove this possible source of bugs^^
52 # Extract params if given, defaulting to odl class defaults if not
53 # Default install method is passed via environment var, set in Rakefile
54 install_method = options.fetch(:install_method, ENV['INSTALL_METHOD'])
55 extra_features = options.fetch(:extra_features, [])
56 default_features = options.fetch(:default_features,
57 ['config', 'standard', 'region', 'package', 'kar', 'ssh', 'management'])
58 odl_rest_port = options.fetch(:odl_rest_port, 8080)
59 log_levels = options.fetch(:log_levels, {})
60 enable_l3 = options.fetch(:enable_l3, 'no')
62 # Build script for consumption by Puppet apply
63 it 'should work idempotently with no errors' do
65 class { 'opendaylight':
66 install_method => #{install_method},
67 default_features => #{default_features},
68 extra_features => #{extra_features},
69 odl_rest_port=> #{odl_rest_port},
70 enable_l3=> #{enable_l3},
71 log_levels=> #{log_levels},
75 # Apply our Puppet manifest on the Beaker host
76 apply_manifest(pp, :catch_failures => true)
78 # Not checking for idempotence because of false failures
79 # related to package manager cache updates outputting to
80 # stdout and different IDs for the puppet manifest apply.
81 # I think this is a limitation in how Beaker can check
82 # for changes, not a problem with the Puppet module.
86 # Shared function that handles generic validations
87 # These should be common for all odl class param combos
88 def generic_validations()
89 # Verify ODL's directory
90 describe file('/opt/opendaylight/') do
91 it { should be_directory }
92 it { should be_owned_by 'odl' }
93 it { should be_grouped_into 'odl' }
96 # Verify ODL's systemd service
97 describe service('opendaylight') do
98 it { should be_enabled }
99 it { should be_enabled.with_level(3) }
100 it { should be_running }
103 # Creation handled by RPM, or Puppet during tarball installs
104 describe user('odl') do
106 it { should belong_to_group 'odl' }
107 # NB: This really shouldn't have a slash at the end!
108 # The home dir set by the RPM is `/opt/opendaylight`.
109 # Since we use the trailing slash elsewhere else, this
110 # may look like a style issue. It isn't! It will make
111 # Beaker tests fail if it ends with a `/`. A future
112 # version of the ODL RPM may change this.
113 it { should have_home_directory '/opt/opendaylight' }
116 # Creation handled by RPM, or Puppet during tarball installs
117 describe group('odl') do
121 # This should not be the odl user's home dir
122 describe file('/home/odl') do
123 # Home dir shouldn't be created for odl user
124 it { should_not be_directory }
127 # OpenDaylight will appear as a Java process
128 describe process('java') do
129 it { should be_running }
132 # Should contain Karaf features config file
133 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
134 it { should be_file }
135 it { should be_owned_by 'odl' }
136 it { should be_grouped_into 'odl' }
139 # Should contain ODL NB port config file
140 describe file('/opt/opendaylight/etc/jetty.xml') do
141 it { should be_file }
142 it { should be_owned_by 'odl' }
143 it { should be_grouped_into 'odl' }
146 # Should contain log level config file
147 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
148 it { should be_file }
149 it { should be_owned_by 'odl' }
150 it { should be_grouped_into 'odl' }
153 # Should contain ODL OVSDB L3 enable/disable config file
154 describe file('/opt/opendaylight/etc/custom.properties') do
155 it { should be_file }
156 it { should be_owned_by 'odl' }
157 it { should be_grouped_into 'odl' }
160 if ['centos-7', 'centos-7-docker', 'fedora-22', 'fedora-23-docker'].include? ENV['RS_SET']
161 # Validations for modern Red Hat family OSs
163 # Verify ODL systemd .service file
164 describe file('/usr/lib/systemd/system/opendaylight.service') do
165 it { should be_file }
166 it { should be_owned_by 'root' }
167 it { should be_grouped_into 'root' }
168 it { should be_mode '644' }
171 # Java 8 should be installed
172 describe package('java-1.8.0-openjdk') do
173 it { should be_installed }
175 elsif ['ubuntu-1404', 'ubuntu-1404-docker'].include? ENV['RS_SET']
176 # Ubuntu-specific validations
178 # Verify ODL Upstart config file
179 describe file('/etc/init/opendaylight.conf') do
180 it { should be_file }
181 it { should be_owned_by 'root' }
182 it { should be_grouped_into 'root' }
183 it { should be_mode '644' }
186 # Java 7 should be installed
187 describe package('openjdk-7-jdk') do
188 it { should be_installed }
191 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
195 # Shared function for validations related to the Karaf config file
196 def karaf_config_validations(options = {})
197 # NB: These param defaults should match the ones used by the opendaylight
198 # class, which are defined in opendaylight::params
199 # TODO: Remove this possible source of bugs^^
200 extra_features = options.fetch(:extra_features, [])
201 default_features = options.fetch(:default_features, ['config', 'standard', 'region',
202 'package', 'kar', 'ssh', 'management'])
204 # Create one list of all of the features
205 features = default_features + extra_features
207 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
208 it { should be_file }
209 it { should be_owned_by 'odl' }
210 it { should be_grouped_into 'odl' }
211 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
215 # Shared function for validations related to the ODL REST port config file
216 def port_config_validations(options = {})
217 # NB: This param default should match the one used by the opendaylight
218 # class, which is defined in opendaylight::params
219 # TODO: Remove this possible source of bugs^^
220 odl_rest_port = options.fetch(:odl_rest_port, 8080)
222 describe file('/opt/opendaylight/etc/jetty.xml') do
223 it { should be_file }
224 it { should be_owned_by 'odl' }
225 it { should be_grouped_into 'odl' }
226 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
230 # Shared function for validations related to custom logging verbosity
231 def log_level_validations(options = {})
232 # NB: This param default should match the one used by the opendaylight
233 # class, which is defined in opendaylight::params
234 # TODO: Remove this possible source of bugs^^
235 log_levels = options.fetch(:log_levels, {})
238 # Should contain log level config file
239 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
240 it { should be_file }
241 it { should be_owned_by 'odl' }
242 it { should be_grouped_into 'odl' }
244 # Should not contain custom log level config
245 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
246 it { should be_file }
247 it { should be_owned_by 'odl' }
248 it { should be_grouped_into 'odl' }
249 its(:content) { should_not match /# Log level config added by puppet-opendaylight/ }
252 # Should contain log level config file
253 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
254 it { should be_file }
255 it { should be_owned_by 'odl' }
256 it { should be_grouped_into 'odl' }
258 # Should not contain custom log level config
259 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
260 it { should be_file }
261 it { should be_owned_by 'odl' }
262 it { should be_grouped_into 'odl' }
263 its(:content) { should match /# Log level config added by puppet-opendaylight/ }
265 # Verify each custom log level config entry
266 log_levels.each_pair do |logger, level|
267 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
268 it { should be_file }
269 it { should be_owned_by 'odl' }
270 it { should be_grouped_into 'odl' }
271 its(:content) { should match /^log4j.logger.#{logger} = #{level}/ }
277 # Shared function for validations related to ODL OVSDB L3 config
278 def enable_l3_validations(options = {})
279 # NB: This param default should match the one used by the opendaylight
280 # class, which is defined in opendaylight::params
281 # TODO: Remove this possible source of bugs^^
282 enable_l3 = options.fetch(:enable_l3, 'no')
284 if [true, 'yes'].include? enable_l3
285 # Confirm ODL OVSDB L3 is enabled
286 describe file('/opt/opendaylight/etc/custom.properties') do
287 it { should be_file }
288 it { should be_owned_by 'odl' }
289 it { should be_grouped_into 'odl' }
290 its(:content) { should match /^ovsdb.l3.fwd.enabled=yes/ }
292 elsif [false, 'no'].include? enable_l3
293 # Confirm ODL OVSDB L3 is disabled
294 describe file('/opt/opendaylight/etc/custom.properties') do
295 it { should be_file }
296 it { should be_owned_by 'odl' }
297 it { should be_grouped_into 'odl' }
298 its(:content) { should match /^ovsdb.l3.fwd.enabled=no/ }
303 # Shared function that handles validations specific to RPM-type installs
304 def rpm_validations()
305 describe yumrepo('opendaylight-41-release') do
307 it { should be_enabled }
310 describe package('opendaylight') do
311 it { should be_installed }
315 # Shared function that handles validations specific to tarball-type installs
316 def tarball_validations()
317 describe package('opendaylight') do
318 it { should_not be_installed }
321 # Repo checks break (not fail) when yum doesn't make sense (Ubuntu)
322 if ['centos-7', 'fedora-22', 'fedora-23-docker'].include? ENV['RS_SET']
323 describe yumrepo('opendaylight-41-release') do
324 it { should_not exist }
325 it { should_not be_enabled }