recover Fedora 20/21
[integration/packaging/puppet-opendaylight.git] / spec / spec_helper.rb
1 require 'puppetlabs_spec_helper/module_spec_helper'
2
3 # Customize filters to ignore 3rd-party code
4 custom_filters = [
5   'Anchor[java::end]',
6   'Stage[setup]',
7   'Anchor[java::begin:]',
8   'Archive::Download[opendaylight.tar.gz]',
9   'Archive::Download[opendaylight-systemd.tar.gz]',
10   'Archive::Extract[opendaylight]',
11   'Archive::Extract[opendaylight-systemd]',
12   'Class[Java::Config]',
13   'Class[Java::Params]',
14   'Class[Stdlib::Stages]',
15   'Class[Stdlib]',
16   'Exec[download archive opendaylight.tar.gz and check sum]',
17   'Exec[download archive opendaylight-systemd.tar.gz and check sum]',
18   'Exec[opendaylight unpack]',
19   'Exec[opendaylight-systemd unpack]',
20   'Exec[rm-on-error-opendaylight.tar.gz]',
21   'Exec[rm-on-error-opendaylight-systemd.tar.gz]',
22   'Package[curl]',
23   'Stage[deploy]',
24   'Stage[deploy_app]',
25   'Stage[deploy_infra]',
26   'Stage[runtime]',
27   'Stage[setup_app]',
28   'Stage[setup_infra]',
29 ]
30 RSpec::Puppet::Coverage.filters.push(*custom_filters)
31
32 # Tests that are common to all possible configurations
33 def generic_tests(yum_repo)
34   # Confirm that module compiles
35   it { should compile }
36   it { should compile.with_all_deps }
37
38   # Confirm presence of classes
39   it { should contain_class('opendaylight') }
40   it { should contain_class('opendaylight::params') }
41   it { should contain_class('opendaylight::install') }
42   it { should contain_class('opendaylight::config') }
43   it { should contain_class('opendaylight::service') }
44
45   # Confirm relationships between classes
46   it { should contain_class('opendaylight::install').that_comes_before('opendaylight::config') }
47   it { should contain_class('opendaylight::config').that_requires('opendaylight::install') }
48   it { should contain_class('opendaylight::config').that_notifies('opendaylight::service') }
49   it { should contain_class('opendaylight::service').that_subscribes_to('opendaylight::config') }
50   it { should contain_class('opendaylight::service').that_comes_before('opendaylight') }
51   it { should contain_class('opendaylight').that_requires('opendaylight::service') }
52
53   # Confirm presence of generic resources
54   it { should contain_service('opendaylight') }
55   it { should contain_file('org.apache.karaf.features.cfg') }
56
57   # Confirm properties of generic resources
58   # NB: These hashes don't work with Ruby 1.8.7, but we
59   #   don't support 1.8.7 so that's okay. See issue #36.
60   it {
61     should contain_service('opendaylight').with(
62       'ensure'      => 'running',
63       'enable'      => 'true',
64       'hasstatus'   => 'true',
65       'hasrestart'  => 'true',
66     )
67   }
68   it {
69     should contain_file('org.apache.karaf.features.cfg').with(
70       'ensure'      => 'file',
71       'path'        => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
72     )
73   }
74 end
75
76 # Shared tests that specialize in testing Karaf feature installs
77 def karaf_feature_tests(features)
78   # Confirm properties of other resources
79   # NB: These hashes don't work with Ruby 1.8.7, but we
80   #   don't support 1.8.7 so that's okay. See issue #36.
81   it {
82     should contain_file('org.apache.karaf.features.cfg').with(
83       'ensure'      => 'file',
84       'path'        => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
85       'content'     => /^featuresBoot=#{features.join(",")}/
86     )
87   }
88 end
89
90 def install_method_tests(method, yum_repo, tarball_url='', unitfile_url='')
91   case method
92   when 'rpm'
93     # Confirm presence of RPM-related resources
94     it { should contain_yumrepo('opendaylight') }
95     it { should contain_package('opendaylight') }
96
97     # Confirm relationships between RPM-related resources
98     it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') }
99     it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') }
100
101     # Confirm properties of RPM-related resources
102     # NB: These hashes don't work with Ruby 1.8.7, but we
103     #   don't support 1.8.7 so that's okay. See issue #36.
104     it {
105       should contain_yumrepo('opendaylight').with(
106         'enabled'     => '1',
107         'gpgcheck'    => '0',
108         'descr'       => 'OpenDaylight SDN controller',
109         'baseurl'     => yum_repo,
110       )
111     }
112     it {
113       should contain_package('opendaylight').with(
114         'ensure'   => 'present',
115       )
116     }
117   when 'tarball'
118     if tarball_url == ''
119       fail('Expected tarball_url param')
120     end
121
122     if unitfile_url == ''
123       fail('Expected unitfile_url param')
124     end
125
126     # Confirm presence of tarball-related resources
127     it { should contain_archive('opendaylight') }
128     it { should contain_archive('opendaylight-systemd') }
129     it { should contain_class('java') }
130     it { should contain_file('/opt/opendaylight/') }
131     it { should contain_file('/usr/lib/systemd/system/opendaylight.service') }
132     it { should contain_user('odl') }
133     it { should contain_group('odl') }
134
135     # Confirm relationships between tarball-related resources
136     it { should contain_archive('opendaylight').that_comes_before('File[/opt/opendaylight/]') }
137     it { should contain_archive('opendaylight').that_comes_before('User[odl]') }
138     it { should contain_archive('opendaylight-systemd').that_comes_before('File[/usr/lib/systemd/system/opendaylight.service]') }
139     it { should contain_file('/opt/opendaylight/').that_requires('Archive[opendaylight]') }
140     it { should contain_file('/opt/opendaylight/').that_requires('Group[odl]') }
141     it { should contain_file('/opt/opendaylight/').that_requires('User[odl]') }
142     it { should contain_file('/usr/lib/systemd/system/opendaylight.service').that_requires('Archive[opendaylight-systemd]') }
143     it { should contain_user('odl').that_comes_before('File[/opt/opendaylight/]') }
144     it { should contain_user('odl').that_requires('Archive[opendaylight]') }
145     it { should contain_user('odl').that_requires('Group[odl]') }
146     it { should contain_group('odl').that_comes_before('File[/opt/opendaylight/]') }
147     it { should contain_group('odl').that_comes_before('User[odl]') }
148
149     # Confirm properties of tarball-related resources
150     # NB: These hashes don't work with Ruby 1.8.7, but we
151     #   don't support 1.8.7 so that's okay. See issue #36.
152     it {
153       should contain_archive('opendaylight').with(
154         'ensure'           => 'present',
155         'url'              => tarball_url,
156         'target'           => '/opt/opendaylight/',
157         'checksum'         => false,
158         'strip_components' => 1,
159         'timeout'          => 600,
160       )
161     }
162     it {
163       should contain_archive('opendaylight-systemd').with(
164         'ensure'           => 'present',
165         'url'              => unitfile_url,
166         'target'           => '/usr/lib/systemd/system/',
167         'root_dir'         => 'opendaylight.service',
168         'checksum'         => false,
169         'strip_components' => 1,
170         'follow_redirects' => true,
171       )
172     }
173     it {
174       should contain_package('java').with(
175         'name' => 'java-1.7.0-openjdk',
176       )
177     }
178     it {
179       should contain_file('/opt/opendaylight/').with(
180         'ensure'  => 'directory',
181         'recurse' => true,
182         'owner'   => 'odl',
183         'group'   => 'odl',
184       )
185     }
186     it {
187       should contain_file('/usr/lib/systemd/system/opendaylight.service').with(
188         'ensure'  => 'file',
189         'owner'   => 'root',
190         'group'   => 'root',
191         'mode'    => '0644',
192       )
193     }
194     it {
195       should contain_user('odl').with(
196         'name'       => 'odl',
197         'ensure'     => 'present',
198         'home'       => '/opt/opendaylight/',
199         'membership' => 'minimum',
200         'groups'     => 'odl',
201       )
202     }
203     it {
204       should contain_group('odl').with(
205         'name'       => 'odl',
206         'ensure'     => 'present',
207       )
208     }
209
210     # Verify that there are no unexpected resources from RPM-type installs
211     it { should_not contain_yumrepo('opendaylight') }
212     it { should_not contain_package('opendaylight') }
213   else
214     fail("Unexpected install method: #{method}")
215   end
216 end
217
218 # Shared tests for unsupported OSs
219 def unsupported_os_tests(expected_err_msg)
220   # Confirm that classes fail on unsupported OSs
221   it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
222   it { expect { should contain_class('opendaylight::install') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
223   it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
224   it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
225
226   # Confirm that other resources fail on unsupported OSs
227   it { expect { should contain_yumrepo('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
228   it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
229   it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
230   it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /#{expected_err_msg}/) }
231 end