mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
virt_net: idempotency of create/stop actions (#53276)
Currently, if we try to stop or start a network two time in a row, the second call will fail. With this patch: - we don't recreate a network, if it exists - we only stop a network if it's active, and so we avoid an exception saying the network is not active * test: mock libvirt * add integration tests for virt_net * test: enable virt_net test on RedHat 7 and 8 * ci: use the unsupported alias * tests that require privileged mode are run in VM * virt_net/create raise unexpected libvirt exception * import mock from units.compat * virt_net: do not call create() on "active" network * virt_net func test: only clean up the libvirt packages * test: virt_net: don't use assert_called() * virt_net: add the destructive alias * move the test in virt_net dir * test/virt_net: clean up the network at the end
This commit is contained in:
committed by
Abhijeet Kasurde
parent
56418cc274
commit
fc3064471b
5
test/integration/targets/virt_net/aliases
Normal file
5
test/integration/targets/virt_net/aliases
Normal file
@@ -0,0 +1,5 @@
|
||||
shippable/posix/group1
|
||||
skip/freebsd
|
||||
skip/osx
|
||||
needs/privileged
|
||||
destructive
|
||||
9
test/integration/targets/virt_net/files/foobar.xml
Normal file
9
test/integration/targets/virt_net/files/foobar.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<network>
|
||||
<name>foobar</name>
|
||||
<forward mode='nat'/>
|
||||
<ip address='192.168.125.1' netmask='255.255.255.0'>
|
||||
<dhcp>
|
||||
<range start='192.168.125.2' end='192.168.125.254'/>
|
||||
</dhcp>
|
||||
</ip>
|
||||
</network>
|
||||
78
test/integration/targets/virt_net/tasks/main.yml
Normal file
78
test/integration/targets/virt_net/tasks/main.yml
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
- include_vars: '{{ item }}'
|
||||
with_first_found:
|
||||
- "{{ ansible_distribution }}-{{ ansible_distribution_version}}.yml"
|
||||
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
|
||||
- "{{ ansible_distribution }}.yml"
|
||||
- "default.yml"
|
||||
|
||||
- block:
|
||||
- name: Install libvirt packages
|
||||
package:
|
||||
name: "{{ virt_net_packages }}"
|
||||
|
||||
- name: Start libvirt
|
||||
service:
|
||||
name: libvirtd
|
||||
state: started
|
||||
|
||||
- name: Define the foobar network
|
||||
virt_net:
|
||||
command: define
|
||||
name: foobar
|
||||
xml: '{{ lookup("file", "foobar.xml") }}'
|
||||
|
||||
- name: Define the foobar network (again)
|
||||
virt_net:
|
||||
command: define
|
||||
name: foobar
|
||||
xml: '{{ lookup("file", "foobar.xml") }}'
|
||||
register: second_virt_net_define
|
||||
|
||||
- name: Start the default network
|
||||
virt_net:
|
||||
uri: qemu:///system
|
||||
command: start
|
||||
name: foobar
|
||||
|
||||
- name: Start the default network (again)
|
||||
virt_net:
|
||||
uri: qemu:///system
|
||||
command: start
|
||||
name: foobar
|
||||
register: second_virt_net_start
|
||||
|
||||
- name: Destroy the foobar network
|
||||
virt_net:
|
||||
command: destroy
|
||||
name: foobar
|
||||
|
||||
- name: Undefine the foobar network
|
||||
virt_net:
|
||||
command: undefine
|
||||
name: foobar
|
||||
register: second_virt_net_define
|
||||
|
||||
- name: Undefine the foobar network (again)
|
||||
virt_net:
|
||||
command: undefine
|
||||
name: foobar
|
||||
register: second_virt_net_undefine
|
||||
|
||||
- name: Ensure the second calls return "unchanged"
|
||||
assert:
|
||||
that:
|
||||
- "second_virt_net_start is not changed"
|
||||
- "second_virt_net_define is not changed"
|
||||
- "second_virt_net_undefine is not changed"
|
||||
|
||||
always:
|
||||
- name: Stop libvirt
|
||||
service:
|
||||
name: libvirtd
|
||||
state: stopped
|
||||
|
||||
- name: Remove only the libvirt packages
|
||||
package:
|
||||
name: "{{ virt_net_packages|select('match', '.*libvirt.*')|list }}"
|
||||
state: absent
|
||||
6
test/integration/targets/virt_net/vars/Debian.yml
Normal file
6
test/integration/targets/virt_net/vars/Debian.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt-daemon
|
||||
- libvirt-daemon-system
|
||||
- python-libvirt
|
||||
- python-lxml
|
||||
6
test/integration/targets/virt_net/vars/Fedora-29.yml
Normal file
6
test/integration/targets/virt_net/vars/Fedora-29.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt
|
||||
- libvirt-daemon
|
||||
- python3-libvirt
|
||||
- python3-lxml
|
||||
6
test/integration/targets/virt_net/vars/RedHat-7.yml
Normal file
6
test/integration/targets/virt_net/vars/RedHat-7.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt
|
||||
- libvirt-daemon
|
||||
- libvirt-python
|
||||
- python-lxml
|
||||
6
test/integration/targets/virt_net/vars/RedHat-8.yml
Normal file
6
test/integration/targets/virt_net/vars/RedHat-8.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt
|
||||
- libvirt-daemon
|
||||
- python3-libvirt
|
||||
- python3-lxml
|
||||
5
test/integration/targets/virt_net/vars/Ubuntu-16.04.yml
Normal file
5
test/integration/targets/virt_net/vars/Ubuntu-16.04.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt-daemon
|
||||
- python-libvirt
|
||||
- python-lxml
|
||||
5
test/integration/targets/virt_net/vars/Ubuntu-18.04.yml
Normal file
5
test/integration/targets/virt_net/vars/Ubuntu-18.04.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt-daemon
|
||||
- python-libvirt
|
||||
- python-lxml
|
||||
6
test/integration/targets/virt_net/vars/Ubuntu-18.10.yml
Normal file
6
test/integration/targets/virt_net/vars/Ubuntu-18.10.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt-daemon
|
||||
- libvirt-daemon-system
|
||||
- python-libvirt
|
||||
- python-lxml
|
||||
5
test/integration/targets/virt_net/vars/default.yml
Normal file
5
test/integration/targets/virt_net/vars/default.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
virt_net_packages:
|
||||
- libvirt-daemon
|
||||
- python-libvirt
|
||||
- python-lxml
|
||||
Reference in New Issue
Block a user