Skip to content

Commit 69fd222

Browse files
NK308galli-leoToroto006Andersson007
authored
Implement ansible module for management of libvirt volumes (ansible-collections#180)
* Initial Commit of virt_volume support * Fixed etree error with an import * Make documentation of the new module more standard * Add references to doc_fragments in virt_volume * Refactor documentation of virt_volume * Fix docstring * Fix import sanity issues * Fix docstring * Fix PEP8 issues * Fix doc of 'state' parameter * Bugfix in 'virt_volume' add missing line * Bug in virt_volume core fixed * Sanity issues fixed * Python2 compatibility fixed * Handling of idempotency for 'present' state of virt_volume changed Trying to define a volume, that already exists caused the integration test to fail with a traceback that implies, a code block has been executed, which should have been skipped in the case of the target volume already existing. The previous code based on raising and catching an exception in case the volume does not already exist, but resulting in the exception bein risen anyway during the test, which lead to the failure. This commit replaces the exception based check in hope to fix this bug. * fixup! Handling of idempotency for 'present' state of virt_volume changed Trying to define a volume, that already exists caused the integration test to fail with a traceback that implies, a code block has been executed, which should have been skipped in the case of the target volume already existing. The previous code based on raising and catching an exception in case the volume does not already exist, but resulting in the exception bein risen anyway during the test, which lead to the failure. This commit replaces the exception based check in hope to fix this bug. * Make volume name in task and xml match during integration test * fixup! Make volume name in task and xml match during integration test * Refactoring into `plugins.module_utils.pool` has been reverted * Probably outdated sets of test variables removed * Package name in integration test changed * Change reference to package in integration testing * fixup! Change reference to package in integration testing * Variable files for Ubuntu deleted, since they are either outdated * Variables for Fedora 29 removed, since it is end-of-life * Remove unnecessary uri from unit test * Integration test refactored to use templates and variables * Add verstion number to plugins/modules/virt_volume.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Name added to author list * Docstring formatting improved in plugins/modules/virt_volume.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Remove redundant option `undefined` from the state parameter. --------- Co-authored-by: Leonardo Galli <leonardo.galli@bluewin.ch> Co-authored-by: toroto006 <tobiaso@student.ethz.ch> Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
1 parent 00fb361 commit 69fd222

File tree

11 files changed

+842
-10
lines changed

11 files changed

+842
-10
lines changed

plugins/modules/virt_volume.py

Lines changed: 713 additions & 0 deletions
Large diffs are not rendered by default.

tests/integration/targets/virt_pool/vars/CentOS-8.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
shippable/posix/group1
2+
skip/aix
3+
skip/freebsd
4+
skip/osx
5+
needs/privileged
6+
destructive
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
pool_info:
3+
volume_name: test1
4+
size: 10
5+
unit: M
6+
pool_name: test_pool
7+
path: /tmp/test_pool
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
- include_vars: '{{ item }}'
3+
with_first_found:
4+
- "{{ ansible_distribution }}-{{ ansible_distribution_version}}.yml"
5+
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
6+
- "{{ ansible_distribution }}.yml"
7+
- "default.yml"
8+
9+
- block:
10+
- name: Install libvirt packages
11+
package:
12+
name: "{{ virt_volume_packages }}"
13+
14+
- name: Start libvirt
15+
service:
16+
name: libvirtd
17+
state: started
18+
19+
- name: Create Storage Pool Dir
20+
file:
21+
path: /var/lib/virt/images
22+
state: directory
23+
recurse: yes
24+
25+
- name: Define the foobar storage pool
26+
virt_pool:
27+
command: define
28+
name: "{{ pool_name }}"
29+
xml: '{{ lookup("template", "pool_definition.xml.j2") }}'
30+
31+
- name: Start the default pool
32+
virt_pool:
33+
state: active
34+
name: "{{ pool_name }}"
35+
36+
- name: Create Volume test1
37+
virt_volume:
38+
name: "{{ volume_name }}"
39+
pool: "{{ pool_name }}"
40+
state: present
41+
xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
42+
43+
- name: List Volumes
44+
virt_volume:
45+
pool: "{{ pool_name }}"
46+
command: list_volumes
47+
register: list_volumes1
48+
49+
- name: Create Volume test1 again
50+
virt_volume:
51+
pool: "{{ pool_name }}"
52+
name: "{{ volume_name }}"
53+
state: present
54+
xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
55+
register: create_test1_2
56+
debugger: always
57+
58+
- name: Destroy the foobar pool
59+
virt_pool:
60+
command: destroy
61+
name: "{{ pool_name }}"
62+
63+
- name: Ensures stuff
64+
assert:
65+
that:
66+
- '"{{ volume_name }}" in list_volumes1'
67+
68+
# - name: Ensure the second calls return "unchanged"
69+
# assert:
70+
# that:
71+
# - "second_virt_net_start is not changed"
72+
# - "second_virt_net_define is not changed"
73+
# - "second_virt_net_undefine is not changed"
74+
75+
always:
76+
- name: Stop libvirt
77+
service:
78+
name: libvirtd
79+
state: stopped
80+
81+
- name: Remove only the libvirt packages
82+
package:
83+
name: "{{ virt_volume_packages|select('match', '.*libvirt.*')|list }}"
84+
state: absent
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<pool type="dir">
2+
<name>{{ pool_name }}</name>
3+
<target>
4+
<path>{{ path }}</path>
5+
</target>
6+
</pool>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<volume>
2+
<name>test1</name>
3+
<allocation>0</allocation>
4+
<capacity unit="{{ unit }}">{{ size }}</capacity>
5+
<target>
6+
<permissions>
7+
<owner>107</owner>
8+
<group>107</group>
9+
<mode>0744</mode>
10+
<label>virt_image_t</label>
11+
</permissions>
12+
</target>
13+
</volume>

tests/integration/targets/virt_pool/vars/Ubuntu-18.10.yml renamed to tests/integration/targets/virt_volume/vars/Debian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
virt_pool_packages:
2+
virt_volume_package:
33
- libvirt-daemon
44
- libvirt-daemon-system
55
- python-libvirt
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
virt_volume_package:
3+
- libvirt
4+
- libvirt-daemon
5+
- libvirt-python
6+
- python-lxml

tests/integration/targets/virt_pool/vars/Fedora-34.yml renamed to tests/integration/targets/virt_volume/vars/RedHat-8.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
virt_pool_packages:
2+
virt_volume_package:
33
- libvirt
44
- libvirt-daemon
55
- python3-libvirt

0 commit comments

Comments
 (0)