summaryrefslogtreecommitdiff
path: root/test/integration/targets/docker_network/tasks/tests/ipam.yml
blob: 993635f770a297701e15cbbe1cb055e9a25c8c85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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