forked from projectatomic/atomic-host-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
196 lines (175 loc) · 7.43 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
---
# vim: set ft=ansible:
# set ft=ansible
#
- name: Package Layering - Test Suite
hosts: all
become: true
vars_files:
- vars.yml
vars:
tests: []
tasks:
- name: Set logging
set_fact:
log_results: true
result_file: "{{ playbook_dir }}/pkg-layering-result.log"
tags: setup
- include_tasks: 'setup.yml'
tags: setup
# TEST
# Verify installing and uninstalling a single package
- block:
- include_tasks: 'single_pkg_install_uninstall.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Single package install and uninstall', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Single package install and uninstall', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: single_pkg_install_uninstall
# TEST
# Verify installing and uninstalling multiple packages
- block:
- include_tasks: 'multi_pkg_install_uninstall.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Multiple package install and uninstall', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Multiple package install and uninstall', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: multi_pkg_install_uninstall
# TEST
# Verify installing using the reboot flag
- block:
- include_tasks: 'reboot_flag.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Reboot flag', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Reboot flag', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: reboot_flag
# TEST
# Verify installing with the dry run option
- block:
- include_tasks: 'dry_run.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Dry run', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Dry run', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: dry_run
# TEST
# Verify installing with dry run option does not install anything
- block:
- include_tasks: 'dry_run_interaction.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Dry run interaction', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Dry run interaction', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: dry_run_interaction
# TEST
# Verify installing a package from an alternate repo
- block:
- include_tasks: 'alternate_repo_install.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Alternate repo install', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Alternate repo install', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: alternate_repo_install
# TEST
# Verify installing with gpgcheck turned on and off
- block:
- include_tasks: 'gpg.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'GPG', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'GPG', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: gpg
# TEST
# Negative test - verify user cannot uninstall an invalid package
- block:
- include_tasks: 'uninstall_invalid_pkg.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Uninstall invalid package', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Uninstall invalid package', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: uninstall_invalid_pkg
# TEST
# Negative test - verify user cannot install an invalid package
- block:
- include_tasks: 'install_invalid_pkg.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Install invalid package', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Install invalid package', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: install_invalid_pkg
# TEST
# Negative test - verify user cannot install an existing package
- block:
- include_tasks: 'install_existing_pkg.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Install existing package', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Install existing package', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: install_existing_pkg
# TEST
# Verify installing a nonroot package
- block:
- include_tasks: 'install_nonroot_pkg.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Install nonroot package', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Install nonroot package', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: install_nonroot_pkg
# TEST
# Negative test - verify user cannot install a previously layered package
- block:
- include_tasks: 'install_previously_layered.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Install previously layered', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Install previously layered', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: install_previously_layered
# TEST
# Negative test - verify user cannot use package layering without sufficient permissions
- block:
- include_tasks: 'install_unprivileged.yml'
- set_fact:
tests: "{{ tests + [ { 'name':'Install unprivileged', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Install unprivileged', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
tags: install_unprivileged
# CLEANUP
- block:
- include_tasks: 'cleanup.yml'
- set_fact:
tests: "{{ tests + [ { 'name': 'Cleanup', 'result':'Passed', 'result_details': '' } ] }}"
rescue:
- set_fact:
tests: "{{ tests + [ { 'name':'Cleanup', 'result':'Failed', 'result_details': ansible_failed_result } ] }}"
always:
# WRITE RESULTS TO FILE
- name: Remove existing log files
local_action: file path={{ result_file }} state=absent
become: false
- name: Save result to file
when: log_results
local_action: copy content={{ tests | to_nice_yaml(indent=2) }} dest={{ result_file }}
become: false
tags: cleanup
# Handled exceptions show up as failures in Ansible but the playbook
# itself does not return 0, so explicitly fail the test by checking
# the test results
- name: Explicitly fail based on test results
when: item['result']|lower == "failed"
fail:
msg: "Failure found in test"
with_items: "{{ tests }}"