mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-05 16:04:09 -07:00
docker_* modules: simplify idempotency comparisons (#47709)
* More generic comparison code from docker_container to docker_common. * More flexibility if a is None and method is allow_to_present. Note that this odes not affect docker_container, as there a is never None. * Update docker_secret and docker_config: simplify labels comparison. * Added unit tests. * Use proper subsequence test for allow_more_present for lists. Note that this does not affect existing code in docker_container, since lists don't use allow_more_present. Using allow_more_present will only be possible in Ansible 2.8. * pep8
This commit is contained in:
parent
e217ba6e19
commit
73533d3fc2
5 changed files with 577 additions and 103 deletions
|
@ -152,7 +152,7 @@ except ImportError:
|
|||
# missing docker-py handled in ansible.module_utils.docker
|
||||
pass
|
||||
|
||||
from ansible.module_utils.docker_common import AnsibleDockerClient, DockerBaseClass
|
||||
from ansible.module_utils.docker_common import AnsibleDockerClient, DockerBaseClass, compare_generic
|
||||
from ansible.module_utils._text import to_native, to_bytes
|
||||
|
||||
|
||||
|
@ -224,22 +224,8 @@ class ConfigManager(DockerBaseClass):
|
|||
if attrs.get('Labels', {}).get('ansible_key'):
|
||||
if attrs['Labels']['ansible_key'] != self.data_key:
|
||||
data_changed = True
|
||||
labels_changed = False
|
||||
if self.labels and attrs.get('Labels'):
|
||||
# check if user requested a label change
|
||||
for label in attrs['Labels']:
|
||||
if self.labels.get(label) and self.labels[label] != attrs['Labels'][label]:
|
||||
labels_changed = True
|
||||
# check if user added a label
|
||||
labels_added = False
|
||||
if self.labels:
|
||||
if attrs.get('Labels'):
|
||||
for label in self.labels:
|
||||
if label not in attrs['Labels']:
|
||||
labels_added = True
|
||||
else:
|
||||
labels_added = True
|
||||
if data_changed or labels_added or labels_changed or self.force:
|
||||
labels_changed = not compare_generic(self.labels, attrs.get('Labels'), 'allow_more_present', 'dict')
|
||||
if data_changed or labels_changed or self.force:
|
||||
# if something changed or force, delete and re-create the config
|
||||
self.absent()
|
||||
config_id = self.create_config()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue