Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_swarm_service: Added default value for mounts.source #58039

Merged
merged 5 commits into from Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,2 @@
bugfixes:
- docker_swarm_service - fix resource lookup if mounts.source="".
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/docker/docker_swarm_service.py
Expand Up @@ -2230,7 +2230,7 @@ def get_service(self, name):
(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'),
Expand Down
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this above this line:

####################################################################

And add this above the test you added:

####################################################################
## mounts.source ###################################################
#################################################################### 

This will keep the tests structured.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The teardown section of the test should not be below mounts.source. Please move these lines

- name: Delete volumes
docker_volume:
name: "{{ volume_name }}"
state: absent
loop:
- "{{ volume_name_1 }}"
- "{{ volume_name_2 }}"
loop_control:
loop_var: volume_name
ignore_errors: yes

Below

####################################################################

Thanks!

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', '<')

####################################################################
####################################################################
####################################################################
Expand Down