Skip to content

Commit c87cd40

Browse files
committed
add test for postStartScript
1 parent 3914151 commit c87cd40

File tree

2 files changed

+286
-1
lines changed

2 files changed

+286
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Advanced Feature: Make securityContext (on Deployments/Jobs) and podSecurityContext (on Pods) configurable. This allows dropping all capabilities, for example. You can override the securityContext for `st2actionrunner`, `st2sensorcontainer`, and `st2client` if your actions or sensors need, for example, additional capabilites that the rest of StackStorm does not need. (#271) (by @cognifloyd)
55
* Prefix template helpers with chart name and format helper comments as template comments. (#272) (by @cognifloyd)
66
* New feature: Add `extra_volumes` to all python-based st2 deployments. This can facilitate changing log levels by loading logging conf file(s) from a custom ConfigMap. (#276) (by @cognifloyd)
7-
* Initialize basic unittest infrastructure using `helm-unittest`. Added tests for labels, custom annotations, SecurityContext, pullSecrets, pullPolicy, Resources, nodeSelector, tolerations, affinity, dnsPolicy, dnsConfig, and ServiceAccount attach. (#284, #288)
7+
* Initialize basic unittest infrastructure using `helm-unittest`. Added tests for labels, custom annotations, SecurityContext, pullSecrets, pullPolicy, Resources, nodeSelector, tolerations, affinity, dnsPolicy, dnsConfig, ServiceAccount attach, and postStartScript. (#284, #288)
88

99
## v0.80.0
1010
* Switch st2 to `v3.6` as a new default stable version (#274)
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
---
2+
suite: postStart scripts
3+
templates:
4+
# primary template files
5+
- deployments.yaml
6+
- configmaps_post-start-script.yaml
7+
8+
# included templates must also be listed
9+
- configmaps_packs.yaml
10+
- configmaps_rbac.yaml
11+
- configmaps_st2-conf.yaml
12+
- configmaps_st2web.yaml
13+
- secrets_datastore_crypto_key.yaml
14+
- secrets_ssh.yaml
15+
- secrets_st2auth.yaml
16+
- secrets_st2chatops.yaml
17+
18+
# st2.packs.sensors.postStartScript is not valid
19+
# post start script on all deployments (not on jobs)
20+
# st2web.postStartScript
21+
# st2auth.postStartScript
22+
# st2api.postStartScript
23+
# st2stream.postStartScript
24+
# st2rulesengine.postStartScript
25+
# st2timersengine.postStartScript
26+
# st2workflowengine.postStartScript
27+
# st2scheduler.postStartScript
28+
# st2notifier.postStartScript
29+
# st2actionrunner.postStartScript
30+
# st2sensorcontainer.postStartScript
31+
# st2garbagecollector.postStartScript
32+
# st2client.postStartScript
33+
# st2chatops.postStartScript
34+
35+
tests:
36+
- it: post-start script for st2actionrunner and st2client
37+
template: configmaps_post-start-script.yaml
38+
set:
39+
st2:
40+
system_user:
41+
user: yelnats # stanley backwards for the test
42+
# ssh_key_file should be /home/yelnats/.ssh/stanley_rsa
43+
asserts:
44+
- hasDocuments:
45+
count: 2
46+
- isKind:
47+
of: ConfigMap
48+
- isAPIVersion:
49+
of: v1
50+
- isNotEmpty:
51+
path: data.[post-start.sh]
52+
- equal:
53+
path: data.[post-start.sh]
54+
value: |
55+
#!/bin/bash
56+
mkdir -p /home/yelnats/.ssh
57+
cp -L /home/yelnats/.ssh-key-vol/stanley_rsa /home/yelnats/.ssh/stanley_rsa
58+
chown -R yelnats:yelnats /home/yelnats/.ssh
59+
chmod 400 /home/yelnats/.ssh/stanley_rsa
60+
chmod 500 /home/yelnats/.ssh
61+
62+
- it: custom post-start script
63+
template: configmaps_post-start-script.yaml
64+
set:
65+
st2:
66+
packs: { sensors: [] } # ensure only 1 sensor
67+
st2web:
68+
postStartScript: &custom_post_start_script
69+
echo hello world
70+
st2auth:
71+
postStartScript: *custom_post_start_script
72+
st2api:
73+
postStartScript: *custom_post_start_script
74+
st2stream:
75+
postStartScript: *custom_post_start_script
76+
st2rulesengine:
77+
postStartScript: *custom_post_start_script
78+
st2timersengine:
79+
postStartScript: *custom_post_start_script
80+
st2workflowengine:
81+
postStartScript: *custom_post_start_script
82+
st2scheduler:
83+
postStartScript: *custom_post_start_script
84+
st2notifier:
85+
postStartScript: *custom_post_start_script
86+
st2actionrunner:
87+
postStartScript: *custom_post_start_script
88+
st2sensorcontainer:
89+
postStartScript: *custom_post_start_script
90+
st2garbagecollector:
91+
postStartScript: *custom_post_start_script
92+
st2client:
93+
postStartScript: *custom_post_start_script
94+
st2chatops:
95+
enabled: true
96+
postStartScript: *custom_post_start_script
97+
asserts:
98+
- hasDocuments:
99+
count: 14
100+
- isKind:
101+
of: ConfigMap
102+
- isAPIVersion:
103+
of: v1
104+
- isNotEmpty:
105+
path: data.[post-start.sh]
106+
- matchRegex:
107+
path: data.[post-start.sh]
108+
# Could also match the shebang at the begginning
109+
# but I'm not sure how to match more than one line.
110+
pattern: echo hello world
111+
112+
- it: Deployments st2actionrunner and st2client have lifecycle.postStartScipt by default
113+
template: deployments.yaml
114+
set:
115+
st2:
116+
packs: { sensors: [] } # ensure only 1 sensor
117+
st2chatops:
118+
enabled: true
119+
asserts:
120+
- hasDocuments:
121+
count: 14
122+
123+
# st2actionrunner and st2client do not have checksum annotations
124+
# (even though they probably should)
125+
- isNull: &assert_checksum
126+
path: spec.template.metadata.annotations.[checksum/post-start-script]
127+
128+
# only st2actionrunner and st2client have default postStart scripts
129+
- equal: &assert_lifecycle
130+
path: spec.template.spec.containers[0].lifecycle.postStart
131+
value:
132+
exec:
133+
command: ["/bin/bash", "/post-start.sh"]
134+
documentIndex: 10
135+
- equal: *assert_lifecycle
136+
documentIndex: 12
137+
138+
- isNull: &assert_null_lifecycle
139+
path: spec.template.spec.containers[0].lifecycle
140+
documentIndex: 0
141+
- isNull: *assert_null_lifecycle
142+
documentIndex: 1
143+
- isNull: *assert_null_lifecycle
144+
documentIndex: 2
145+
- isNull: *assert_null_lifecycle
146+
documentIndex: 3
147+
- isNull: *assert_null_lifecycle
148+
documentIndex: 4
149+
- isNull: *assert_null_lifecycle
150+
documentIndex: 5
151+
- isNull: *assert_null_lifecycle
152+
documentIndex: 6
153+
- isNull: *assert_null_lifecycle
154+
documentIndex: 7
155+
- isNull: *assert_null_lifecycle
156+
documentIndex: 8
157+
- isNull: *assert_null_lifecycle
158+
documentIndex: 9
159+
- isNull: *assert_null_lifecycle
160+
documentIndex: 11
161+
- isNull: *assert_null_lifecycle
162+
documentIndex: 13
163+
164+
- contains: &assert_volume_mount
165+
path: spec.template.spec.containers[0].volumeMounts
166+
content:
167+
name: st2-post-start-script-vol
168+
mountPath: /post-start.sh
169+
subPath: post-start.sh
170+
documentIndex: 10
171+
- contains: *assert_volume_mount
172+
documentIndex: 12
173+
174+
- notContains: *assert_volume_mount
175+
documentIndex: 0
176+
- notContains: *assert_volume_mount
177+
documentIndex: 1
178+
- notContains: *assert_volume_mount
179+
documentIndex: 2
180+
- notContains: *assert_volume_mount
181+
documentIndex: 4
182+
- notContains: *assert_volume_mount
183+
documentIndex: 5
184+
- notContains: *assert_volume_mount
185+
documentIndex: 6
186+
- notContains: *assert_volume_mount
187+
documentIndex: 7
188+
- notContains: *assert_volume_mount
189+
documentIndex: 8
190+
- notContains: *assert_volume_mount
191+
documentIndex: 9
192+
- notContains: *assert_volume_mount
193+
documentIndex: 11
194+
195+
# st2web and st2chatops have no volumes (and can be null)
196+
- isEmpty:
197+
path: spec.template.spec.containers[0].volumeMounts
198+
documentIndex: 3
199+
- isEmpty:
200+
path: spec.template.spec.containers[0].volumeMounts
201+
documentIndex: 13
202+
203+
- contains: &assert_volume
204+
path: spec.template.spec.volumes
205+
content:
206+
name: st2-post-start-script-vol
207+
# we cannot easily validate the generated ConfigMap name
208+
#configMap:
209+
# name: {{ .Release.Name }}-st2auth-post-start-script
210+
any: true
211+
documentIndex: 10
212+
- contains: *assert_volume
213+
documentIndex: 12
214+
215+
- notContains: *assert_volume
216+
documentIndex: 0
217+
- notContains: *assert_volume
218+
documentIndex: 1
219+
- notContains: *assert_volume
220+
documentIndex: 2
221+
- notContains: *assert_volume
222+
documentIndex: 4
223+
- notContains: *assert_volume
224+
documentIndex: 5
225+
- notContains: *assert_volume
226+
documentIndex: 6
227+
- notContains: *assert_volume
228+
documentIndex: 7
229+
- notContains: *assert_volume
230+
documentIndex: 8
231+
- notContains: *assert_volume
232+
documentIndex: 9
233+
- notContains: *assert_volume
234+
documentIndex: 11
235+
236+
- isEmpty:
237+
path: spec.template.spec.volumes
238+
documentIndex: 3
239+
- isEmpty:
240+
path: spec.template.spec.volumes
241+
documentIndex: 13
242+
243+
- it: Deployments accept custom lifecycle.postStartScipt
244+
template: deployments.yaml
245+
set:
246+
st2:
247+
packs: { sensors: [] } # ensure only 1 sensor
248+
st2web:
249+
postStartScript: *custom_post_start_script
250+
st2auth:
251+
postStartScript: *custom_post_start_script
252+
st2api:
253+
postStartScript: *custom_post_start_script
254+
st2stream:
255+
postStartScript: *custom_post_start_script
256+
st2rulesengine:
257+
postStartScript: *custom_post_start_script
258+
st2timersengine:
259+
postStartScript: *custom_post_start_script
260+
st2workflowengine:
261+
postStartScript: *custom_post_start_script
262+
st2scheduler:
263+
postStartScript: *custom_post_start_script
264+
st2notifier:
265+
postStartScript: *custom_post_start_script
266+
st2actionrunner:
267+
postStartScript: *custom_post_start_script
268+
st2sensorcontainer:
269+
postStartScript: *custom_post_start_script
270+
st2garbagecollector:
271+
postStartScript: *custom_post_start_script
272+
st2client:
273+
postStartScript: *custom_post_start_script
274+
st2chatops:
275+
enabled: true
276+
postStartScript: *custom_post_start_script
277+
asserts:
278+
- hasDocuments:
279+
count: 14
280+
281+
- isNotEmpty: *assert_checksum
282+
- equal: *assert_lifecycle
283+
- contains: *assert_volume_mount
284+
- contains: *assert_volume
285+

0 commit comments

Comments
 (0)