1 require 'puppetlabs_spec_helper/module_spec_helper'
3 # Customize filters to ignore 3rd-party code
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]',
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]',
25 'Stage[deploy_infra]',
30 RSpec::Puppet::Coverage.filters.push(*custom_filters)
32 # Tests that are common to all possible configurations
34 # Confirm that module compiles
36 it { should compile.with_all_deps }
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') }
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') }
53 # Confirm presence of generic resources
54 it { should contain_service('opendaylight') }
55 it { should contain_file('org.apache.karaf.features.cfg') }
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.
61 should contain_service('opendaylight').with(
62 'ensure' => 'running',
64 'hasstatus' => 'true',
65 'hasrestart' => 'true',
69 should contain_file('org.apache.karaf.features.cfg').with(
71 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
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.
82 should contain_file('org.apache.karaf.features.cfg').with(
84 'path' => '/opt/opendaylight/etc/org.apache.karaf.features.cfg',
85 'content' => /^featuresBoot=#{features.join(",")}/
90 def tarball_install_tests(options = {})
92 tarball_url = options.fetch(:tarball_url, 'https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.2-Helium-SR2/distribution-karaf-0.2.2-Helium-SR2.tar.gz')
93 unitfile_url = options.fetch(:unitfile_url, 'https://github.com/dfarrell07/opendaylight-systemd/archive/master/opendaylight-unitfile.tar.gz')
94 osfamily = options.fetch(:osfamily, 'RedHat')
96 # Confirm presence of tarball-related resources
97 it { should contain_archive('opendaylight') }
98 it { should contain_class('java') }
99 it { should contain_file('/opt/opendaylight/') }
100 it { should contain_user('odl') }
101 it { should contain_group('odl') }
103 # Confirm relationships between tarball-related resources
104 it { should contain_archive('opendaylight').that_comes_before('File[/opt/opendaylight/]') }
105 it { should contain_archive('opendaylight').that_comes_before('User[odl]') }
106 it { should contain_file('/opt/opendaylight/').that_requires('Archive[opendaylight]') }
107 it { should contain_file('/opt/opendaylight/').that_requires('Group[odl]') }
108 it { should contain_file('/opt/opendaylight/').that_requires('User[odl]') }
109 it { should contain_user('odl').that_comes_before('File[/opt/opendaylight/]') }
110 it { should contain_user('odl').that_requires('Archive[opendaylight]') }
111 it { should contain_user('odl').that_requires('Group[odl]') }
112 it { should contain_group('odl').that_comes_before('File[/opt/opendaylight/]') }
113 it { should contain_group('odl').that_comes_before('User[odl]') }
115 # Confirm properties of tarball-related resources
116 # NB: These hashes don't work with Ruby 1.8.7, but we
117 # don't support 1.8.7 so that's okay. See issue #36.
119 should contain_archive('opendaylight').with(
120 'ensure' => 'present',
121 'url' => tarball_url,
122 'target' => '/opt/opendaylight/',
124 'strip_components' => 1,
129 should contain_file('/opt/opendaylight/').with(
130 'ensure' => 'directory',
137 should contain_user('odl').with(
139 'ensure' => 'present',
140 'home' => '/opt/opendaylight/',
141 'membership' => 'minimum',
146 should contain_group('odl').with(
148 'ensure' => 'present',
152 # OS-specific validations
155 # Validations specific to Red Hat family OSs (RHEL/CentOS/Fedora)
156 it { should contain_archive('opendaylight-systemd') }
157 it { should contain_file('/usr/lib/systemd/system/opendaylight.service') }
158 it { should contain_archive('opendaylight-systemd').that_comes_before('File[/usr/lib/systemd/system/opendaylight.service]') }
159 it { should contain_file('/usr/lib/systemd/system/opendaylight.service').that_requires('Archive[opendaylight-systemd]') }
161 # NB: These hashes don't work with Ruby 1.8.7, but we
162 # don't support 1.8.7 so that's okay. See issue #36.
164 should contain_package('java').with(
165 'name' => 'java-1.7.0-openjdk',
169 should contain_archive('opendaylight-systemd').with(
170 'ensure' => 'present',
171 'url' => unitfile_url,
172 'target' => '/usr/lib/systemd/system/',
173 'root_dir' => 'opendaylight.service',
175 'strip_components' => 1,
176 'follow_redirects' => true,
180 should contain_file('/usr/lib/systemd/system/opendaylight.service').with(
188 # Validations specific to Debain family OSs (Ubuntu)
190 should contain_package('java').with(
191 'name' => 'java7-jdk',
195 should contain_file('/etc/init/opendaylight.conf').with(
202 expected_msg = 'Debian has limited support, is less stable, less tested.'
205 # This could be any check, most (all?) will raise warning
206 should contain_file('/etc/init/opendaylight.conf').to(
207 raise_warning(Puppet::Warning, /#{expected_msg}/)
212 fail("Unexpected osfamily #{osfamily}")
215 # Verify that there are no unexpected resources from RPM-type installs
216 it { should_not contain_yumrepo('opendaylight') }
217 it { should_not contain_package('opendaylight') }
220 def rpm_install_tests(options = {})
222 # Default to CentOS 7 Yum repo URL
223 yum_repo = options.fetch(:yum_repo, 'https://copr-be.cloud.fedoraproject.org/results/dfarrell07/OpenDaylight/epel-7-$basearch/')
225 # Confirm presence of RPM-related resources
226 it { should contain_yumrepo('opendaylight') }
227 it { should contain_package('opendaylight') }
229 # Confirm relationships between RPM-related resources
230 it { should contain_package('opendaylight').that_requires('Yumrepo[opendaylight]') }
231 it { should contain_yumrepo('opendaylight').that_comes_before('Package[opendaylight]') }
233 # Confirm properties of RPM-related resources
234 # NB: These hashes don't work with Ruby 1.8.7, but we
235 # don't support 1.8.7 so that's okay. See issue #36.
237 should contain_yumrepo('opendaylight').with(
240 'descr' => 'OpenDaylight SDN controller',
241 'baseurl' => yum_repo,
245 should contain_package('opendaylight').with(
246 'ensure' => 'present',
251 # Shared tests for unsupported OSs
252 def unsupported_os_tests(options = {})
254 expected_msg = options.fetch(:expected_msg)
256 # Confirm that classes fail on unsupported OSs
257 it { expect { should contain_class('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
258 it { expect { should contain_class('opendaylight::install') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
259 it { expect { should contain_class('opendaylight::config') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
260 it { expect { should contain_class('opendaylight::service') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
262 # Confirm that other resources fail on unsupported OSs
263 it { expect { should contain_yumrepo('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
264 it { expect { should contain_package('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
265 it { expect { should contain_service('opendaylight') }.to raise_error(Puppet::Error, /#{expected_msg}/) }
266 it { expect { should contain_file('org.apache.karaf.features.cfg') }.to raise_error(Puppet::Error, /#{expected_msg}/) }