forked from projectatomic/atomic-host-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.yml
614 lines (484 loc) · 16.3 KB
/
main.yml
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
---
# vim: set ft=ansible:
#
# !!!NOTE!!! This playbook was tested using Ansible 2.2; it is recommended
# that the same version is used.
#
# Test Cases
# Core Functionality
# - Verify system containers can be installed through atomic command
# - Verify system containers can be uninstalled through the atomic command
# - Verify user can specify name for system containers
# - Verify system containers can be listed
# - Verify environment variables can be pass to the container
# - Verify update/rollback of system containers
# - Verify commands can be run in the system container
# - Verify specification of rootfs for system containers.
# - Verify setting RUN_DIRECTORY and STATE_DIRECTORY
# - Verify system containers are started on reboot
# - Verify system containers persist through reboot
#
# Flannel & Etcd Tests
# - Verify installation of flannel and etcd containers
#
# Negative Testing
# - Verify uninstalling a system container that does not exist fails
# - Verify installing a system container that does not exist fails
# - Verify DESTDIR, NAME, EXEC_START, EXEC_STOP, HOST_UID, and HOST_GID
# cannot be set
#
# Not Covered
# Upgrade Tests
# - Verify the system container persists through ostree upgrade
# - Verify the system container persists through ostree rollback
#
- name: System Containers - Setup
hosts: all
become: yes
tags:
- setup
vars_files:
- vars.yml
pre_tasks:
- name: Set facts
set_fact:
etcd_image: 'registry.access.redhat.com/rhel7/etcd'
etcd_name: 'etcd'
flannel_image: 'registry.access.redhat.com/rhel7/flannel'
flannel_name: 'flannel'
when: ansible_distribution == 'RedHat'
- name: Set facts
set_fact:
etcd_image: 'registry.fedoraproject.org/f25/etcd'
etcd_name: 'etcd'
flannel_image: 'registry.fedoraproject.org/f25/flannel'
flannel_name: 'flannel'
when: ansible_distribution != 'RedHat'
roles:
# This playbook requires Ansible 2.2 and an Atomic Host
- role: ansible_version_check
avc_major: "2"
avc_minor: "2"
tags:
- ansible_version_check
# Subscribe if the system is RHEL
- role: redhat_subscription
when: ansible_distribution == 'RedHat'
tags:
- redhat_subscription
- name: System Containers - Install/Uninstall
hosts: all
become: yes
# - Verify system containers can be installed through atomic command
# - Verify system containers can be uninstalled through the atomic command
# - Verify user can specify name for system containers
# - Verify system containers can be listed
tags:
- install_uninstall
vars_files:
- vars.yml
roles:
- role: atomic_system_install
image: "{{ g_hw_image }}"
- role: atomic_system_install_verify
image: "{{ g_hw_image }}"
- role: atomic_system_uninstall
name: "{{ g_hw_name }}"
# uninstall can only be done by name because multiple system containers can
# use the same image https://github.com/projectatomic/atomic/issues/705
- role: atomic_system_uninstall_verify
image: "{{ g_hw_image }}"
- name: System Containers - Reboot
hosts: all
become: yes
tags:
- reboot
vars_files:
- vars.yml
tasks:
- name: Install system container and pass in variables
command: >
atomic install
--system
--name={{ g_hw_name }}
--set=PORT=8080
--set=RECEIVER=foo
{{ g_hw_image }}
- name: Start hello-world service
command: systemctl start {{ g_hw_name }}
- include: 'roles/atomic_system_install_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8080
register: c_output
- name: Fail if output is incorrect
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi foo' not in c_output.stdout"
- include: ../../common/ans_reboot.yml
- name: Verify {{ g_hw_name }} service is active
command: systemctl is-active {{ g_hw_name }}
register: hw_output
failed_when: "'active' not in hw_output.stdout"
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8080
register: c_output
- name: Fail if output is incorrect
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi foo' not in c_output.stdout"
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ g_hw_name }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: System Containers - Pass Variables
hosts: all
become: yes
# - Verify environment variables can be pass to the container
tags:
- pass_variables
vars_files:
- vars.yml
tasks:
- name: Install system container and pass in variables
command: >
atomic install
--system
--name={{ g_hw_name }}
--set=PORT=8080
--set=RECEIVER=foo
{{ g_hw_image }}
- name: Start hello-world service
command: systemctl start {{ g_hw_name }}
- include: 'roles/atomic_system_install_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8080
register: c_output
- name: Fail if output is incorrect
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi foo' not in c_output.stdout"
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ g_hw_name }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: System Containers - Update/Rollback
hosts: all
become: yes
# - Verify update/rollback of system containers
tags:
- update_rollback
vars_files:
- vars.yml
tasks:
- name: Install system container and pass in variables
command: >
atomic install
--system
--name={{ g_hw_name }}
--set=PORT=8080
--set=RECEIVER=foo
{{ g_hw_image }}
- name: Start hello-world service
command: systemctl start {{ g_hw_name }}
- include: 'roles/atomic_system_install_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8080
register: c_output
- name: Fail if Hi foo is not in output
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi foo' not in c_output.stdout"
- name: Update system container
command: atomic containers update --set=RECEIVER=bar {{ g_hw_name }}
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8080
register: c_output
- name: Fail if Hi bar is not in output
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi bar' not in c_output.stdout"
- name: Rollback system container
command: atomic containers rollback {{ g_hw_name }}
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8080
register: c_output
- name: Fail if Hi foo is not in output
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi foo' not in c_output.stdout"
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ g_hw_name }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: System Containers - Rootfs
hosts: all
become: yes
# - Verify specification of rootfs for system containers.
tags:
- rootfs
vars_files:
- vars.yml
tasks:
- name: Install system container and pass in variables
command: >
atomic install
--system
--name={{ g_hw_name }}
--set=PORT=8080
--set=RECEIVER=foo
{{ g_hw_image }}
- name: Start {{ g_hw_name }} service
command: systemctl start {{ g_hw_name }}
- include: 'roles/atomic_system_install_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8080
register: c_output
- name: Fail if Hi foo is not in output
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi foo' not in c_output.stdout"
- name: Create another container using the first container as the rootfs
command: atomic install
--system
--name={{ g_hw_name }}-remote
--rootfs=/var/lib/containers/atomic/{{ g_hw_name }}
--set=RECEIVER=remote
--set=PORT=8083
{{ g_hw_image }}
- name: Start the {{ g_hw_name }}-remote service
command: systemctl start {{ g_hw_name }}-remote
- name: Verify system container is running with the parameters passed in
command: curl http://localhost:8083
register: c_output
- name: Fail if Hi remote is not in output
fail:
msg: "Parameters were not correctly passed in"
when: "'Hi remote' not in c_output.stdout"
- name: Verify first container has rootfs
stat:
path: /var/lib/containers/atomic/{{ g_hw_name }}/rootfs
register: hw
- name: Verify first container has rootfs
stat:
path: /var/lib/containers/atomic/{{ g_hw_name }}-remote/rootfs
register: hwr
- name: Fail when rootfs dir is missing from main container
fail:
msg: "/var/lib/containers/atomic/{{ g_hw_name }}/rootfs does not exist"
when: hw.stat.exists == False
- name: Fail when rootfs dir exists for rootfs container
fail:
msg: "/var/lib/containers/atomic/{{ g_hw_name }}-remote/rootfs exists"
when: hwr.stat.exists != True
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ g_hw_name }}-remote"
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ g_hw_name }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ g_hw_name }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ g_hw_name }}-remote"
- name: System Containers - Flannel & Etcd
hosts: all
become: yes
# Flannel & Etcd Tests
tags:
- flannel_etcd
vars_files:
- vars.yml
tasks:
- name: Check for etcd rpm
command: rpm -q etcd
register: rpm_etcd
ignore_errors: true
- name: Check for flannel rpm
command: rpm -q flannel
register: rpm_flannel
ignore_errors: true
- name: Stop flanneld server if flannel rpm present
service:
name: flanneld
state: stopped
enabled: no
when: rpm_flannel.rc == 0
- name: Stop etcd service if etcd rpm present
service:
name: etcd
state: stopped
enabled: no
when: rpm_etcd.rc == 0
- name: Install etcd
command: >
atomic install
--system
--name=etcd
{{ etcd_image }}
register: ai_etcd
retries: 5
delay: 60
until: ai_etcd|success
- name: Start etcd
command: systemctl start etcd
- name: Verify etcd is active
command: systemctl is-active etcd
register: etcd_output
failed_when: "'active' not in etcd_output.stdout"
- name: Wait for etcd port to open
wait_for:
port: 2379
timeout: 30
- name: Configure etcd
command: >
runc exec etcd etcdctl
set /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
- name: Install flannel
command:
atomic install
--system
--name=flannel
{{ flannel_image }}
register: ai_flannel
retries: 5
delay: 60
until: ai_flannel|success
- name: Start flannel
command: systemctl start flannel
- name: Verify flannel service is active
command: systemctl is-active flannel
register: flannel_output
failed_when: "'active' not in flannel_output.stdout"
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ etcd_name }}"
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ flannel_name }}"
# Upstream issue with flannel container installation stopping docker
# https://github.com/projectatomic/atomic-system-containers/issues/23
- name: Start docker
command: systemctl start docker
when: "'gscrivano' in etcd_image"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ etcd_image }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ flannel_image }}"
- name: System Containers - Set RUN_DIRECTORY & STATE_DIRECTORY
hosts: all
become: yes
# - Verify setting RUN_DIRECTORY and STATE_DIRECTORY
tags:
- run_state_dir
vars_files:
- vars.yml
tasks:
- name: Set facts
set_fact:
run_dir: '/root'
state_dir: '/root'
- name: Create container with RUN_DIRECTORY and STATE_DIRECTORY
command: >
atomic install
--system
--set=RUN_DIRECTORY={{ run_dir }}
--set=STATE_DIRECTORY={{ state_dir }}
{{ g_hw_image }}
- name: Get output of {{ g_hw_name }} info file
command: cat /var/lib/containers/atomic/{{ g_hw_name }}/info
register: info_output
- name: Convert output to JSON
set_fact:
info_json: "{{ info_output.stdout|from_json }}"
- name: Verify RUN_DIRECTORY is set
fail:
msg: "RUN_DIRECTORY is not set to {{ run_dir }}"
when: run_dir not in info_json['values']['RUN_DIRECTORY']
- name: Verify STATE_DIRECTORY is set
fail:
msg: "STATE_DIRECTORY is not set to {{ state_dir }}"
when: state_dir not in info_json['values']['STATE_DIRECTORY']
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ g_hw_name }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: System Containers - Negative Testing
hosts: all
become: yes
# Negative Testing
# - Verify uninstalling a system container that does not exist fails
# - Verify installing a system container that does not exist fails
# - Verify DESTDIR, NAME, EXEC_START, EXEC_STOP, HOST_UID, and HOST_GID
# cannot be set
tags:
- negative
vars_files:
- vars.yml
tasks:
- name: Uninstall system container that does not exist
command: atomic uninstall foobar
register: auf_output
failed_when: auf_output.rc == 0
- name: Install a system container that does not exist
command: atomic install xxfoobarxx
register: aif_output
failed_when: aif_output.rc == 0
- name: Create container with DESTDIR, NAME, EXEC_START, EXEC_STOP, HOST_UID, HOST_GID
command: >
atomic install
--system
--set=DESTDIR={{ g_invalid_value }}
--set=NAME={{ g_invalid_value }}
--set=EXEC_START={{ g_invalid_value }}
--set=EXEC_STOP={{ g_invalid_value }}
--set=HOST_UID={{ g_invalid_value }}
--set=HOST_GID={{ g_invalid_value }}
{{ g_hw_image }}
- name: Get output of {{ g_hw_name }} info file
command: cat /var/lib/containers/atomic/{{ g_hw_name }}/info
register: info_output
- name: Fail if {{ g_invalid_value }} in output
fail:
msg: "Able to set DESTDIR, NAME, EXEC_START, EXEC_STOP, HOST_UID, or HOST_GID"
when: g_invalid_value in info_output.stdout
- include: 'roles/atomic_system_uninstall/tasks/main.yml'
vars:
name: "{{ g_hw_name }}"
- include: 'roles/atomic_system_uninstall_verify/tasks/main.yml'
vars:
image: "{{ g_hw_image }}"
- name: System Containers - Cleanup
hosts: all
become: yes
tags:
- cleanup
vars_files:
- vars.yml
roles:
- role: atomic_images_delete_all
tags:
- atomic_images_delete_all
- role: redhat_unsubscribe
when: ansible_distribution == 'RedHat'
tags:
- redhat_unsubscribe