Skip to content

Commit

Permalink
[docker_network] Fix idempotency when using aux_addresses in ipam_con…
Browse files Browse the repository at this point in the history
…fig (ansible#56901)

* [docker_network] Fix idempotency when using aux_addresses in ipam_config

Mismatch between keys returned by Docker API (AuxilliaryAddresses) vs
expected by Ansible module (aux_addresses) resulted in tasks always
have status 'changed'. The existing code normalizing one set of
keys to another missed this special case where converting
CamelCase to lowercase is not sufficent.

Please see
https://github.com/moby/moby/blob/master/api/types/network/network.go
for reference.

* Correct keywords formatting in changelog file

Co-Authored-By: Felix Fontein <felix@fontein.de>
  • Loading branch information
2 people authored and ansibot committed May 26, 2019
1 parent 2f523ad commit 37df89b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/docker_network_aux_addresses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- docker_network module - fix idempotency when using ``aux_addresses`` in ``ipam_config``.
16 changes: 15 additions & 1 deletion lib/ansible/modules/cloud/docker/docker_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ def get_ip_version(cidr):
raise ValueError('"{0}" is not a valid CIDR'.format(cidr))


def normalize_ipam_config_key(key):
"""Normalizes IPAM config keys returned by Docker API to match Ansible keys
:param key: Docker API key
:type key: str
:return Ansible module key
:rtype str
"""
special_cases = {
'AuxiliaryAddresses': 'aux_addresses'
}
return special_cases.get(key, key.lower())


class DockerNetworkManager(object):

def __init__(self, client):
Expand Down Expand Up @@ -447,7 +461,7 @@ def has_different_config(self, net):
continue
camelkey = None
for net_key in net_config:
if key == net_key.lower():
if key == normalize_ipam_config_key(net_key):
camelkey = net_key
break
if not camelkey or net_config.get(camelkey) != value:
Expand Down

0 comments on commit 37df89b

Please sign in to comment.