mirror of https://github.com/ansible/ansible.git
[docker_network] add ipv6 support (#47492)
* [docker_network] add ipv6 support * docker_network: review ipam_options * docker_network: fix requirements * docker_network: fix deprecation notice * docker_network: add minimum docker version change * docker_network: remove trailing whitespace * docker_network: revert rename of network_four #discussion_r228707101 * docker_network: refactor IPAM config comparison #discussion_r228707255, #discussion_r228707280 * docker_network: correct spelling of IPv4 and IPv6 #discussion_r228707114, #discussion_r228707138 * docker_network: manually remove networks #discussion_r228709051 * docker_network: refactor enable_ipv6 condition #discussion_r228707317 * docker_network: add mutually_exclusive #discussion_r228707185 * docker_network: fix iprange #discussion_r228709072 * docker_network: add auxiliary addresses in examples and tests * docker_network: link to docker docs #discussion_r228707018 * docker_network: remove list default #discussion_r228707060, #discussion_r228709091 * docker_network: introduce params syntax for create_network() #discussion_r228709031 * docker_network: beautify code * docker_network: resolve change requests * docker_network: add yaml header * docker_networking: fix get_ip_version * docker_network: extend CIDR test * docker_network: use backported unittest2 for python 2.6 * docker_network: migrate unittest to pytestpull/47956/head
parent
80ca779aa7
commit
00bab2d24d
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- "docker_network - Add support for IPv6 networks."
|
||||||
|
deprecated_features:
|
||||||
|
- "docker_network - Deprecate ``ipam_options`` in favour of ``ipam_config``."
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- "docker_network - Minimum docker-py version increased from ``1.8.0`` to ``1.10.0``."
|
||||||
|
- "docker_network - Minimum docker server version increased from ``1.9.0`` to ``1.10.0``."
|
@ -0,0 +1,212 @@
|
|||||||
|
---
|
||||||
|
- name: Registering network names
|
||||||
|
set_fact:
|
||||||
|
nname_ipam_0: "{{ name_prefix ~ '-network-ipam-0' }}"
|
||||||
|
nname_ipam_1: "{{ name_prefix ~ '-network-ipam-1' }}"
|
||||||
|
nname_ipam_2: "{{ name_prefix ~ '-network-ipam-2' }}"
|
||||||
|
nname_ipam_3: "{{ name_prefix ~ '-network-ipam-3' }}"
|
||||||
|
|
||||||
|
- name: Registering network names
|
||||||
|
set_fact:
|
||||||
|
dnetworks: "{{ dnetworks }} + [nname_ipam_0, nname_ipam_1, nname_ipam_2, nname_ipam_3]"
|
||||||
|
|
||||||
|
|
||||||
|
#################### network-ipam-0 deprecated ####################
|
||||||
|
|
||||||
|
- name: Create network with ipam_config and deprecated ipam_options
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_0 }}"
|
||||||
|
ipam_options:
|
||||||
|
subnet: 172.3.29.0/24
|
||||||
|
ipam_config:
|
||||||
|
- subnet: 172.3.29.0/24
|
||||||
|
register: network
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is failed
|
||||||
|
- "network.msg == 'parameters are mutually exclusive: ipam_config, ipam_options'"
|
||||||
|
|
||||||
|
- name: Create network with deprecated custom IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_0 }}"
|
||||||
|
ipam_options:
|
||||||
|
subnet: 172.3.29.0/24
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
|
||||||
|
- name: Change subnet of network with deprecated custom IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_0 }}"
|
||||||
|
ipam_options:
|
||||||
|
subnet: 172.3.30.0/24
|
||||||
|
register: network
|
||||||
|
diff: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
- network['diff'] | length == 1
|
||||||
|
- network['diff'][0] == "ipam_config[0].subnet"
|
||||||
|
|
||||||
|
- name: Cleanup network with ipam_config and deprecated ipam_options
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_0 }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
|
||||||
|
#################### network-ipam-1 ####################
|
||||||
|
- name: Create network with custom IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_1 }}"
|
||||||
|
ipam_config:
|
||||||
|
- subnet: 172.3.27.0/24
|
||||||
|
gateway: 172.3.27.2
|
||||||
|
iprange: 172.3.27.0/26
|
||||||
|
aux_addresses:
|
||||||
|
host1: 172.3.27.3
|
||||||
|
host2: 172.3.27.4
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
|
||||||
|
- name: Change subnet, gateway, iprange and auxiliary addresses of network with custom IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_1 }}"
|
||||||
|
ipam_config:
|
||||||
|
- subnet: 172.3.28.0/24
|
||||||
|
gateway: 172.3.28.2
|
||||||
|
iprange: 172.3.28.0/26
|
||||||
|
aux_addresses:
|
||||||
|
host1: 172.3.28.3
|
||||||
|
register: network
|
||||||
|
diff: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
- network['diff'] | length == 4
|
||||||
|
- '"ipam_config[0].subnet" in network["diff"]'
|
||||||
|
- '"ipam_config[0].gateway" in network["diff"]'
|
||||||
|
- '"ipam_config[0].iprange" in network["diff"]'
|
||||||
|
- '"ipam_config[0].aux_addresses" in network["diff"]'
|
||||||
|
|
||||||
|
- name: Remove gateway and iprange of network with custom IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_1 }}"
|
||||||
|
ipam_config:
|
||||||
|
- subnet: 172.3.28.0/24
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is not changed
|
||||||
|
|
||||||
|
- name: Cleanup network with custom IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_1 }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
|
||||||
|
#################### network-ipam-2 ####################
|
||||||
|
|
||||||
|
- name: Create network with IPv6 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_2 }}"
|
||||||
|
enable_ipv6: yes
|
||||||
|
ipam_config:
|
||||||
|
- subnet: fdd1:ac8c:0557:7ce0::/64
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
|
||||||
|
- name: Change subnet of network with IPv6 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_2 }}"
|
||||||
|
enable_ipv6: yes
|
||||||
|
ipam_config:
|
||||||
|
- subnet: fdd1:ac8c:0557:7ce1::/64
|
||||||
|
register: network
|
||||||
|
diff: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
- network['diff'] | length == 1
|
||||||
|
- network['diff'][0] == "ipam_config[0].subnet"
|
||||||
|
|
||||||
|
- name: Change subnet of network with IPv6 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_2 }}"
|
||||||
|
enable_ipv6: yes
|
||||||
|
ipam_config:
|
||||||
|
- subnet: "fdd1:ac8c:0557:7ce1::"
|
||||||
|
register: network
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is failed
|
||||||
|
- "network.msg == '\"fdd1:ac8c:0557:7ce1::\" is not a valid CIDR'"
|
||||||
|
|
||||||
|
- name: Cleanup network with IPv6 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_2 }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
|
||||||
|
#################### network-ipam-3 ####################
|
||||||
|
|
||||||
|
- name: Create network with IPv6 and custom IPv4 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_3 }}"
|
||||||
|
enable_ipv6: yes
|
||||||
|
ipam_config:
|
||||||
|
- subnet: 172.4.27.0/24
|
||||||
|
- subnet: fdd1:ac8c:0557:7ce2::/64
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
|
||||||
|
- name: Change subnet order of network with IPv6 and custom IPv4 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_3 }}"
|
||||||
|
enable_ipv6: yes
|
||||||
|
ipam_config:
|
||||||
|
- subnet: fdd1:ac8c:0557:7ce2::/64
|
||||||
|
- subnet: 172.4.27.0/24
|
||||||
|
register: network
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is not changed
|
||||||
|
|
||||||
|
- name: Remove IPv6 from network with custom IPv4 and IPv6 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_3 }}"
|
||||||
|
enable_ipv6: no
|
||||||
|
ipam_config:
|
||||||
|
- subnet: 172.4.27.0/24
|
||||||
|
register: network
|
||||||
|
diff: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- network is changed
|
||||||
|
- network['diff'] | length == 1
|
||||||
|
- network['diff'][0] == "enable_ipv6"
|
||||||
|
|
||||||
|
- name: Cleanup network with IPv6 and custom IPv4 IPAM config
|
||||||
|
docker_network:
|
||||||
|
name: "{{ nname_ipam_3 }}"
|
||||||
|
state: absent
|
@ -0,0 +1,27 @@
|
|||||||
|
"""Unit tests for docker_network."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from ansible.modules.cloud.docker.docker_network import get_ip_version
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("cidr,expected", [
|
||||||
|
('192.168.0.1/16', 'ipv4'),
|
||||||
|
('192.168.0.1/24', 'ipv4'),
|
||||||
|
('192.168.0.1/32', 'ipv4'),
|
||||||
|
('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
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("cidr", [
|
||||||
|
'192.168.0.1',
|
||||||
|
'192.168.0.1/34',
|
||||||
|
'192.168.0.1/asd',
|
||||||
|
'fdd1:ac8c:0557:7ce2::',
|
||||||
|
])
|
||||||
|
def test_get_ip_version_negatives(cidr):
|
||||||
|
with pytest.raises(ValueError) as e:
|
||||||
|
get_ip_version(cidr)
|
||||||
|
assert '"{0}" is not a valid CIDR'.format(cidr) == str(e.value)
|
Loading…
Reference in New Issue