Fix docker_plugin crash when handling plugin options (#447)

* Fix docker_plugin crash when handling plugin options.

* Try to add tests.
This commit is contained in:
Felix Fontein 2022-08-12 19:29:45 +02:00 committed by GitHub
parent f513ba2c59
commit a50257381f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- "docker_plugin - fix crash when handling plugin options (https://github.com/ansible-collections/community.docker/issues/446, https://github.com/ansible-collections/community.docker/pull/447)."

View File

@ -245,7 +245,7 @@ class DockerPluginManager(object):
self.existing_plugin = self.client.get_json('/plugins/{0}/json', self.preferred_name) self.existing_plugin = self.client.get_json('/plugins/{0}/json', self.preferred_name)
if self.parameters.plugin_options: if self.parameters.plugin_options:
data = prepare_options(self.parameters.plugin_options) data = prepare_options(self.parameters.plugin_options)
self.client.post_json('/plugins/{0}/set', self.preferred_name, data=['{0}={1}'.format(k, v) for k, v in data.items()]) self.client.post_json('/plugins/{0}/set', self.preferred_name, data=data)
except APIError as e: except APIError as e:
self.client.fail(to_native(e)) self.client.fail(to_native(e))
@ -271,7 +271,7 @@ class DockerPluginManager(object):
if not self.check_mode: if not self.check_mode:
try: try:
data = prepare_options(self.parameters.plugin_options) data = prepare_options(self.parameters.plugin_options)
self.client.post_json('/plugins/{0}/set', self.preferred_name, data=['{0}={1}'.format(k, v) for k, v in data.items()]) self.client.post_json('/plugins/{0}/set', self.preferred_name, data=data)
except APIError as e: except APIError as e:
self.client.fail(to_native(e)) self.client.fail(to_native(e))
self.actions.append("Updated plugin %s settings" % self.preferred_name) self.actions.append("Updated plugin %s settings" % self.preferred_name)

View File

@ -5,7 +5,7 @@
- name: Create random name prefix - name: Create random name prefix
set_fact: set_fact:
name_prefix: "cvmfs/overlay2-graphdriver" name_prefix: "vieux/sshfs"
plugin_names: [] plugin_names: []
- debug: - debug:

View File

@ -62,6 +62,12 @@
state: absent state: absent
register: absent_4 register: absent_4
- name: Cleanup
docker_plugin:
plugin_name: "{{ plugin_name }}"
state: absent
force_remove: true
- assert: - assert:
that: that:
- create_1 is changed - create_1 is changed
@ -75,10 +81,48 @@
############ Plugin_Options ############ ############ Plugin_Options ############
######################################## ########################################
# Integration-Test with plugin_options is in TODO-List
- name: Install a plugin with options
docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '1'
state: present
register: create_1
- name: Install a plugin with options (idempotent)
docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '1'
state: present
register: create_2
- name: Install a plugin with different options
docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '0'
state: present
register: update_1
- name: Install a plugin with different options (idempotent)
docker_plugin:
plugin_name: "{{ plugin_name }}"
plugin_options:
DEBUG: '0'
state: present
register: update_2
- name: Cleanup - name: Cleanup
docker_plugin: docker_plugin:
plugin_name: "{{ plugin_name }}" plugin_name: "{{ plugin_name }}"
state: absent state: absent
force_remove: true force_remove: true
- assert:
that:
- create_1 is changed
- create_2 is not changed
- update_1 is changed
- update_2 is not changed