General refactoring of 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       # TODO: I'd prefer not to use gini-archive. See:
34       # https://github.com/dfarrell07/puppet-opendaylight/issues/52
35       on host, puppet('module', 'install', 'gini-archive'), { :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 def install_odl(options = {})
45   # NB: These param defaults should match the ones used by the opendaylight
46   #   class, which are defined in opendaylight::params
47   # TODO: Remove this possible source of bugs^^
48   # Extract params if given, defaulting to odl class defaults if not
49   install_method = options.fetch(:install_method, 'rpm')
50   extra_features = options.fetch(:extra_features, [])
51   default_features = options.fetch(:default_features, ['config', 'standard', 'region',
52                                   'package', 'kar', 'ssh', 'management'])
53
54   # Build script for consumption by Puppet apply
55   it 'should work idempotently with no errors' do
56     pp = <<-EOS
57     class { 'opendaylight':
58       install_method => #{install_method},
59       default_features => #{default_features},
60       extra_features => #{extra_features},
61     }
62     EOS
63
64     # TODO: Apply to host selectively based on install method
65
66     # Run it twice and test for idempotency
67     apply_manifest(pp, :catch_failures => true)
68     apply_manifest(pp, :catch_changes  => true)
69   end
70 end
71
72 # Shared function that handles generic validations
73 # These should be common for all odl class param combos
74 def generic_validations()
75   # TODO: It'd be nice to do this independently of install dir name
76   describe file('/opt/opendaylight-0.2.2/') do
77     it { should be_directory }
78     it { should be_owned_by 'odl' }
79     it { should be_grouped_into 'odl' }
80     it { should be_mode '775' }
81   end
82
83   describe service('opendaylight') do
84     it { should be_enabled }
85     it { should be_enabled.with_level(3) }
86     it { should be_running }
87   end
88
89   # OpenDaylight will appear as a Java process
90   describe process('java') do
91     it { should be_running }
92   end
93
94   # TODO: It'd be nice to do this independently of install dir name
95   describe user('odl') do
96     it { should exist }
97     it { should belong_to_group 'odl' }
98     it { should have_home_directory '/opt/opendaylight-0.2.2' }
99   end
100
101   describe file('/home/odl') do
102     # Home dir shouldn't be created for odl user
103     it { should_not be_directory }
104   end
105
106   describe file('/usr/lib/systemd/system/opendaylight.service') do
107     it { should be_file }
108     it { should be_owned_by 'root' }
109     it { should be_grouped_into 'root' }
110     it { should be_mode '644' }
111   end
112 end
113
114 # Shared function for validations related to the Karaf config file
115 def karaf_config_validations(options = {})
116   # NB: These param defaults should match the ones used by the opendaylight
117   #   class, which are defined in opendaylight::params
118   # TODO: Remove this possible source of bugs^^
119   extra_features = options.fetch(:extra_features, [])
120   default_features = options.fetch(:default_features, ['config', 'standard', 'region',
121                                   'package', 'kar', 'ssh', 'management'])
122
123   # Create one list of all of the features
124   features = default_features + extra_features
125
126   # TODO: It'd be nice to do this independently of install dir name
127   describe file('/opt/opendaylight-0.2.2/etc/org.apache.karaf.features.cfg') do
128     it { should be_file }
129     it { should be_owned_by 'odl' }
130     it { should be_grouped_into 'odl' }
131     it { should be_mode '775' }
132     its(:content) { should match /^featuresBoot=#{features.join(",")}/ }
133   end
134 end
135
136 # Shared function that handles validations specific to RPM-type installs
137 def rpm_validations()
138   describe yumrepo('opendaylight') do
139     it { should exist }
140     it { should be_enabled }
141   end
142
143   describe package('opendaylight') do
144     it { should be_installed }
145   end
146 end