Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/one_host/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # test code for the one_host module
8 # Copyright (c) Ansible Project
9 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
10 # SPDX-License-Identifier: GPL-3.0-or-later
11
12 # ENVIRONMENT PREPARACTION
13
14 - set_fact: test_number= 0
15
16 - name: "test_{{test_number}}: copy fixtures to test host"
17 copy:
18 src: testhost/tmp/opennebula-fixtures.json.gz
19 dest: /tmp
20 when:
21 - opennebula_test_fixture
22 - opennebula_test_fixture_replay
23
24
25 # SETUP INITIAL TESTING CONDITION
26
27 - set_fact: test_number={{ test_number | int + 1 }}
28
29 - name: "test_{{test_number}}: ensure the tests hosts are absent"
30 one_host:
31 name: "{{ item }}"
32 state: absent
33 api_endpoint: "{{ opennebula_url }}"
34 api_username: "{{ opennebula_username }}"
35 api_token: "{{ opennebula_password }}"
36 validate_certs: false
37 environment:
38 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
39 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
40 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
41 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
42 with_items: "{{opennebula_test.hosts}}"
43 register: result
44
45 # NOT EXISTING HOSTS
46
47 - set_fact: test_number={{ test_number | int + 1 }}
48
49 - name: "test_{{test_number}}: attempt to enable a host that does not exists"
50 one_host:
51 name: badhost
52 state: "{{item}}"
53 api_url: "{{ opennebula_url }}"
54 api_username: "{{ opennebula_username }}"
55 api_password: "{{ opennebula_password }}"
56 validate_certs: false
57 environment:
58 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
59 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
60 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
61 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{item}}"
62 ignore_errors: true
63 register: result
64 with_items:
65 - enabled
66 - disabled
67 - offline
68
69 - name: "assert test_{{test_number}} failed"
70 assert:
71 that:
72 - result is failed
73 - result.results[0].msg == 'invalid host state ERROR'
74
75 # ---
76
77 - set_fact: test_number={{ test_number | int + 1 }}
78
79 - name: "test_{{test_number}}: delete an unexisting host"
80 one_host:
81 name: badhost
82 state: absent
83 validate_certs: false
84 environment:
85 ONE_URL: "{{ opennebula_url }}"
86 ONE_USERNAME: "{{ opennebula_username }}"
87 ONE_PASSWORD: "{{ opennebula_password }}"
88 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
89 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
90 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
91 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}"
92 register: result
93
94 - name: "assert test_{{test_number}} worked"
95 assert:
96 that:
97 - result.changed
98
99 # HOST ENABLEMENT
100
101 - set_fact: test_number={{ test_number | int + 1 }}
102
103
104 - name: "test_{{test_number}}: enable the test hosts"
105 one_host:
106 name: "{{ item }}"
107 state: enabled
108 api_url: "{{ opennebula_url }}"
109 api_username: "{{ opennebula_username }}"
110 api_password: "{{ opennebula_password }}"
111 validate_certs: false
112 environment:
113 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
114 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
115 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
116 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
117 with_items: "{{opennebula_test.hosts}}"
118 register: result
119
120 - name: "assert test_{{test_number}} worked"
121 assert:
122 that:
123 - result.changed
124
125 # TEMPLATE MANAGEMENT
126
127 - set_fact: test_number={{ test_number | int + 1 }}
128
129 - name: "test_{{test_number}}: setup template values on hosts"
130 one_host:
131 name: "{{ item }}"
132 state: enabled
133 api_url: "{{ opennebula_url }}"
134 api_username: "{{ opennebula_username }}"
135 api_password: "{{ opennebula_password }}"
136 validate_certs: false
137 template:
138 LABELS:
139 - test
140 - custom
141 TEST_VALUE: 2
142 environment:
143 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
144 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
145 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
146 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
147 with_items: "{{opennebula_test.hosts}}"
148 register: result
149
150 - name: "assert test_{{test_number}} worked"
151 assert:
152 that:
153 - result.changed
154
155 # ---
156
157 - set_fact: test_number={{ test_number | int + 1 }}
158
159 - name: "test_{{test_number}}: setup equivalent template values on hosts"
160 one_host:
161 name: "{{ item }}"
162 state: enabled
163 api_url: "{{ opennebula_url }}"
164 api_username: "{{ opennebula_username }}"
165 api_password: "{{ opennebula_password }}"
166 validate_certs: false
167 labels:
168 - test
169 - custom
170 attributes:
171 TEST_VALUE: "2"
172 environment:
173 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
174 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
175 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
176 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
177 with_items: "{{opennebula_test.hosts}}"
178 register: result
179
180 - name: "assert test_{{test_number}} worked"
181 assert:
182 that:
183 - result is not changed
184
185 # HOST DISABLEMENT
186
187 - set_fact: test_number={{ test_number | int + 1 }}
188
189 - name: "test_{{test_number}}: disable the test hosts"
190 one_host:
191 name: "{{ item }}"
192 state: disabled
193 api_url: "{{ opennebula_url }}"
194 api_username: "{{ opennebula_username }}"
195 api_password: "{{ opennebula_password }}"
196 validate_certs: false
197 environment:
198 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
199 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
200 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
201 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
202 with_items: "{{opennebula_test.hosts}}"
203 register: result
204
205 - name: "assert test_{{test_number}} worked"
206 assert:
207 that:
208 - result.changed
209
210 # HOST OFFLINE
211
212 - set_fact: test_number={{ test_number | int + 1 }}
213
214 - name: "test_{{test_number}}: offline the test hosts"
215 one_host:
216 name: "{{ item }}"
217 state: offline
218 api_url: "{{ opennebula_url }}"
219 api_username: "{{ opennebula_username }}"
220 api_password: "{{ opennebula_password }}"
221 validate_certs: false
222 environment:
223 PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
224 PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
225 PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
226 PYONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
227 with_items: "{{opennebula_test.hosts}}"
228 register: result
229
230 - name: "assert test_{{test_number}} worked"
231 assert:
232 that:
233 - result.changed
234
235 # TEARDOWN
236
237 - name: fetch fixtures
238 fetch:
239 src: /tmp/opennebula-fixtures.json.gz
240 dest: targets/one_host/files
241 when:
242 - opennebula_test_fixture
243 - not opennebula_test_fixture_replay