-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
startup_spec.rb
189 lines (164 loc) · 6.17 KB
/
startup_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# frozen_string_literal: true
require 'spec_helper'
describe 'zabbix::startup', type: :define do # rubocop:disable RSpec/MultipleDescribes
let(:title) { 'zabbix-agent' }
let :pre_condition do
'service{"zabbix-agent":}'
end
on_supported_os.each do |os, os_facts|
context "on #{os}" do
context 'on legacy init systems' do
['false', false].each do |systemd_fact_state|
let :facts do
os_facts.merge({ systemd: systemd_fact_state })
end
context 'it works' do
let :params do
{
agent_configfile_path: '/something'
}
end
case os_facts[:os]['family']
when 'Debian'
it do
is_expected.to contain_file('/etc/init.d/zabbix-agent').with(
ensure: 'file',
content: %r{DAEMON_OPTS="-c /something"}
)
end
when 'RedHat'
it do
is_expected.to contain_file('/etc/init.d/zabbix-agent').with(
ensure: 'file',
content: %r{OPTS="/something"}
)
end
when 'windows'
it { is_expected.to have_exec_resource_count(1) }
it { is_expected.to contain_exec('install_agent_zabbix-agent') }
else
it { is_expected.not_to compile.with_all_deps }
next
end
it { is_expected.not_to contain_class('systemd') }
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-agent.service') }
end
end
end
next if os_facts[:os]['family'] == 'windows'
context "#{os} on systemd" do
['true', true].each do |systemd_fact_state|
let :facts do
os_facts.merge({ systemd: systemd_fact_state })
end
context 'it works' do
let :params do
{
agent_configfile_path: '/something',
pidfile: '/somethingelse',
additional_service_params: '--foreground'
}
end
it { is_expected.to contain_class('systemd') }
it { is_expected.to contain_systemd__unit_file('zabbix-agent.service') }
it { is_expected.to contain_file('/etc/init.d/zabbix-agent').with_ensure('absent') }
it do
is_expected.to contain_file('/etc/systemd/system/zabbix-agent.service').with(
ensure: 'file',
mode: '0444'
)
end
it { is_expected.to contain_file('/etc/systemd/system/zabbix-agent.service').with_content(%r{ExecStart=/usr/sbin/zabbix_agentd --foreground -c /something}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-agent.service').with_content(%r{PIDFile=/somethingelse}) }
end
end
end
end
end
end
describe 'zabbix::startup', type: :define do
let(:title) { 'zabbix-server' }
on_supported_os.each do |os, os_facts|
context "on #{os}" do
context 'on legacy init systems' do
['false', false].each do |systemd_fact_state|
let :facts do
os_facts.merge({ systemd: systemd_fact_state })
end
context 'it works' do
let :params do
{
server_configfile_path: '/something',
database_type: 'mysql',
manage_database: true
}
end
case os_facts[:os]['family']
when 'Debian'
it do
is_expected.to contain_file('/etc/init.d/zabbix-server').with(
ensure: 'file',
content: %r{DAEMON_OPTS="-c /something"}
)
end
when 'RedHat'
it do
is_expected.to contain_file('/etc/init.d/zabbix-server').with(
ensure: 'file',
content: %r{OPTS="/something"}
)
end
else
it { is_expected.not_to compile.with_all_deps }
next
end
it { is_expected.not_to contain_class('systemd') }
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-server.service') }
end
end
end
end
next if os_facts[:os]['family'] == 'windows'
context 'on systemd' do
['true', true].each do |systemd_fact_state|
let :facts do
os_facts.merge({ systemd: systemd_fact_state })
end
context 'it works on mysql' do
let :params do
{
server_configfile_path: '/something',
pidfile: '/somethingelse',
database_type: 'mysql',
additional_service_params: '--foreground',
manage_database: true
}
end
it { is_expected.to contain_class('systemd') }
it { is_expected.to contain_systemd__unit_file('zabbix-server.service') }
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') }
it do
is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with(
ensure: 'file',
mode: '0444'
)
end
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{ExecStart=/usr/sbin/zabbix_server --foreground -c /something}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{PIDFile=/somethingelse}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=mysqld.service}) }
context 'and works on postgres' do
let :params do
{
server_configfile_path: '/something',
pidfile: '/somethingelse',
database_type: 'postgresql',
manage_database: true
}
end
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=postgresql.service}) }
end
end
end
end
end
end