diff options
author | Felix Fontein <felix@fontein.de> | 2019-12-29 23:16:17 +0100 |
---|---|---|
committer | Matt Clay <matt@mystile.com> | 2020-01-10 15:07:48 -0800 |
commit | 519846a1be47b43672f7e33bbadda3ce50a95535 (patch) | |
tree | bcb6a38fff33d22107a0b7f2f55da454bef00b68 /test | |
parent | 3f98e1ff4ea49c9dea2631a608b50796027d185d (diff) | |
download | ansible-519846a1be47b43672f7e33bbadda3ce50a95535.tar.gz |
docker_network: fix multiple subnet (of same IP version) idempotence (#65839)
* Fix multiple subnet (of same IP version) idempotence for docker_network.
* Add changelog.
* Unit tests no longer make sense, since the part of the code they test has been removed.
* Re-add CIDR validation. Move it to better position (module setup instead of idempotence check).
* Update changelog.
* Only run new tests on VM test images.
* Actually do what is documented. Especially since an empty object is a valid value for aux_addresses.
(cherry picked from commit 17ef253ad15fa6a02e1e22f5847aba85b60e151f)
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/targets/docker_network/tasks/tests/ipam.yml | 82 | ||||
-rw-r--r-- | test/units/modules/cloud/docker/test_docker_network.py | 10 |
2 files changed, 82 insertions, 10 deletions
diff --git a/test/integration/targets/docker_network/tasks/tests/ipam.yml b/test/integration/targets/docker_network/tasks/tests/ipam.yml index cd448fac42..7405c3b194 100644 --- a/test/integration/targets/docker_network/tasks/tests/ipam.yml +++ b/test/integration/targets/docker_network/tasks/tests/ipam.yml @@ -11,7 +11,7 @@ dnetworks: "{{ dnetworks + [nname_ipam_0, nname_ipam_1, nname_ipam_2, nname_ipam_3] }}" -#################### network-ipam-0 deprecated #################### +#################### Deprecated ipam_config #################### - name: Create network with ipam_config and deprecated ipam_options (conflicting) docker_network: @@ -98,7 +98,7 @@ state: absent -#################### network-ipam-1 #################### +#################### IPv4 IPAM config #################### - name: Create network with custom IPAM config docker_network: name: "{{ nname_ipam_1 }}" @@ -169,7 +169,7 @@ state: absent -#################### network-ipam-2 #################### +#################### IPv6 IPAM config #################### - name: Create network with IPv6 IPAM config docker_network: @@ -230,7 +230,7 @@ state: absent -#################### network-ipam-3 #################### +#################### IPv4 and IPv6 network #################### - name: Create network with IPv6 and custom IPv4 IPAM config docker_network: @@ -279,7 +279,79 @@ state: absent -#################### network-ipam-4 #################### +#################### multiple IPv4 networks #################### + +- block: + - name: Create network with two IPv4 IPAM configs + docker_network: + name: "{{ nname_ipam_3 }}" + driver: "macvlan" + driver_options: + parent: "{{ ansible_default_ipv4.alias }}" + ipam_config: + - subnet: 172.4.27.0/24 + - subnet: 172.4.28.0/24 + register: network + + - assert: + that: + - network is changed + + - name: Create network with two IPv4 IPAM configs (idempotence) + docker_network: + name: "{{ nname_ipam_3 }}" + driver: "macvlan" + driver_options: + parent: "{{ ansible_default_ipv4.alias }}" + ipam_config: + - subnet: 172.4.28.0/24 + - subnet: 172.4.27.0/24 + register: network + + - assert: + that: + - network is not changed + + - name: Create network with two IPv4 IPAM configs (change) + docker_network: + name: "{{ nname_ipam_3 }}" + driver: "macvlan" + driver_options: + parent: "{{ ansible_default_ipv4.alias }}" + ipam_config: + - subnet: 172.4.27.0/24 + - subnet: 172.4.29.0/24 + register: network + diff: yes + + - assert: + that: + - network is changed + - network.diff.differences | length == 1 + + - name: Create network with one IPv4 IPAM config (no change) + docker_network: + name: "{{ nname_ipam_3 }}" + driver: "macvlan" + driver_options: + parent: "{{ ansible_default_ipv4.alias }}" + ipam_config: + - subnet: 172.4.29.0/24 + register: network + + - assert: + that: + - network is not changed + + - name: Cleanup network + docker_network: + name: "{{ nname_ipam_3 }}" + state: absent + + when: ansible_facts.virtualization_type != 'docker' + + +#################### IPAM driver options #################### - name: Create network with IPAM driver options docker_network: diff --git a/test/units/modules/cloud/docker/test_docker_network.py b/test/units/modules/cloud/docker/test_docker_network.py index 2c385a71d2..f2c0d5d504 100644 --- a/test/units/modules/cloud/docker/test_docker_network.py +++ b/test/units/modules/cloud/docker/test_docker_network.py @@ -1,7 +1,7 @@ """Unit tests for docker_network.""" import pytest -from ansible.modules.cloud.docker.docker_network import get_ip_version +from ansible.modules.cloud.docker.docker_network import validate_cidr @pytest.mark.parametrize("cidr,expected", [ @@ -11,8 +11,8 @@ from ansible.modules.cloud.docker.docker_network import get_ip_version ('fdd1:ac8c:0557:7ce2::/64', 'ipv6'), ('fdd1:ac8c:0557:7ce2::/128', 'ipv6'), ]) -def test_get_ip_version_positives(cidr, expected): - assert get_ip_version(cidr) == expected +def test_validate_cidr_positives(cidr, expected): + assert validate_cidr(cidr) == expected @pytest.mark.parametrize("cidr", [ @@ -21,7 +21,7 @@ def test_get_ip_version_positives(cidr, expected): '192.168.0.1/asd', 'fdd1:ac8c:0557:7ce2::', ]) -def test_get_ip_version_negatives(cidr): +def test_validate_cidr_negatives(cidr): with pytest.raises(ValueError) as e: - get_ip_version(cidr) + validate_cidr(cidr) assert '"{0}" is not a valid CIDR'.format(cidr) == str(e.value) |