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
33 def generic_tests(yum_repo)
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 install_method_tests(method, yum_repo, tarball_url='', unitfile_url='')
93 # Confirm presence of RPM-related resources
94 it { should contain_yumrepo('opendaylight') }
95 it { should contain_package('opendaylight') }
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]') }
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.
105 should contain_yumrepo('opendaylight').with(
108 'descr' => 'OpenDaylight SDN controller',
109 'baseurl' => yum_repo,
113 should contain_package('opendaylight').with(
114 'ensure' => 'present',
119 fail('Expected tarball_url param')
122 if unitfile_url == ''
123 fail('Expected unitfile_url param')
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') }
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]') }
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.
153 should contain_archive('opendaylight').with(
154 'ensure' => 'present',
155 'url' => tarball_url,
156 'target' => '/opt/opendaylight/',
158 'strip_components' => 1,
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',
169 'strip_components' => 1,
170 'follow_redirects' => true,
174 should contain_package('java').with(
175 'name' => 'java-1.7.0-openjdk',
179 should contain_file('/opt/opendaylight/').with(
180 'ensure' => 'directory',
187 should contain_file('/usr/lib/systemd/system/opendaylight.service').with(
195 should contain_user('odl').with(
197 'ensure' => 'present',
198 'home' => '/opt/opendaylight/',
199 'membership' => 'minimum',
204 should contain_group('odl').with(
206 'ensure' => 'present',
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') }
214 fail("Unexpected install method: #{method}")
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}/) }
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}/) }