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 # Install params are passed via environment var, set in Rakefile
50 # Changing the installed version of ODL via `puppet apply` is not supported
51 # by puppet-odl, so it's not possible to vary these params in the same
52 # Beaker test run. Do a different run passing different env vars.
53 install_method = ENV['INSTALL_METHOD']
54 rpm_repo = ENV['RPM_REPO']
56 # NB: These param defaults should match the ones used by the opendaylight
57 # class, which are defined in opendaylight::params
58 # TODO: Remove this possible source of bugs^^
59 # Extract params if given, defaulting to odl class defaults if not
60 extra_features = options.fetch(:extra_features, [])
61 default_features = options.fetch(:default_features,
62 ['config', 'standard', 'region', 'package', 'kar', 'ssh', 'management'])
63 odl_rest_port = options.fetch(:odl_rest_port, 8080)
64 log_levels = options.fetch(:log_levels, {})
65 enable_ha = options.fetch(:enable_ha, false)
66 ha_node_ips = options.fetch(:ha_node_ips, [])
67 ha_node_index = options.fetch(:ha_node_index, 0)
69 # Build script for consumption by Puppet apply
70 it 'should work idempotently with no errors' do
72 class { 'opendaylight':
73 install_method => #{install_method},
74 rpm_repo => #{rpm_repo},
75 default_features => #{default_features},
76 extra_features => #{extra_features},
77 odl_rest_port=> #{odl_rest_port},
78 enable_ha=> #{enable_ha},
79 ha_node_ips=> #{ha_node_ips},
80 ha_node_index=> #{ha_node_index},
81 log_levels=> #{log_levels},
85 # Apply our Puppet manifest on the Beaker host
86 apply_manifest(pp, :catch_failures => true)
88 # Not checking for idempotence because of false failures
89 # related to package manager cache updates outputting to
90 # stdout and different IDs for the puppet manifest apply.
91 # I think this is a limitation in how Beaker can check
92 # for changes, not a problem with the Puppet module.
96 # Shared function that handles generic validations
97 # These should be common for all odl class param combos
98 def generic_validations()
99 # Verify ODL's directory
100 describe file('/opt/opendaylight/') do
101 it { should be_directory }
102 it { should be_owned_by 'odl' }
103 it { should be_grouped_into 'odl' }
106 # Verify ODL's systemd service
107 describe service('opendaylight') do
108 it { should be_enabled }
109 it { should be_enabled.with_level(3) }
110 it { should be_running }
113 # Creation handled by RPM, or Puppet during tarball installs
114 describe user('odl') do
116 it { should belong_to_group 'odl' }
117 # NB: This really shouldn't have a slash at the end!
118 # The home dir set by the RPM is `/opt/opendaylight`.
119 # Since we use the trailing slash elsewhere else, this
120 # may look like a style issue. It isn't! It will make
121 # Beaker tests fail if it ends with a `/`. A future
122 # version of the ODL RPM may change this.
123 it { should have_home_directory '/opt/opendaylight' }
126 # Creation handled by RPM, or Puppet during tarball installs
127 describe group('odl') do
131 # This should not be the odl user's home dir
132 describe file('/home/odl') do
133 # Home dir shouldn't be created for odl user
134 it { should_not be_directory }
137 # OpenDaylight will appear as a Java process
138 describe process('java') do
139 it { should be_running }
142 # Should contain Karaf features config file
143 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
144 it { should be_file }
145 it { should be_owned_by 'odl' }
146 it { should be_grouped_into 'odl' }
149 # Should contain ODL NB port config file
150 describe file('/opt/opendaylight/etc/jetty.xml') do
151 it { should be_file }
152 it { should be_owned_by 'odl' }
153 it { should be_grouped_into 'odl' }
156 # Should contain log level config file
157 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
158 it { should be_file }
159 it { should be_owned_by 'odl' }
160 it { should be_grouped_into 'odl' }
163 if ['centos-7', 'centos-7-docker', 'fedora-22', 'fedora-23', 'fedora-23-docker'].include? ENV['RS_SET']
164 # Validations for modern Red Hat family OSs
166 # Verify ODL systemd .service file
167 describe file('/usr/lib/systemd/system/opendaylight.service') do
168 it { should be_file }
169 it { should be_owned_by 'root' }
170 it { should be_grouped_into 'root' }
171 it { should be_mode '644' }
174 # Java 8 should be installed
175 describe package('java-1.8.0-openjdk') do
176 it { should be_installed }
178 elsif ['ubuntu-1404', 'ubuntu-1404-docker'].include? ENV['RS_SET']
179 # Ubuntu-specific validations
181 # Verify ODL Upstart config file
182 describe file('/etc/init/opendaylight.conf') do
183 it { should be_file }
184 it { should be_owned_by 'root' }
185 it { should be_grouped_into 'root' }
186 it { should be_mode '644' }
189 # Java 7 should be installed
190 describe package('openjdk-7-jdk') do
191 it { should be_installed }
194 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
198 # Shared function for validations related to the Karaf config file
199 def karaf_config_validations(options = {})
200 # NB: These param defaults should match the ones used by the opendaylight
201 # class, which are defined in opendaylight::params
202 # TODO: Remove this possible source of bugs^^
203 extra_features = options.fetch(:extra_features, [])
204 default_features = options.fetch(:default_features, ['config', 'standard', 'region',
205 'package', 'kar', 'ssh', 'management'])
207 # Create one list of all of the features
208 features = default_features + extra_features
210 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
211 it { should be_file }
212 it { should be_owned_by 'odl' }
213 it { should be_grouped_into 'odl' }
214 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
218 # Shared function for validations related to the ODL REST port config file
219 def port_config_validations(options = {})
220 # NB: This param default should match the one used by the opendaylight
221 # class, which is defined in opendaylight::params
222 # TODO: Remove this possible source of bugs^^
223 odl_rest_port = options.fetch(:odl_rest_port, 8080)
225 describe file('/opt/opendaylight/etc/jetty.xml') do
226 it { should be_file }
227 it { should be_owned_by 'odl' }
228 it { should be_grouped_into 'odl' }
229 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
233 # Shared function for validations related to custom logging verbosity
234 def log_level_validations(options = {})
235 # NB: This param default should match the one used by the opendaylight
236 # class, which is defined in opendaylight::params
237 # TODO: Remove this possible source of bugs^^
238 log_levels = options.fetch(:log_levels, {})
241 # Should contain log level config file
242 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
243 it { should be_file }
244 it { should be_owned_by 'odl' }
245 it { should be_grouped_into 'odl' }
247 # Should not contain custom log level config
248 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
249 it { should be_file }
250 it { should be_owned_by 'odl' }
251 it { should be_grouped_into 'odl' }
252 its(:content) { should_not match /# Log level config added by puppet-opendaylight/ }
255 # Should contain log level config file
256 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
257 it { should be_file }
258 it { should be_owned_by 'odl' }
259 it { should be_grouped_into 'odl' }
261 # Should not contain custom log level config
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 /# Log level config added by puppet-opendaylight/ }
268 # Verify each custom log level config entry
269 log_levels.each_pair do |logger, level|
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 /^log4j.logger.#{logger} = #{level}/ }
280 # Shared function for validations related to ODL OVSDB HA config
281 def enable_ha_validations(options = {})
282 # NB: This param default should match the one used by the opendaylight
283 # class, which is defined in opendaylight::params
284 # TODO: Remove this possible source of bugs^^
285 enable_ha = options.fetch(:enable_ha, false)
286 ha_node_ips = options.fetch(:ha_node_ips, [])
287 ha_node_index = options.fetch(:ha_node_index, 0)
289 ha_node_count = ha_node_ips.size
292 # Confirm ODL OVSDB HA is enabled
294 # Check for HA_NODE_COUNT >= 2
295 describe file('/opt/opendaylight/deploy/jolokia.xml') do
296 it { should be_file }
297 it { should be_owned_by 'odl' }
298 it { should be_grouped_into 'odl' }
301 # Check for HA_NODE_COUNT < 2
302 fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
307 # Shared function that handles validations specific to RPM-type installs
308 def rpm_validations()
309 rpm_repo = ENV['RPM_REPO']
311 describe yumrepo(rpm_repo) do
313 it { should be_enabled }
316 describe package('opendaylight') do
317 it { should be_installed }
321 # Shared function that handles validations specific to tarball-type installs
322 def tarball_validations()
323 rpm_repo = ENV['RPM_REPO']
325 describe package('opendaylight') do
326 it { should_not be_installed }
329 # Repo checks break (not fail) when yum doesn't make sense (Ubuntu)
330 if ['centos-7', 'fedora-22', 'fedora-23', 'fedora-23-docker'].include? ENV['RS_SET']
331 describe yumrepo(rpm_repo) do
332 it { should_not exist }
333 it { should_not be_enabled }