Add initial support for Ubuntu 14.04 Beaker tests
[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       # TODO: Why is 1 an acceptable exit code?
31       on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
32       # Install archive, a dependency of the odl mod use for tarball-type installs
33       on host, puppet('module', 'install', 'camptocamp-archive'), { :acceptable_exit_codes => [0] }
34       # Install Java Puppet mod, a dependency of the tarball install method
35       on host, puppet('module', 'install', 'puppetlabs-java'), { :acceptable_exit_codes => [0] }
36     end
37   end
38 end
39
40 #
41 # NB: These are a library of helper fns used by the Beaker tests
42 #
43
44 # NB: There are a large number of helper functions used in these tests.
45 # They make this code much more friendly, but may need to be referenced.
46 # The serverspec helpers (`should`, `be_running`...) are documented here:
47 #   http://serverspec.org/resource_types.html
48
49 def install_odl(options = {})
50   # NB: These param defaults should match the ones used by the opendaylight
51   #   class, which are defined in opendaylight::params
52   # TODO: Remove this possible source of bugs^^
53   # Extract params if given, defaulting to odl class defaults if not
54   # Default install method is passed via environment var, set in Rakefile
55   install_method = options.fetch(:install_method, ENV['INSTALL_METHOD'])
56   extra_features = options.fetch(:extra_features, [])
57   default_features = options.fetch(:default_features, ['config', 'standard', 'region',
58                                   'package', 'kar', 'ssh', 'management'])
59
60   # Build script for consumption by Puppet apply
61   it 'should work idempotently with no errors' do
62     pp = <<-EOS
63     class { 'opendaylight':
64       install_method => #{install_method},
65       default_features => #{default_features},
66       extra_features => #{extra_features},
67     }
68     EOS
69
70     # Apply our Puppet manifest on the Beaker host
71     apply_manifest(pp, :catch_failures => true)
72
73     # The tarball extract isn't idempotent, can't do this check
74     # See: https://github.com/dfarrell07/puppet-opendaylight/issues/45#issuecomment-78135725
75     if install_method != 'tarball'
76       # Run it twice to test for idempotency
77       apply_manifest(pp, :catch_changes  => true)
78     end
79   end
80 end
81
82 # Shared function that handles generic validations
83 # These should be common for all odl class param combos
84 def generic_validations()
85   # Verify ODL's directory
86   describe file('/opt/opendaylight/') do
87     it { should be_directory }
88     it { should be_owned_by 'odl' }
89     it { should be_grouped_into 'odl' }
90   end
91
92   # Verify ODL's systemd service
93   describe service('opendaylight') do
94     it { should be_enabled }
95     it { should be_enabled.with_level(3) }
96     it { should be_running }
97   end
98
99   # Creation handled by RPM, or Puppet during tarball installs
100   describe user('odl') do
101     it { should exist }
102     it { should belong_to_group 'odl' }
103     # NB: This really shouldn't have a slash at the end!
104     #     The home dir set by the RPM is `/opt/opendaylight`.
105     #     Since we use the trailing slash elsewhere else, this
106     #     may look like a style issue. It isn't! It will make
107     #     Beaker tests fail if it ends with a `/`. A future
108     #     version of the ODL RPM may change this.
109     it { should have_home_directory '/opt/opendaylight' }
110   end
111
112   # Creation handled by RPM, or Puppet during tarball installs
113   describe group('odl') do
114     it { should exist }
115   end
116
117   # This should not be the odl user's home dir
118   describe file('/home/odl') do
119     # Home dir shouldn't be created for odl user
120     it { should_not be_directory }
121   end
122
123   # OpenDaylight will appear as a Java process
124   describe process('java') do
125     it { should be_running }
126   end
127
128   # Validations specific to the host OS
129   if ['centos-7', 'fedora-20', 'fedora-21'].include? ENV['RS_SET']
130     # Validations for Red Hat family OSs
131
132     # Verify ODL systemd .service file
133     describe file('/usr/lib/systemd/system/opendaylight.service') do
134       it { should be_file }
135       it { should be_owned_by 'root' }
136       it { should be_grouped_into 'root' }
137       it { should be_mode '644' }
138     end
139
140     # Java 7 should be installed
141     describe package('java-1.7.0-openjdk') do
142       it { should be_installed }
143     end
144   elsif ENV['RS_SET'] == 'ubuntu-1404'
145     # Ubuntu-specific validations
146
147     # Verify ODL Upstart config file
148     describe file('/etc/init/opendaylight.conf') do
149       it { should be_file }
150       it { should be_owned_by 'root' }
151       it { should be_grouped_into 'root' }
152       it { should be_mode '644' }
153     end
154
155     # Java 7 should be installed
156     describe package('java7-jdk') do
157       it { should be_installed }
158     end
159   else
160     fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
161   end
162 end
163
164 # Shared function for validations related to the Karaf config file
165 def karaf_config_validations(options = {})
166   # NB: These param defaults should match the ones used by the opendaylight
167   #   class, which are defined in opendaylight::params
168   # TODO: Remove this possible source of bugs^^
169   extra_features = options.fetch(:extra_features, [])
170   default_features = options.fetch(:default_features, ['config', 'standard', 'region',
171                                   'package', 'kar', 'ssh', 'management'])
172
173   # Create one list of all of the features
174   features = default_features + extra_features
175
176   describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
177     it { should be_file }
178     it { should be_owned_by 'odl' }
179     it { should be_grouped_into 'odl' }
180     its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
181   end
182 end
183
184 # Shared function for validations related to the ODL REST port config file
185 def port_config_validations(options = {})
186   # NB: This param default should match the one used by the opendaylight
187   #   class, which is defined in opendaylight::params
188   # TODO: Remove this possible source of bugs^^
189   port = options.fetch(:port, 8080)
190
191   describe file('/opt/opendaylight/configuration/tomcat-server.xml') do
192     it { should be_file }
193     it { should be_owned_by 'odl' }
194     it { should be_grouped_into 'odl' }
195     its(:content) { should match /'    <Connector port="#{port}" protocol="HTTP\/1.1"'$/ }
196   end
197 end
198
199
200 # Shared function that handles validations specific to RPM-type installs
201 def rpm_validations()
202   describe yumrepo('opendaylight') do
203     it { should exist }
204     it { should be_enabled }
205   end
206
207   describe package('opendaylight') do
208     it { should be_installed }
209   end
210 end
211
212 # Shared function that handles validations specific to tarball-type installs
213 def tarball_validations()
214   describe yumrepo('opendaylight') do
215     it { should_not exist }
216     it { should_not be_enabled }
217   end
218
219   describe package('opendaylight') do
220     it { should_not be_installed }
221   end
222 end