-
-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathmanage_dropin_spec.rb
265 lines (228 loc) · 7.69 KB
/
manage_dropin_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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# frozen_string_literal: true
require 'spec_helper'
describe 'systemd::manage_dropin' do
context 'supported operating systems' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) { facts }
let(:title) { 'foobar.conf' }
context 'on a service' do
let(:params) do
{
unit: 'special.service',
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__dropin_file('foobar.conf').with_content(%r{^# Deployed with puppet$}) }
context 'with empty sections' do
let(:params) do
super().merge(
unit_entry: {},
service_entry: {}
)
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^\[Unit\]$}).
with_content(%r{^\[Service\]$}).
without_content(%r{^\[Slice\]$})
}
end
context 'setting some parameters simply' do
let(:params) do
super().merge(
unit_entry: {
DefaultDependencies: true
},
service_entry: {
SyslogIdentifier: 'simple',
LimitCORE: 'infinity',
IODeviceWeight:
[
['/dev/weight', 10],
['/dev/weight2', 20],
],
IOReadBandwidthMax: ['/dev/weight3', '50K'],
}
)
end
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^LimitCORE=infinity$}).
with_content(%r{^DefaultDependencies=true$}).
with_content(%r{^SyslogIdentifier=simple$}).
with_content(%r{^IODeviceWeight=/dev/weight 10$}).
with_content(%r{^IODeviceWeight=/dev/weight2 20$}).
with_content(%r{^IOReadBandwidthMax=/dev/weight3 50K$}).
without_content(%r{^\[Slice\]$})
}
end
context 'drop file chaning Type and resetting ExecStart' do
let(:params) do
super().merge(
service_entry: {
Type: 'oneshot',
ExecStart: ['', '/usr/bin/doit.sh'],
}
)
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^\[Service\]$}).
without_content(%r{^\[Unit\]$}).
without_content(%r{^\[Install\]$}).
with_content(%r{^ExecStart=$}).
with_content(%r{^ExecStart=/usr/bin/doit.sh$}).
with_content(%r{^Type=oneshot$})
}
end
context 'with an instance to instance relation' do
let(:params) do
super().merge(
unit_entry: {
'After' => ['user-runtime-dir@%i.service'],
'Requires' => ['user-runtime-dir@%i.service'],
}
)
end
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^After=user-runtime-dir@%i.service$}).
with_content(%r{^Requires=user-runtime-dir@%i.service$})
}
end
context 'with a timer entry' do
let(:params) do
super().merge(
timer_entry: {
'OnCalendar' => 'soon',
}
)
end
it { is_expected.to compile.and_raise_error(%r{timer_entry is only valid for timer units}) }
end
context 'with a slice entry' do
let(:params) do
super().merge(
slice_entry: {
'MemoryMax' => '100G',
}
)
end
it { is_expected.to compile.and_raise_error(%r{slice_entry is only valid for slice units}) }
end
end
context 'on a swap unit' do
let(:params) do
{
unit: 'file.swap',
swap_entry: {
'Priority' => 10,
}
}
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_unit('file.swap').
with_content(%r{^\[Swap\]$}).
with_content(%r{^Priority=10$})
}
end
context 'on a timer' do
let(:params) do
{
unit: 'special.timer',
timer_entry: {
'OnCalendar' => 'soon',
}
}
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_unit('special.timer').
with_content(%r{^OnCalendar=soon$})
}
end
context 'on a mount' do
let(:params) do
{
unit: 'var-lib-sss-db.mount',
mount_entry: {
'SloppyOptions' => true,
}
}
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_unit('var-lib-sss-db.mount').
with_content(%r{^SloppyOptions=true$})
}
end
context 'on a slice' do
let(:params) do
{
unit: 'user-.slice',
slice_entry: {
'MemoryMax' => '10G',
'MemoryAccounting' => true,
'IOWriteBandwidthMax' => [
['/dev/afs', '50P'],
['/dev/gluster', 50],
]
}
}
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_unit('user-.slice').
with_content(%r{^IOWriteBandwidthMax=/dev/afs 50P$}).
with_content(%r{^IOWriteBandwidthMax=/dev/gluster 50$}).
with_content(%r{^MemoryMax=10G$}).
with_content(%r{^MemoryAccounting=true$}).
without_content(%r{^\[Service\]$})
}
end
context 'on a path unit' do
let(:params) do
{
unit: 'special.path',
path_entry: {
'PathExists' => '/etc/hosts',
}
}
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_unit('special.path').
with_content(%r{^\[Path\]$}).
with_content(%r{^PathExists=/etc/hosts$})
}
end
context 'on a socket unit' do
let(:params) do
{
unit: 'special.socket',
socket_entry: {
'ListenMessageQueue' => '/panic',
}
}
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_unit('special.socket').
with_content(%r{^\[Socket\]$}).
with_content(%r{^ListenMessageQueue=/panic$})
}
end
end
end
end
end