[docker_network] Add handling for Python booleans in driver_options (#48105)

Fixes #26708
This commit is contained in:
Dave Bendit 2018-11-06 08:39:45 -06:00 committed by John R Barker
parent 0d9c923464
commit d7686e1bc0
3 changed files with 75 additions and 2 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- "docker_network - ``driver_options`` containing Python booleans would cause Docker to throw exceptions."

View file

@ -268,6 +268,21 @@ def get_ip_version(cidr):
raise ValueError('"{0}" is not a valid CIDR'.format(cidr))
def get_driver_options(driver_options):
result = dict()
if driver_options is not None:
for k, v in driver_options.items():
# Go doesn't like 'True' or 'False'
if v is True:
v = 'true'
elif v is False:
v = 'false'
else:
v = str(v)
result[str(k)] = v
return result
class DockerNetworkManager(object):
def __init__(self, client):
@ -288,6 +303,9 @@ class DockerNetworkManager(object):
if self.parameters.ipam_options:
self.parameters.ipam_config = [self.parameters.ipam_options]
if self.parameters.driver_options:
self.parameters.driver_options = get_driver_options(self.parameters.driver_options)
state = self.parameters.state
if state == 'present':
self.present()

View file

@ -2,10 +2,9 @@
- name: Registering network name
set_fact:
nname_1: "{{ name_prefix ~ '-network-1' }}"
nname_2: "{{ name_prefix ~ '-network-2' }}"
- name: Registering network name
set_fact:
dnetworks: "{{ dnetworks }} + [nname_1, nname_2]"
dnetworks: "{{ dnetworks }} + [nname_1]"
####################################################################
## internal ########################################################
@ -40,3 +39,56 @@
- internal_1 is changed
- internal_2 is not changed
- internal_3 is changed
####################################################################
## driver_options ##################################################
####################################################################
- name: driver_options
docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: 'false'
register: driver_options_1
- name: driver_options (idempotency)
docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: 'false'
register: driver_options_2
- name: driver_options (idempotency with string translation)
docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: False
register: driver_options_3
- name: driver_options (change)
docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: 'true'
register: driver_options_4
- name: driver_options (idempotency with string translation)
docker_network:
name: "{{ nname_1 }}"
driver_options:
com.docker.network.bridge.enable_icc: True
register: driver_options_5
- name: cleanup
docker_network:
name: "{{ nname_1 }}"
state: absent
force: yes
- assert:
that:
- driver_options_1 is changed
- driver_options_2 is not changed
- driver_options_3 is not changed
- driver_options_4 is changed
- driver_options_5 is not changed