1---
2- name: setup
3  cs_volume: name={{ cs_resource_prefix }}_vol state=absent
4  register: vol
5- name: verify setup
6  assert:
7    that:
8    - vol is successful
9
10- name: setup instance 1
11  cs_instance:
12    name: "{{ test_cs_instance_1 }}"
13    template: "{{ test_cs_instance_template }}"
14    service_offering: "{{ test_cs_instance_offering_1 }}"
15  register: instance
16- name: verify create instance
17  assert:
18    that:
19    - instance is successful
20
21- name: setup instance 2
22  cs_instance:
23    name: "{{ test_cs_instance_2 }}"
24    template: "{{ test_cs_instance_template }}"
25    service_offering: "{{ test_cs_instance_offering_1 }}"
26  register: instance
27- name: verify create instance
28  assert:
29    that:
30    - instance is successful
31
32- name: test fail if missing name
33  action: cs_volume
34  register: vol
35  ignore_errors: true
36- name: verify results of fail if missing name
37  assert:
38    that:
39    - vol is failed
40    - "vol.msg == 'missing required arguments: name'"
41
42- name: test create volume in check mode
43  cs_volume:
44    name: "{{ cs_resource_prefix }}_vol"
45    disk_offering: "{{ test_cs_disk_offering_1 }}"
46    size: 20
47  register: vol
48  check_mode: true
49- name: verify results test create volume in check mode
50  assert:
51    that:
52    - vol is changed
53
54- name: test create volume
55  cs_volume:
56    name: "{{ cs_resource_prefix }}_vol"
57    disk_offering: "{{ test_cs_disk_offering_1 }}"
58    size: 20
59  register: vol
60- name: verify results test create volume
61  assert:
62    that:
63    - vol is changed
64    - vol.size == 20 * 1024 ** 3
65    - vol.name == "{{ cs_resource_prefix }}_vol"
66
67- name: test create volume idempotence
68  cs_volume:
69    name: "{{ cs_resource_prefix }}_vol"
70    disk_offering: "{{ test_cs_disk_offering_1 }}"
71    size: 20
72  register: vol
73- name: verify results test create volume idempotence
74  assert:
75    that:
76    - vol is not changed
77    - vol.size == 20 * 1024 ** 3
78    - vol.name == "{{ cs_resource_prefix }}_vol"
79
80- name: test shrink volume in check mode
81  cs_volume:
82    name: "{{ cs_resource_prefix }}_vol"
83    disk_offering: "{{ test_cs_disk_offering_1 }}"
84    size: 10
85    shrink_ok: yes
86  register: vol
87  check_mode: true
88- name: verify results test create volume in check mode
89  assert:
90    that:
91    - vol is changed
92    - vol.size == 20 * 1024 ** 3
93    - vol.name == "{{ cs_resource_prefix }}_vol"
94
95- name: test shrink volume
96  cs_volume:
97    name: "{{ cs_resource_prefix }}_vol"
98    disk_offering: "{{ test_cs_disk_offering_1 }}"
99    size: 10
100    shrink_ok: yes
101  register: vol
102- name: verify results test create volume
103  assert:
104    that:
105    - vol is changed
106    - vol.size == 10 * 1024 ** 3
107    - vol.name == "{{ cs_resource_prefix }}_vol"
108
109- name: test shrink volume idempotence
110  cs_volume:
111    name: "{{ cs_resource_prefix }}_vol"
112    disk_offering: "{{ test_cs_disk_offering_1 }}"
113    size: 10
114    shrink_ok: yes
115  register: vol
116- name: verify results test create volume
117  assert:
118    that:
119    - vol is not changed
120    - vol.size == 10 * 1024 ** 3
121    - vol.name == "{{ cs_resource_prefix }}_vol"
122
123- name: test attach volume in check mode
124  cs_volume:
125    name: "{{ cs_resource_prefix }}_vol"
126    vm: "{{ test_cs_instance_1 }}"
127    state: attached
128  register: vol
129  check_mode: true
130- name: verify results test attach volume in check mode
131  assert:
132    that:
133    - vol is changed
134    - vol.name == "{{ cs_resource_prefix }}_vol"
135    - vol.attached is not defined
136
137- name: test attach volume
138  cs_volume:
139    name: "{{ cs_resource_prefix }}_vol"
140    vm: "{{ test_cs_instance_1 }}"
141    state: attached
142  register: vol
143- name: verify results test attach volume
144  assert:
145    that:
146    - vol is changed
147    - vol.name == "{{ cs_resource_prefix }}_vol"
148    - vol.vm == "{{ test_cs_instance_1 }}"
149    - vol.attached is defined
150
151- name: test attach volume idempotence
152  cs_volume:
153    name: "{{ cs_resource_prefix }}_vol"
154    vm: "{{ test_cs_instance_1 }}"
155    state: attached
156  register: vol
157- name: verify results test attach volume idempotence
158  assert:
159    that:
160    - vol is not changed
161    - vol.name == "{{ cs_resource_prefix }}_vol"
162    - vol.vm == "{{ test_cs_instance_1 }}"
163    - vol.attached is defined
164
165- name: test attach attached volume to another vm in check mdoe
166  cs_volume:
167    name: "{{ cs_resource_prefix }}_vol"
168    vm: "{{ test_cs_instance_2 }}"
169    state: attached
170  register: vol
171  check_mode: true
172- name: verify results test attach attached volume to another vm in check mode
173  assert:
174    that:
175    - vol is changed
176    - vol.name == "{{ cs_resource_prefix }}_vol"
177    - vol.vm == "{{ test_cs_instance_1 }}"
178    - vol.attached is defined
179
180- name: test attach attached volume to another vm
181  cs_volume:
182    name: "{{ cs_resource_prefix }}_vol"
183    vm: "{{ test_cs_instance_2 }}"
184    state: attached
185  register: vol
186- name: verify results test attach attached volume to another vm
187  assert:
188    that:
189    - vol is changed
190    - vol.name == "{{ cs_resource_prefix }}_vol"
191    - vol.vm == "{{ test_cs_instance_2 }}"
192    - vol.attached is defined
193
194- name: test attach attached volume to another vm idempotence
195  cs_volume:
196    name: "{{ cs_resource_prefix }}_vol"
197    vm: "{{ test_cs_instance_2 }}"
198    state: attached
199  register: vol
200- name: verify results test attach attached volume to another vm idempotence
201  assert:
202    that:
203    - vol is not changed
204    - vol.name == "{{ cs_resource_prefix }}_vol"
205    - vol.vm == "{{ test_cs_instance_2 }}"
206    - vol.attached is defined
207
208- name: test detach volume in check mode
209  cs_volume:
210    name: "{{ cs_resource_prefix }}_vol"
211    state: detached
212  register: vol
213  check_mode: true
214- name: verify results test detach volume in check mdoe
215  assert:
216    that:
217    - vol is changed
218    - vol.name == "{{ cs_resource_prefix }}_vol"
219    - vol.attached is defined
220
221- name: test detach volume
222  cs_volume:
223    name: "{{ cs_resource_prefix }}_vol"
224    state: detached
225  register: vol
226- name: verify results test detach volume
227  assert:
228    that:
229    - vol is changed
230    - vol.name == "{{ cs_resource_prefix }}_vol"
231    - vol.attached is undefined
232
233- name: test detach volume idempotence
234  cs_volume:
235    name: "{{ cs_resource_prefix }}_vol"
236    state: detached
237  register: vol
238- name: verify results test detach volume idempotence
239  assert:
240    that:
241    - vol is not changed
242    - vol.name == "{{ cs_resource_prefix }}_vol"
243    - vol.attached is undefined
244
245- name: test delete volume in check mode
246  cs_volume:
247    name: "{{ cs_resource_prefix }}_vol"
248    state: absent
249  register: vol
250  check_mode: true
251- name: verify results test create volume in check mode
252  assert:
253    that:
254    - vol is changed
255    - vol.name == "{{ cs_resource_prefix }}_vol"
256
257- name: test delete volume
258  cs_volume:
259    name: "{{ cs_resource_prefix }}_vol"
260    state: absent
261  register: vol
262- name: verify results test create volume
263  assert:
264    that:
265    - vol is changed
266    - vol.name == "{{ cs_resource_prefix }}_vol"
267
268- name: test delete volume idempotence
269  cs_volume:
270    name: "{{ cs_resource_prefix }}_vol"
271    state: absent
272  register: vol
273- name: verify results test delete volume idempotence
274  assert:
275    that:
276    - vol is not changed
277
278- name: cleanup instance 1
279  cs_instance:
280    name: "{{ test_cs_instance_1 }}"
281    state: absent
282  register: instance
283- name: verify create instance
284  assert:
285    that:
286    - instance is successful
287
288- name: cleanup instance 2
289  cs_instance:
290    name: "{{ test_cs_instance_2 }}"
291    state: absent
292  register: instance
293- name: verify create instance
294  assert:
295    that:
296    - instance is successful
297