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 # The tarball extract isn't idempotent, can't do this check
79 # See: https://github.com/dfarrell07/puppet-opendaylight/issues/45#issuecomment-78135725
80 if install_method != 'tarball'
81 # Run it twice to test for idempotency
82 apply_manifest(pp, :catch_changes => true)
87 # Shared function that handles generic validations
88 # These should be common for all odl class param combos
89 def generic_validations()
90 # Verify ODL's directory
91 describe file('/opt/opendaylight/') do
92 it { should be_directory }
93 it { should be_owned_by 'odl' }
94 it { should be_grouped_into 'odl' }
97 # Verify ODL's systemd service
98 describe service('opendaylight') do
99 it { should be_enabled }
100 it { should be_enabled.with_level(3) }
101 it { should be_running }
104 # Creation handled by RPM, or Puppet during tarball installs
105 describe user('odl') do
107 it { should belong_to_group 'odl' }
108 # NB: This really shouldn't have a slash at the end!
109 # The home dir set by the RPM is `/opt/opendaylight`.
110 # Since we use the trailing slash elsewhere else, this
111 # may look like a style issue. It isn't! It will make
112 # Beaker tests fail if it ends with a `/`. A future
113 # version of the ODL RPM may change this.
114 it { should have_home_directory '/opt/opendaylight' }
117 # Creation handled by RPM, or Puppet during tarball installs
118 describe group('odl') do
122 # This should not be the odl user's home dir
123 describe file('/home/odl') do
124 # Home dir shouldn't be created for odl user
125 it { should_not be_directory }
128 # OpenDaylight will appear as a Java process
129 describe process('java') do
130 it { should be_running }
133 # Should contain log level config file
134 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
135 it { should be_file }
136 it { should be_owned_by 'odl' }
137 it { should be_grouped_into 'odl' }
140 if ['centos-7', 'centos-7-docker', 'fedora-22'].include? ENV['RS_SET']
141 # Validations for modern Red Hat family OSs
143 # Verify ODL systemd .service file
144 describe file('/usr/lib/systemd/system/opendaylight.service') do
145 it { should be_file }
146 it { should be_owned_by 'root' }
147 it { should be_grouped_into 'root' }
148 it { should be_mode '644' }
151 # Java 8 should be installed
152 describe package('java-1.8.0-openjdk') do
153 it { should be_installed }
155 elsif ['ubuntu-1404', 'ubuntu-1404-docker'].include? ENV['RS_SET']
156 # Ubuntu-specific validations
158 # Verify ODL Upstart config file
159 describe file('/etc/init/opendaylight.conf') do
160 it { should be_file }
161 it { should be_owned_by 'root' }
162 it { should be_grouped_into 'root' }
163 it { should be_mode '644' }
166 # Java 7 should be installed
167 describe package('openjdk-7-jdk') do
168 it { should be_installed }
171 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
175 # Shared function for validations related to the Karaf config file
176 def karaf_config_validations(options = {})
177 # NB: These param defaults should match the ones used by the opendaylight
178 # class, which are defined in opendaylight::params
179 # TODO: Remove this possible source of bugs^^
180 extra_features = options.fetch(:extra_features, [])
181 default_features = options.fetch(:default_features, ['config', 'standard', 'region',
182 'package', 'kar', 'ssh', 'management'])
184 # Create one list of all of the features
185 features = default_features + extra_features
187 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
188 it { should be_file }
189 it { should be_owned_by 'odl' }
190 it { should be_grouped_into 'odl' }
191 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
195 # Shared function for validations related to the ODL REST port config file
196 def port_config_validations(options = {})
197 # NB: This param default should match the one used by the opendaylight
198 # class, which is defined in opendaylight::params
199 # TODO: Remove this possible source of bugs^^
200 odl_rest_port = options.fetch(:odl_rest_port, 8080)
202 describe file('/opt/opendaylight/etc/jetty.xml') do
203 it { should be_file }
204 it { should be_owned_by 'odl' }
205 it { should be_grouped_into 'odl' }
206 its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
210 # Shared function for validations related to custom logging verbosity
211 def log_level_validations(options = {})
212 # NB: This param default should match the one used by the opendaylight
213 # class, which is defined in opendaylight::params
214 # TODO: Remove this possible source of bugs^^
215 log_levels = options.fetch(:log_levels, {})
218 # Should contain log level config file
219 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
220 it { should be_file }
221 it { should be_owned_by 'odl' }
222 it { should be_grouped_into 'odl' }
224 # Should not contain custom log level config
225 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
226 it { should be_file }
227 it { should be_owned_by 'odl' }
228 it { should be_grouped_into 'odl' }
229 its(:content) { should_not match /# Log level config added by puppet-opendaylight/ }
232 # Should contain log level config file
233 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
234 it { should be_file }
235 it { should be_owned_by 'odl' }
236 it { should be_grouped_into 'odl' }
238 # Should not contain custom log level config
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' }
243 its(:content) { should match /# Log level config added by puppet-opendaylight/ }
245 # Verify each custom log level config entry
246 log_levels.each_pair do |logger, level|
247 describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
248 it { should be_file }
249 it { should be_owned_by 'odl' }
250 it { should be_grouped_into 'odl' }
251 its(:content) { should match /log4j.logger.#{logger} = #{level}/ }
257 # Shared function for validations related to ODL OVSDB L3 config
258 def enable_l3_validations(options = {})
259 # NB: This param default should match the one used by the opendaylight
260 # class, which is defined in opendaylight::params
261 # TODO: Remove this possible source of bugs^^
262 enable_l3 = options.fetch(:enable_l3, 'no')
264 describe file('/opt/opendaylight/etc/custom.properties') do
265 it { should be_file }
266 it { should be_owned_by 'odl' }
267 it { should be_grouped_into 'odl' }
268 its(:content) { should match /ovsdb.l3.fwd.enabled=#{enable_l3}/ }
272 # Shared function that handles validations specific to RPM-type installs
273 def rpm_validations()
274 describe yumrepo('opendaylight-4-testing') do
276 it { should be_enabled }
279 describe package('opendaylight') do
280 it { should be_installed }
284 # Shared function that handles validations specific to tarball-type installs
285 def tarball_validations()
286 describe package('opendaylight') do
287 it { should_not be_installed }
290 # Repo checks break (not fail) when yum doesn't make sense (Ubuntu)
291 if ['centos-7', 'fedora-22'].include? ENV['RS_SET']
292 describe yumrepo('opendaylight-4-testing') do
293 it { should_not exist }
294 it { should_not be_enabled }