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
|
# ============================================================
- name: Test rax_cbs_attachments with no args
rax_cbs_attachments:
ignore_errors: true
register: rax_cbs_attachments
- name: Validate results of rax_cbs_attachments with no args
assert:
that:
- rax_cbs_attachments|failed
- 'rax_cbs_attachments.msg == "missing required arguments: server,volume,device"'
# ============================================================
# ============================================================
- name: Test rax_cbs_attachments with server, volume and device
rax_cbs_attachments:
server: '1234'
volume: '1234'
device: /dev/xvde
ignore_errors: true
register: rax_cbs_attachments
- name: Validate results of rax_cbs_attachments with server, volume and device
assert:
that:
- rax_cbs_attachments|failed
- rax_cbs_attachments.msg == 'No credentials supplied!'
# ============================================================
# ============================================================
- name: Test rax_cbs_attachments with credentials, server, volume and device
rax_cbs_attachments:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
server: '1234'
volume: '1234'
device: /dev/xvde
ignore_errors: true
register: rax_cbs_attachments
- name: Validate results of rax_cbs_attachments with credentials, server, volume and device
assert:
that:
- rax_cbs_attachments|failed
- rax_cbs_attachments.msg.startswith('None is not a valid region')
# ============================================================
# ============================================================
- name: Test rax_cbs_attachments with creds, region, invalid server, invalid volume and device
rax_cbs_attachments:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
server: '1234'
volume: '1234'
device: /dev/xvde
ignore_errors: true
register: rax_cbs_attachments
- name: Validate rax_cbs_attachments creds, region, invalid server, invalid volume and device
assert:
that:
- rax_cbs_attachments|failed
- rax_cbs_attachments.msg == 'No matching storage volumes were found'
# ============================================================
# ============================================================
- name: Build Volume for rax_cbs_attachments test
rax_cbs:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ resource_prefix }}-rax_cbs_attachments"
wait: true
wait_timeout: "{{ rackspace_wait_timeout }}"
register: rax_cbs
- name: Validate volume build
assert:
that:
- rax_cbs|success
- rax_cbs|changed
- rax_cbs.volume.display_name == "{{ resource_prefix }}-rax_cbs_attachments"
# ============================================================
# ============================================================
- name: Build CloudServer for rax_cbs_attachments tests
rax:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
image: "{{ rackspace_image_id }}"
flavor: "{{ rackspace_flavor }}"
name: "{{ resource_prefix }}-rax_cbs_attachments"
wait: true
wait_timeout: "{{ rackspace_wait_timeout }}"
register: rax
- name: Validate CloudServer build
assert:
that:
- rax|success
- rax|changed
- rax.action == 'create'
- rax.instances|length == 1
- rax.instances[0].name == "{{ resource_prefix }}-rax_cbs_attachments"
# ============================================================
# ============================================================
- name: Test rax_cbs_attachments with creds, region, invalid server, volume and device
rax_cbs_attachments:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
server: '1234'
volume: "{{ rax_cbs.volume.id }}"
device: /dev/xvde
ignore_errors: true
register: rax_cbs_attachments
- name: Validate rax_cbs_attachments creds, region, invalid server, volume and device
assert:
that:
- rax_cbs_attachments|failed
- rax_cbs_attachments.msg == 'No Server was matched by name, try using the Server ID instead'
# ============================================================
# ============================================================
- name: Test rax_cbs_attachments with creds, region, server, volume and device (valid)
rax_cbs_attachments:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
server: "{{ rax.instances[0].id }}"
volume: "{{ rax_cbs.volume.id }}"
device: /dev/xvde
wait: true
wait_timeout: "{{ rackspace_wait_timeout }}"
register: rax_cbs_attachments
- name: Validate rax_cbs_attachments creds, region, server, volume and device (valid)
assert:
that:
- rax_cbs_attachments|success
- rax_cbs_attachments|changed
- rax_cbs_attachments.volume.attachments.0.device == '/dev/xvde'
- rax_cbs_attachments.volume.attachments.0.server_id == "{{ rax.instances[0].id }}"
- name: Idempotent present test
rax_cbs_attachments:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
server: "{{ rax.instances[0].id }}"
volume: "{{ rax_cbs.volume.id }}"
device: /dev/xvde
wait: true
wait_timeout: "{{ rackspace_wait_timeout }}"
register: rax_cbs_attachments
- name: Validate idempotent present test
assert:
that:
- rax_cbs_attachments|success
- not rax_cbs_attachments|changed
- name: Unattach volume
rax_cbs_attachments:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
server: "{{ rax.instances[0].id }}"
volume: "{{ rax_cbs.volume.id }}"
device: /dev/xvde
wait: true
wait_timeout: "{{ rackspace_wait_timeout }}"
state: absent
register: rax_cbs_attachments
- name: Validate unattach volume
assert:
that:
- rax_cbs_attachments|success
- rax_cbs_attachments|changed
- rax_cbs_attachments.volume.attachments == []
- name: Idempotent absent test
rax_cbs_attachments:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
server: "{{ rax.instances[0].id }}"
volume: "{{ rax_cbs.volume.id }}"
device: /dev/xvde
wait: true
wait_timeout: "{{ rackspace_wait_timeout }}"
state: absent
register: rax_cbs_attachments
- name: Validate idempotent absent test
assert:
that:
- rax_cbs_attachments|success
- not rax_cbs_attachments|changed
# ============================================================
# ============================================================
- name: Delete test volume
rax_cbs:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
name: "{{ rax_cbs.volume.id }}"
state: absent
register: rax_cbs
- name: Validate delete integration 6
assert:
that:
- rax_cbs|success
- rax_cbs|changed
# ============================================================
# ============================================================
- name: "Delete CloudServer"
rax:
username: "{{ rackspace_username }}"
api_key: "{{ rackspace_api_key }}"
region: "{{ rackspace_region }}"
instance_ids: "{{ rax.instances[0].id }}"
state: absent
wait: true
wait_timeout: "{{ rackspace_wait_timeout }}"
register: rax
- name: "Validate delete"
assert:
that:
- rax|changed
- rax|success
- rax.action == 'delete'
# ============================================================
|