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'
10 elsif host.name == "ubuntu-16-docker" || host.name == "ubuntu-16"
11 install_puppet_agent_on(host, puppet_collection: "pc1")
18 RSpec.configure do |c|
20 proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
22 # Readable test descriptions
23 c.formatter = :documentation
25 # Configure all nodes in nodeset
27 # Install opendaylight module on any/all Beaker hosts
28 # TODO: Should this be done in host.each loop?
29 puppet_module_install(:source => proj_root, :module_name => 'opendaylight')
31 # Install stdlib, a dependency of the odl mod
32 on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0] }
33 # Install apt, a dependency of the deb install method
34 on host, puppet('module', 'install', 'puppetlabs-apt'), { :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 rpm_repo = ENV['RPM_REPO']
54 deb_repo = ENV['DEB_REPO']
62 # NB: These param defaults should match the ones used by the opendaylight
63 # class, which are defined in opendaylight::params
64 # TODO: Remove this possible source of bugs^^
65 # Extract params if given, defaulting to odl class defaults if not
66 extra_features = options.fetch(:extra_features, [])
67 default_features = options.fetch(:default_features,
68 ['config', 'standard', 'region', 'package', 'kar', 'ssh', 'management'])
69 odl_rest_port = options.fetch(:odl_rest_port, 8080)
70 log_levels = options.fetch(:log_levels, {})
71 enable_ha = options.fetch(:enable_ha, false)
72 ha_node_ips = options.fetch(:ha_node_ips, [])
73 ha_node_index = options.fetch(:ha_node_index, 0)
75 # Build script for consumption by Puppet apply
76 it 'should work idempotently with no errors' do
78 class { 'opendaylight':
79 rpm_repo => '#{rpm_repo}',
80 deb_repo => '#{deb_repo}',
81 default_features => #{default_features},
82 extra_features => #{extra_features},
83 odl_rest_port=> #{odl_rest_port},
84 enable_ha=> #{enable_ha},
85 ha_node_ips=> #{ha_node_ips},
86 ha_node_index=> #{ha_node_index},
87 log_levels=> #{log_levels},
91 # Apply our Puppet manifest on the Beaker host
92 apply_manifest(pp, :catch_failures => true)
94 # Not checking for idempotence because of false failures
95 # related to package manager cache updates outputting to
96 # stdout and different IDs for the puppet manifest apply.
97 # I think this is a limitation in how Beaker can check
98 # for changes, not a problem with the Puppet module.
102 # Shared function that handles generic validations
103 # These should be common for all odl class param combos
104 def generic_validations()
105 # Verify ODL's directory
106 describe file('/opt/opendaylight/') do
107 it { should be_directory }
108 it { should be_owned_by 'odl' }
109 it { should be_grouped_into 'odl' }
112 # Verify ODL's systemd service
113 describe service('opendaylight') do
114 it { should be_enabled }
115 it { should be_enabled.with_level(3) }
116 it { should be_running.under('systemd') }
119 # Creation handled by RPM or Deb
120 describe user('odl') do
122 it { should belong_to_group 'odl' }
123 # NB: This really shouldn't have a slash at the end!
124 # The home dir set by the RPM is `/opt/opendaylight`.
125 # Since we use the trailing slash elsewhere else, this
126 # may look like a style issue. It isn't! It will make
127 # Beaker tests fail if it ends with a `/`. A future
128 # version of the ODL RPM may change this.
129 it { should have_home_directory '/opt/opendaylight' }
132 # Creation handled by RPM or Deb
133 describe group('odl') do
137 # This should not be the odl user's home dir
138 describe file('/home/odl') do
139 # Home dir shouldn't be created for odl user
140 it { should_not be_directory }
143 # OpenDaylight will appear as a Java process
144 describe process('java') do
145 it { should be_running }
148 # Should contain Karaf features config file
149 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
150 it { should be_file }
151 it { should be_owned_by 'odl' }
152 it { should be_grouped_into 'odl' }
155 # Should contain ODL NB port config file
156 describe file('/opt/opendaylight/etc/jetty.xml') do
157 it { should be_file }
158 it { should be_owned_by 'odl' }
159 it { should be_grouped_into 'odl' }
162 # Should contain log level config file
163 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
164 it { should be_file }
165 it { should be_owned_by 'odl' }
166 it { should be_grouped_into 'odl' }
169 if ['centos-7', 'centos-7-docker'].include? ENV['RS_SET']
170 # Validations for modern Red Hat family OSs
172 # Verify ODL systemd .service file
173 describe file('/usr/lib/systemd/system/opendaylight.service') do
174 it { should be_file }
175 it { should be_owned_by 'root' }
176 it { should be_grouped_into 'root' }
177 it { should be_mode '644' }
180 # Java 8 should be installed
181 describe package('java-1.8.0-openjdk') do
182 it { should be_installed }
185 # Ubuntu 16.04 specific validation
186 elsif ['ubuntu-16', 'ubuntu-16-docker'].include? ENV['RS_SET']
188 # Verify ODL systemd .service file
189 describe file('/lib/systemd/system/opendaylight.service') do
190 it { should be_file }
191 it { should be_owned_by 'root' }
192 it { should be_grouped_into 'root' }
193 it { should be_mode '644' }
196 # Java 8 should be installed
197 describe package('openjdk-8-jre-headless') do
198 it { should be_installed }
202 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
206 # Shared function for validations related to the Karaf config file
207 def karaf_config_validations(options = {})
208 # NB: These param defaults should match the ones used by the opendaylight
209 # class, which are defined in opendaylight::params
210 # TODO: Remove this possible source of bugs^^
211 extra_features = options.fetch(:extra_features, [])
212 default_features = options.fetch(:default_features, ['config', 'standard', 'region',
213 'package', 'kar', 'ssh', 'management'])
215 # Create one list of all of the features
216 features = default_features + extra_features
218 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
219 it { should be_file }
220 it { should be_owned_by 'odl' }
221 it { should be_grouped_into 'odl' }
222 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
226 # Shared function for validations related to the ODL REST port config file
227 def port_config_validations(options = {})
228 # NB: This param default should match the one used by the opendaylight
229 # class, which is defined in opendaylight::params
230 # TODO: Remove this possible source of bugs^^
231 odl_rest_port = options.fetch(:odl_rest_port, 8080)
233 describe file('/opt/opendaylight/etc/jetty.xml') do
234 it { should be_file }
235 it { should be_owned_by 'odl' }
236 it { should be_grouped_into 'odl' }
237 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
241 # Shared function for validations related to custom logging verbosity
242 def log_level_validations(options = {})
243 # NB: This param default should match the one used by the opendaylight
244 # class, which is defined in opendaylight::params
245 # TODO: Remove this possible source of bugs^^
246 log_levels = options.fetch(:log_levels, {})
249 # Should contain log level config file
250 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
251 it { should be_file }
252 it { should be_owned_by 'odl' }
253 it { should be_grouped_into 'odl' }
255 # Should not contain custom log level config
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' }
260 its(:content) { should_not match /# Log level config added by puppet-opendaylight/ }
263 # Should contain log level config file
264 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
265 it { should be_file }
266 it { should be_owned_by 'odl' }
267 it { should be_grouped_into 'odl' }
269 # Should not contain custom log level config
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 /# Log level config added by puppet-opendaylight/ }
276 # Verify each custom log level config entry
277 log_levels.each_pair do |logger, level|
278 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
279 it { should be_file }
280 it { should be_owned_by 'odl' }
281 it { should be_grouped_into 'odl' }
282 its(:content) { should match /^log4j.logger.#{logger} = #{level}/ }
288 # Shared function for validations related to ODL OVSDB HA config
289 def enable_ha_validations(options = {})
290 # NB: This param default should match the one used by the opendaylight
291 # class, which is defined in opendaylight::params
292 # TODO: Remove this possible source of bugs^^
293 enable_ha = options.fetch(:enable_ha, false)
294 ha_node_ips = options.fetch(:ha_node_ips, [])
295 ha_node_index = options.fetch(:ha_node_index, 0)
297 ha_node_count = ha_node_ips.size
299 if (enable_ha) && (ha_node_count < 2)
300 # Check for HA_NODE_COUNT < 2
301 fail("Number of HA nodes less than 2: #{ha_node_count} and HA Enabled")
305 # Shared function that handles validations specific to RPM-type installs
306 def rpm_validations()
307 rpm_repo = ENV['RPM_REPO']
309 describe yumrepo(rpm_repo) do
311 it { should be_enabled }
314 describe package('opendaylight') do
315 it { should be_installed }
319 # Shared function that handles validations specific to Deb-type installs
320 def deb_validations()
321 deb_repo = ENV['DEB_REPO']
323 # Docs: http://serverspec.org/resource_types.html#ppa
324 describe ppa(deb_repo) do
326 it { should be_enabled }
329 describe package('opendaylight') do
330 it { should be_installed }