Update ODL to Beryllium SR1
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper_acceptance.rb
1 require 'beaker-rspec/spec_helper'
2 require 'beaker-rspec/helpers/serverspec'
3
4 # Install Puppet on all Beaker hosts
5 unless ENV['BEAKER_provision'] == 'no'
6   hosts.each do |host|
7     # Install Puppet
8     if host.is_pe?
9       install_pe
10     else
11       install_puppet
12     end
13   end
14 end
15
16 RSpec.configure do |c|
17   # Project root
18   proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
19
20   # Readable test descriptions
21   c.formatter = :documentation
22
23   # Configure all nodes in nodeset
24   c.before :suite do
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')
28     hosts.each do |host|
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] }
35     end
36   end
37 end
38
39 #
40 # NB: These are a library of helper fns used by the Beaker tests
41 #
42
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
47
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')
61
62   # Build script for consumption by Puppet apply
63   it 'should work idempotently with no errors' do
64     pp = <<-EOS
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},
72     }
73     EOS
74
75     # Apply our Puppet manifest on the Beaker host
76     apply_manifest(pp, :catch_failures => true)
77
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)
83     end
84   end
85 end
86
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' }
95   end
96
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 }
102   end
103
104   # Creation handled by RPM, or Puppet during tarball installs
105   describe user('odl') do
106     it { should exist }
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' }
115   end
116
117   # Creation handled by RPM, or Puppet during tarball installs
118   describe group('odl') do
119     it { should exist }
120   end
121
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 }
126   end
127
128   # OpenDaylight will appear as a Java process
129   describe process('java') do
130     it { should be_running }
131   end
132
133   # Should contain Karaf features config file
134   describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
135     it { should be_file }
136     it { should be_owned_by 'odl' }
137     it { should be_grouped_into 'odl' }
138   end
139
140   # Should contain ODL NB port config file
141   describe file('/opt/opendaylight/etc/jetty.xml') do
142     it { should be_file }
143     it { should be_owned_by 'odl' }
144     it { should be_grouped_into 'odl' }
145   end
146
147   # Should contain log level config file
148   describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
149     it { should be_file }
150     it { should be_owned_by 'odl' }
151     it { should be_grouped_into 'odl' }
152   end
153
154   # Should contain ODL OVSDB L3 enable/disable config file
155   describe file('/opt/opendaylight/etc/custom.properties') do
156     it { should be_file }
157     it { should be_owned_by 'odl' }
158     it { should be_grouped_into 'odl' }
159   end
160
161   if ['centos-7', 'centos-7-docker', 'fedora-22', 'fedora-23-docker'].include? ENV['RS_SET']
162     # Validations for modern Red Hat family OSs
163
164     # Verify ODL systemd .service file
165     describe file('/usr/lib/systemd/system/opendaylight.service') do
166       it { should be_file }
167       it { should be_owned_by 'root' }
168       it { should be_grouped_into 'root' }
169       it { should be_mode '644' }
170     end
171
172     # Java 8 should be installed
173     describe package('java-1.8.0-openjdk') do
174       it { should be_installed }
175     end
176   elsif ['ubuntu-1404', 'ubuntu-1404-docker'].include? ENV['RS_SET']
177     # Ubuntu-specific validations
178
179     # Verify ODL Upstart config file
180     describe file('/etc/init/opendaylight.conf') do
181       it { should be_file }
182       it { should be_owned_by 'root' }
183       it { should be_grouped_into 'root' }
184       it { should be_mode '644' }
185     end
186
187     # Java 7 should be installed
188     describe package('openjdk-7-jdk') do
189       it { should be_installed }
190     end
191   else
192     fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
193   end
194 end
195
196 # Shared function for validations related to the Karaf config file
197 def karaf_config_validations(options = {})
198   # NB: These param defaults should match the ones used by the opendaylight
199   #   class, which are defined in opendaylight::params
200   # TODO: Remove this possible source of bugs^^
201   extra_features = options.fetch(:extra_features, [])
202   default_features = options.fetch(:default_features, ['config', 'standard', 'region',
203                                   'package', 'kar', 'ssh', 'management'])
204
205   # Create one list of all of the features
206   features = default_features + extra_features
207
208   describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
209     it { should be_file }
210     it { should be_owned_by 'odl' }
211     it { should be_grouped_into 'odl' }
212     its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
213   end
214 end
215
216 # Shared function for validations related to the ODL REST port config file
217 def port_config_validations(options = {})
218   # NB: This param default should match the one used by the opendaylight
219   #   class, which is defined in opendaylight::params
220   # TODO: Remove this possible source of bugs^^
221   odl_rest_port = options.fetch(:odl_rest_port, 8080)
222
223   describe file('/opt/opendaylight/etc/jetty.xml') do
224     it { should be_file }
225     it { should be_owned_by 'odl' }
226     it { should be_grouped_into 'odl' }
227     its(:content) { should match /Property name="jetty.port" default="#{odl_rest_port}"/ }
228   end
229 end
230
231 # Shared function for validations related to custom logging verbosity
232 def log_level_validations(options = {})
233   # NB: This param default should match the one used by the opendaylight
234   #   class, which is defined in opendaylight::params
235   # TODO: Remove this possible source of bugs^^
236   log_levels = options.fetch(:log_levels, {})
237
238   if log_levels.empty?
239     # Should contain log level config file
240     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
241       it { should be_file }
242       it { should be_owned_by 'odl' }
243       it { should be_grouped_into 'odl' }
244     end
245     # Should not contain custom log level config
246     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
247       it { should be_file }
248       it { should be_owned_by 'odl' }
249       it { should be_grouped_into 'odl' }
250       its(:content) { should_not match /# Log level config added by puppet-opendaylight/ }
251     end
252   else
253     # Should contain log level config file
254     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
255       it { should be_file }
256       it { should be_owned_by 'odl' }
257       it { should be_grouped_into 'odl' }
258     end
259     # Should not contain custom log level config
260     describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
261       it { should be_file }
262       it { should be_owned_by 'odl' }
263       it { should be_grouped_into 'odl' }
264       its(:content) { should match /# Log level config added by puppet-opendaylight/ }
265     end
266     # Verify each custom log level config entry
267     log_levels.each_pair do |logger, level|
268       describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
269         it { should be_file }
270         it { should be_owned_by 'odl' }
271         it { should be_grouped_into 'odl' }
272         its(:content) { should match /^log4j.logger.#{logger} = #{level}/ }
273       end
274     end
275   end
276 end
277
278 # Shared function for validations related to ODL OVSDB L3 config
279 def enable_l3_validations(options = {})
280   # NB: This param default should match the one used by the opendaylight
281   #   class, which is defined in opendaylight::params
282   # TODO: Remove this possible source of bugs^^
283   enable_l3 = options.fetch(:enable_l3, 'no')
284
285   if [true, 'yes'].include? enable_l3
286     # Confirm ODL OVSDB L3 is enabled
287     describe file('/opt/opendaylight/etc/custom.properties') do
288       it { should be_file }
289       it { should be_owned_by 'odl' }
290       it { should be_grouped_into 'odl' }
291       its(:content) { should match /^ovsdb.l3.fwd.enabled=yes/ }
292     end
293   elsif [false, 'no'].include? enable_l3
294     # Confirm ODL OVSDB L3 is disabled
295     describe file('/opt/opendaylight/etc/custom.properties') do
296       it { should be_file }
297       it { should be_owned_by 'odl' }
298       it { should be_grouped_into 'odl' }
299       its(:content) { should match /^ovsdb.l3.fwd.enabled=no/ }
300     end
301   end
302 end
303
304 # Shared function that handles validations specific to RPM-type installs
305 def rpm_validations()
306   describe yumrepo('opendaylight-41-release') do
307     it { should exist }
308     it { should be_enabled }
309   end
310
311   describe package('opendaylight') do
312     it { should be_installed }
313   end
314 end
315
316 # Shared function that handles validations specific to tarball-type installs
317 def tarball_validations()
318   describe package('opendaylight') do
319     it { should_not be_installed }
320   end
321
322   # Repo checks break (not fail) when yum doesn't make sense (Ubuntu)
323   if ['centos-7', 'fedora-22', 'fedora-23-docker'].include? ENV['RS_SET']
324     describe yumrepo('opendaylight-41-release') do
325       it { should_not exist }
326       it { should_not be_enabled }
327     end
328   end
329 end