docker_plugin: do not crash when plugin doesn't exist (#553)

* Do not crash when plugin doesn't exist.

* Improve style.

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
This commit is contained in:
Felix Fontein
2023-01-13 20:49:06 +01:00
committed by GitHub
parent 01429108d3
commit c7cbec0163
3 changed files with 74 additions and 1 deletions
+8 -1
View File
@@ -346,11 +346,18 @@ class DockerPluginManager(object):
@property
def result(self):
plugin_data = {}
if self.parameters.state != 'absent':
try:
plugin_data = self.client.get_json('/plugins/{0}/json', self.preferred_name)
except NotFound:
# This can happen in check mode
pass
result = {
'actions': self.actions,
'changed': self.changed,
'diff': self.diff,
'plugin': self.client.get_json('/plugins/{0}/json', self.preferred_name) if self.parameters.state != 'absent' else {}
'plugin': plugin_data,
}
return dict((k, v) for k, v in result.items() if v is not None)