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)
60 # Build script for consumption by Puppet apply
61 it 'should work idempotently with no errors' do
63 class { 'opendaylight':
64 install_method => #{install_method},
65 default_features => #{default_features},
66 extra_features => #{extra_features},
67 odl_rest_port=> #{odl_rest_port},
71 # Apply our Puppet manifest on the Beaker host
72 apply_manifest(pp, :catch_failures => true)
74 # The tarball extract isn't idempotent, can't do this check
75 # See: https://github.com/dfarrell07/puppet-opendaylight/issues/45#issuecomment-78135725
76 if install_method != 'tarball'
77 # Run it twice to test for idempotency
78 apply_manifest(pp, :catch_changes => true)
83 # Shared function that handles generic validations
84 # These should be common for all odl class param combos
85 def generic_validations()
86 # Verify ODL's directory
87 describe file('/opt/opendaylight/') do
88 it { should be_directory }
89 it { should be_owned_by 'odl' }
90 it { should be_grouped_into 'odl' }
93 # Verify ODL's systemd service
94 describe service('opendaylight') do
95 it { should be_enabled }
96 it { should be_enabled.with_level(3) }
97 it { should be_running }
100 # Creation handled by RPM, or Puppet during tarball installs
101 describe user('odl') do
103 it { should belong_to_group 'odl' }
104 # NB: This really shouldn't have a slash at the end!
105 # The home dir set by the RPM is `/opt/opendaylight`.
106 # Since we use the trailing slash elsewhere else, this
107 # may look like a style issue. It isn't! It will make
108 # Beaker tests fail if it ends with a `/`. A future
109 # version of the ODL RPM may change this.
110 it { should have_home_directory '/opt/opendaylight' }
113 # Creation handled by RPM, or Puppet during tarball installs
114 describe group('odl') do
118 # This should not be the odl user's home dir
119 describe file('/home/odl') do
120 # Home dir shouldn't be created for odl user
121 it { should_not be_directory }
124 # OpenDaylight will appear as a Java process
125 describe process('java') do
126 it { should be_running }
129 # Validations specific to the host OS
130 if ['fedora-20'].include? ENV['RS_SET']
131 # Validations for (legecy) Fedora 20 checks
132 # NB: Fedora 20 support will be removed soon, it's EOL
134 # Verify ODL systemd .service file
135 describe file('/usr/lib/systemd/system/opendaylight.service') do
136 it { should be_file }
137 it { should be_owned_by 'root' }
138 it { should be_grouped_into 'root' }
139 it { should be_mode '644' }
142 # Java 7 should be installed
143 describe package('java-1.7.0-openjdk') do
144 it { should be_installed }
146 elsif ['centos-7', 'centos-7-docker', 'fedora-21'].include? ENV['RS_SET']
147 # Validations for modern Red Hat family OSs
149 # Verify ODL systemd .service file
150 describe file('/usr/lib/systemd/system/opendaylight.service') do
151 it { should be_file }
152 it { should be_owned_by 'root' }
153 it { should be_grouped_into 'root' }
154 it { should be_mode '644' }
157 # Java 8 should be installed
158 describe package('java-1.8.0-openjdk') do
159 it { should be_installed }
161 elsif ['ubuntu-1404', 'ubuntu-1404-docker'].include? ENV['RS_SET']
162 # Ubuntu-specific validations
164 # Verify ODL Upstart config file
165 describe file('/etc/init/opendaylight.conf') 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' }
172 # Java 7 should be installed
173 describe package('openjdk-7-jdk') do
174 it { should be_installed }
177 fail("Unexpected RS_SET (host OS): #{ENV['RS_SET']}")
181 # Shared function for validations related to the Karaf config file
182 def karaf_config_validations(options = {})
183 # NB: These param defaults should match the ones used by the opendaylight
184 # class, which are defined in opendaylight::params
185 # TODO: Remove this possible source of bugs^^
186 extra_features = options.fetch(:extra_features, [])
187 default_features = options.fetch(:default_features, ['config', 'standard', 'region',
188 'package', 'kar', 'ssh', 'management'])
190 # Create one list of all of the features
191 features = default_features + extra_features
193 describe file('/opt/opendaylight/etc/org.apache.karaf.features.cfg') do
194 it { should be_file }
195 it { should be_owned_by 'odl' }
196 it { should be_grouped_into 'odl' }
197 its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
201 # Shared function for validations related to the ODL REST port config file
202 def port_config_validations(options = {})
203 # NB: This param default should match the one used by the opendaylight
204 # class, which is defined in opendaylight::params
205 # TODO: Remove this possible source of bugs^^
206 odl_rest_port = options.fetch(:odl_rest_port, 8080)
208 describe file('/opt/opendaylight/etc/jetty.xml') 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 /Property name="jetty.port" default="#{odl_rest_port}"/ }
217 # Shared function that handles validations specific to RPM-type installs
218 def rpm_validations()
219 describe yumrepo('opendaylight-3-candidate') do
221 it { should be_enabled }
224 describe package('opendaylight') do
225 it { should be_installed }
229 # Shared function that handles validations specific to tarball-type installs
230 def tarball_validations()
231 describe package('opendaylight') do
232 it { should_not be_installed }
235 # Repo checks break (not fail) when yum doesn't make sense (Ubuntu)
236 if ['centos-7', 'fedora-20', 'fedora-21'].include? ENV['RS_SET']
237 describe yumrepo('opendaylight-3-candidate') do
238 it { should_not exist }
239 it { should_not be_enabled }