From 122d4164c583076cbededca60c9e17f5d550fba8 Mon Sep 17 00:00:00 2001 From: Dmitriy Yakovlev Date: Thu, 20 Jun 2019 22:58:32 +0300 Subject: [PATCH] docker_swarm_service: Added default value for mounts.source (#58039) * Added default value for mounts.source * Added the changelog fragment * Added tests * Fixed separators * Moved the teardown section at the end --- ...ker_swarm_service-fix-resource-lookup.yaml | 2 + .../cloud/docker/docker_swarm_service.py | 2 +- .../tasks/tests/mounts.yml | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/58039-docker_swarm_service-fix-resource-lookup.yaml diff --git a/changelogs/fragments/58039-docker_swarm_service-fix-resource-lookup.yaml b/changelogs/fragments/58039-docker_swarm_service-fix-resource-lookup.yaml new file mode 100644 index 0000000000..63daa74a74 --- /dev/null +++ b/changelogs/fragments/58039-docker_swarm_service-fix-resource-lookup.yaml @@ -0,0 +1,2 @@ +bugfixes: + - docker_swarm_service - fix resource lookup if mounts.source="". diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py index 296420a5e6..96cc5f8aa1 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py @@ -2230,7 +2230,7 @@ class DockerServiceManager(object): (key.lower(), value) for key, value in driver_config.items() ) or None ds.mounts.append({ - 'source': mount_data['Source'], + 'source': mount_data.get('Source', ''), 'type': mount_data['Type'], 'target': mount_data['Target'], 'readonly': mount_data.get('ReadOnly'), diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml b/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml index e2c2029329..5063648e61 100644 --- a/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml +++ b/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml @@ -509,6 +509,53 @@ - "'Minimum version required' in mounts_tmpfs_size_1.msg" when: docker_py_version is version('2.6.0', '<') +#################################################################### +## mounts.source ################################################### +#################################################################### + +- name: mounts.source (empty for tmpfs) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + resolve_image: no + command: '/bin/sh -v -c "sleep 10m"' + mounts: + - source: "" + target: "/tmp/{{ volume_name_1 }}" + type: "tmpfs" + register: mounts_tmpfs_source_1 + ignore_errors: yes + +- name: mounts.source (empty for tmpfs idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + resolve_image: no + command: '/bin/sh -v -c "sleep 10m"' + mounts: + - source: "" + target: "/tmp/{{ volume_name_1 }}" + type: "tmpfs" + register: mounts_tmpfs_source_2 + ignore_errors: yes + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - mounts_tmpfs_source_1 is changed + - mounts_tmpfs_source_2 is not changed + when: docker_py_version is version('2.6.0', '>=') +- assert: + that: + - mounts_tmpfs_source_1 is failed + - "'Minimum version required' in mounts_tmpfs_source_1.msg" + when: docker_py_version is version('2.6.0', '<') + #################################################################### #################################################################### ####################################################################