mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-16 03:52:05 +00:00
Fix label sanitization error handling. (#1029)
This commit is contained in:
parent
9e26c4794e
commit
9cc70f5202
2
changelogs/fragments/1029-sanitize-labels-fail.yml
Normal file
2
changelogs/fragments/1029-sanitize-labels-fail.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "Fix label sanitization code to avoid crashes in case of errors (https://github.com/ansible-collections/community.docker/issues/1028, https://github.com/ansible-collections/community.docker/pull/1029)."
|
||||||
@ -282,7 +282,7 @@ class DifferenceTracker(object):
|
|||||||
def sanitize_labels(labels, labels_field, client=None, module=None):
|
def sanitize_labels(labels, labels_field, client=None, module=None):
|
||||||
def fail(msg):
|
def fail(msg):
|
||||||
if client is not None:
|
if client is not None:
|
||||||
client.module.fail(msg)
|
client.fail(msg)
|
||||||
if module is not None:
|
if module is not None:
|
||||||
module.fail_json(msg=msg)
|
module.fail_json(msg=msg)
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|||||||
@ -118,6 +118,14 @@
|
|||||||
## labels ##########################################################
|
## labels ##########################################################
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
|
- name: Create a volume with an invalid label
|
||||||
|
docker_volume:
|
||||||
|
name: "{{ vname }}"
|
||||||
|
labels:
|
||||||
|
foo: 1.0
|
||||||
|
register: driver_labels_invalid
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Create a volume with labels
|
- name: Create a volume with labels
|
||||||
docker_volume:
|
docker_volume:
|
||||||
name: "{{ vname }}"
|
name: "{{ vname }}"
|
||||||
@ -173,6 +181,8 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
|
- driver_labels_invalid is failed
|
||||||
|
- driver_labels_invalid.msg == "The value 1.0 for 'foo' of labels is not a string or something than can be safely converted to a string!"
|
||||||
- driver_labels_1 is changed
|
- driver_labels_1 is changed
|
||||||
- driver_labels_2 is not changed
|
- driver_labels_2 is not changed
|
||||||
- driver_labels_3 is not changed
|
- driver_labels_3 is not changed
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user