|
2 | 2 |
|
3 | 3 | describe 'graphite::config', :type => 'class' do
|
4 | 4 |
|
5 |
| - shared_context 'Unsupported OS' do |
6 |
| - it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )} |
7 |
| - end |
8 |
| - |
9 |
| - shared_context 'Debian unsupported platforms' do |
10 |
| - it { is_expected.to raise_error(Puppet::Error,/Unsupported Debian release/) } |
11 |
| - end |
12 |
| - |
13 |
| - shared_context 'RedHat unsupported platforms' do |
14 |
| - it { is_expected.to raise_error(Puppet::Error,/Unsupported RedHat release/) } |
15 |
| - end |
16 |
| - |
17 |
| - shared_context 'supported platforms' do |
18 |
| - it { is_expected.to contain_class('graphite::params') } |
19 |
| - it { is_expected.to contain_exec('Initial django db creation') } |
20 |
| - it { is_expected.to contain_class('graphite::config_apache') } |
21 |
| - |
22 |
| - # cron check |
23 |
| - it { is_expected.to contain_file('/opt/graphite/bin/carbon-logrotate.sh').with({ |
24 |
| - 'ensure' => 'file', 'mode' => '0544', 'content' => /^CARBON_LOGS_PATH="\/opt\/graphite\/storage\/log"$/ }) } |
25 |
| - it { is_expected.to contain_cron('Rotate carbon logs').with({ |
26 |
| - 'command' => '/opt/graphite/bin/carbon-logrotate.sh', |
27 |
| - 'hour' => '3', |
28 |
| - 'minute' => '15', |
29 |
| - 'require' => 'File[/opt/graphite/bin/carbon-logrotate.sh]', |
30 |
| - 'user' => 'root',}) } |
31 |
| - end |
32 |
| - |
33 | 5 | shared_context 'RedHat supported platforms' do
|
34 | 6 | it { is_expected.to contain_file('/opt/graphite/storage/whisper').with({
|
35 | 7 | 'ensure' => 'directory', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0755', }) }
|
|
44 | 16 | 'ensure' => 'file', 'owner' => 'apache', 'group' => 'apache', 'mode' => '0644' }).that_requires('Package[httpd]') }
|
45 | 17 | it { is_expected.to contain_file('/opt/graphite/webapp/graphite/graphite_wsgi.py').with({
|
46 | 18 | 'ensure' => 'link', 'target' => '/opt/graphite/conf/graphite_wsgi.py', 'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]' }) }
|
| 19 | + it { is_expected.to contain_service('carbon-cache').with({ |
| 20 | + 'ensure' => 'running', |
| 21 | + 'enable' => 'true', |
| 22 | + 'hasrestart' => 'true', |
| 23 | + 'hasstatus' => 'true', |
| 24 | + 'provider' => 'redhat', |
| 25 | + 'require' => 'File[/etc/init.d/carbon-cache]' }) } |
47 | 26 | end
|
48 | 27 |
|
49 | 28 | shared_context 'RedHat 6 platforms' do
|
| 29 | + it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({ |
| 30 | + 'ensure' => 'file', |
| 31 | + 'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/, |
| 32 | + 'mode' => '0750', |
| 33 | + 'require' => 'File[/opt/graphite/conf/carbon.conf]', |
| 34 | + 'notify' => [] }) } |
50 | 35 | end
|
51 | 36 |
|
52 | 37 | shared_context 'RedHat 7 platforms' do
|
53 | 38 | it { is_expected.to contain_exec('graphite-reload-systemd') }
|
| 39 | + it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({ |
| 40 | + 'ensure' => 'file', |
| 41 | + 'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/, |
| 42 | + 'mode' => '0750', |
| 43 | + 'require' => 'File[/opt/graphite/conf/carbon.conf]', |
| 44 | + 'notify' => /graphite-reload-systemd/ }) } |
54 | 45 | end
|
55 | 46 |
|
56 | 47 | shared_context 'Debian supported platforms' do
|
|
67 | 58 | 'ensure' => 'file', 'owner' => 'www-data', 'group' => 'www-data', 'mode' => '0644' }).that_requires('Package[apache2]') }
|
68 | 59 | it { is_expected.to contain_file('/opt/graphite/webapp/graphite/graphite_wsgi.py').with({
|
69 | 60 | 'ensure' => 'link', 'target' => '/opt/graphite/conf/graphite_wsgi.py', 'require' => 'File[/opt/graphite/conf/graphite_wsgi.py]' }) }
|
| 61 | + it { is_expected.to contain_service('carbon-cache').only_with({ |
| 62 | + 'ensure' => 'running', |
| 63 | + 'enable' => 'true', |
| 64 | + 'hasrestart' => 'true', |
| 65 | + 'hasstatus' => 'true', |
| 66 | + 'provider' => nil, |
| 67 | + 'require' => 'File[/etc/init.d/carbon-cache]' }) } |
| 68 | + it { is_expected.to contain_file('/etc/init.d/carbon-cache').with({ |
| 69 | + 'ensure' => 'file', |
| 70 | + 'content' => /^GRAPHITE_DIR="\/opt\/graphite"$/, |
| 71 | + 'mode' => '0750', |
| 72 | + 'require' => 'File[/opt/graphite/conf/carbon.conf]', |
| 73 | + 'notify' => [] }) } |
| 74 | + end |
| 75 | + |
| 76 | + |
| 77 | + context 'Unsupported OS' do |
| 78 | + let(:facts) {{ :osfamily => 'unsupported', :operatingsystem => 'UnknownOS' }} |
| 79 | + it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )} |
70 | 80 | end
|
71 | 81 |
|
72 |
| - # Loop through various contexts |
73 |
| - [ { :osfamily => 'Debian', :lsbdistcodename => 'capybara', :operatingsystem => 'Debian' }, |
74 |
| - { :osfamily => 'Debian', :lsbdistcodename => 'squeeze', :operatingsystem => 'Debian' }, |
75 |
| - { :osfamily => 'Debian', :lsbdistcodename => 'trusty', :operatingsystem => 'Debian' }, |
76 |
| - { :osfamily => 'FreeBSD', :operatingsystemrelease => '8.4-RELEASE-p27', :operatingsystem => 'FreeBSD' }, |
77 |
| - { :osfamily => 'RedHat', :operatingsystemrelease => '5.0', :operatingsystem => 'CentOS' }, |
78 |
| - { :osfamily => 'RedHat', :operatingsystemrelease => '6.6', :operatingsystem => 'CentOS' }, |
79 |
| - { :osfamily => 'RedHat', :operatingsystemrelease => '7.1', :operatingsystem => 'CentOS' }, |
80 |
| - ].each do |myfacts| |
| 82 | + on_supported_os.each do |os, facts| |
| 83 | + context "on #{os}" do |
| 84 | + let(:facts) do |
| 85 | + facts |
| 86 | + end |
| 87 | + let :pre_condition do |
| 88 | + 'include ::graphite' |
| 89 | + end |
| 90 | + |
| 91 | + it { is_expected.to compile.with_all_deps } |
| 92 | + it { is_expected.to contain_class('graphite::params') } |
| 93 | + it { is_expected.to contain_exec('Initial django db creation') } |
| 94 | + it { is_expected.to contain_class('graphite::config_apache') } |
81 | 95 |
|
82 |
| - context 'OS %s %s' % myfacts.values do |
83 |
| - let :facts do myfacts end |
84 |
| - let :pre_condition do 'include ::graphite' end |
| 96 | + # cron check |
| 97 | + it { is_expected.to contain_file('/opt/graphite/bin/carbon-logrotate.sh').with({ |
| 98 | + 'ensure' => 'file', 'mode' => '0544', 'content' => /^CARBON_LOGS_PATH="\/opt\/graphite\/storage\/log"$/ }) } |
| 99 | + it { is_expected.to contain_cron('Rotate carbon logs').with({ |
| 100 | + 'command' => '/opt/graphite/bin/carbon-logrotate.sh', |
| 101 | + 'hour' => '3', |
| 102 | + 'minute' => '15', |
| 103 | + 'require' => 'File[/opt/graphite/bin/carbon-logrotate.sh]', |
| 104 | + 'user' => 'root',}) } |
85 | 105 |
|
86 |
| - case myfacts[:osfamily] |
| 106 | + case facts[:osfamily] |
87 | 107 | when 'Debian' then
|
88 |
| - case myfacts[:lsbdistcodename] |
89 |
| - when 'capybara' then |
90 |
| - it_behaves_like 'Debian unsupported platforms' |
91 |
| - else |
92 |
| - it_behaves_like 'supported platforms' |
93 |
| - it_behaves_like 'Debian supported platforms' |
94 |
| - |
95 |
| - end |
| 108 | + it_behaves_like 'Debian supported platforms' |
96 | 109 | when 'RedHat' then
|
97 |
| - case myfacts[:operatingsystemrelease] |
98 |
| - when /^[6-7]/ then |
99 |
| - it_behaves_like 'supported platforms' |
100 |
| - it_behaves_like 'RedHat supported platforms' |
101 |
| - case myfacts[:operatingsystemrelease] |
102 |
| - when /^6/ then |
103 |
| - it_behaves_like 'RedHat 6 platforms' |
104 |
| - when /^7/ then |
105 |
| - it_behaves_like 'RedHat 7 platforms' |
106 |
| - end |
107 |
| - |
| 110 | + it_behaves_like 'RedHat supported platforms' |
| 111 | + case facts[:operatingsystemrelease] |
| 112 | + when /^6/ then |
| 113 | + it_behaves_like 'RedHat 6 platforms' |
| 114 | + when /^7/ then |
| 115 | + it_behaves_like 'RedHat 7 platforms' |
108 | 116 | else
|
109 |
| - it_behaves_like 'RedHat unsupported platforms' |
| 117 | + it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )} |
110 | 118 | end
|
111 | 119 | else
|
112 |
| - it_behaves_like 'Unsupported OS' |
| 120 | + it { is_expected.to raise_error(Puppet::Error,/unsupported os,.+\./ )} |
113 | 121 | end
|
| 122 | + |
114 | 123 | end
|
115 | 124 | end
|
| 125 | + |
116 | 126 | end
|
0 commit comments