From 0c73e47a42f69901ea892f9d0e58acb554f4e668 Mon Sep 17 00:00:00 2001 From: Scott Luther Date: Wed, 4 Sep 2019 10:34:05 -0700 Subject: [PATCH] =?UTF-8?q?fix=20erroneous=20failures=20in=20docker=5Fcomp?= =?UTF-8?q?ose=20due=20to=20deprecation=20warnings=20=E2=80=A6=20(#61650)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix erroneous failures in docker_compose due to deprecation warnings from docker (#60961) * Update error handling to work with new method of capturing output Co-Authored-By: Felix Fontein * update error handling * fix syntax error * fix indentation * fix indentation (again) * remove erroneous line --- ...docker_compose-fix-deprecation-warning.yml | 2 + .../modules/cloud/docker/docker_compose.py | 44 +++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/60961-docker_compose-fix-deprecation-warning.yml diff --git a/changelogs/fragments/60961-docker_compose-fix-deprecation-warning.yml b/changelogs/fragments/60961-docker_compose-fix-deprecation-warning.yml new file mode 100644 index 00000000000..7168a8c28d0 --- /dev/null +++ b/changelogs/fragments/60961-docker_compose-fix-deprecation-warning.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_compose - fix issue where docker deprecation warning results in ansible erroneously reporting a failure" diff --git a/lib/ansible/modules/cloud/docker/docker_compose.py b/lib/ansible/modules/cloud/docker/docker_compose.py index dce98018f3a..a9c4488442b 100644 --- a/lib/ansible/modules/cloud/docker/docker_compose.py +++ b/lib/ansible/modules/cloud/docker/docker_compose.py @@ -886,11 +886,18 @@ class ContainerManager(DockerBaseClass): except Exception as exc: self.client.fail("Error: service image lookup failed - %s" % str(exc)) + out_redir_name, err_redir_name = make_redirection_tempfiles() # pull the image try: - service.pull(ignore_pull_failures=False) + with stdout_redirector(out_redir_name): + with stderr_redirector(err_redir_name): + service.pull(ignore_pull_failures=False) except Exception as exc: - self.client.fail("Error: pull failed with %s" % str(exc)) + fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, + msg_format="Error: pull failed with %s") + self.client.fail(**fail_reason) + else: + cleanup_redirection_tempfiles(out_redir_name, err_redir_name) # store the new image ID new_image_id = '' @@ -933,11 +940,18 @@ class ContainerManager(DockerBaseClass): except Exception as exc: self.client.fail("Error: service image lookup failed - %s" % str(exc)) + out_redir_name, err_redir_name = make_redirection_tempfiles() # build the image try: - new_image_id = service.build(pull=self.pull, no_cache=self.nocache) + with stdout_redirector(out_redir_name): + with stderr_redirector(err_redir_name): + new_image_id = service.build(pull=self.pull, no_cache=self.nocache) except Exception as exc: - self.client.fail("Error: build failed with %s" % str(exc)) + fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, + msg_format="Error: build failed with %s") + self.client.fail(**fail_reason) + else: + cleanup_redirection_tempfiles(out_redir_name, err_redir_name) if new_image_id not in old_image_id: # if a new image was built @@ -966,10 +980,17 @@ class ContainerManager(DockerBaseClass): )) if not self.check_mode and result['changed']: image_type = image_type_from_opt('--rmi', self.remove_images) + out_redir_name, err_redir_name = make_redirection_tempfiles() try: - self.project.down(image_type, self.remove_volumes, self.remove_orphans) + with stdout_redirector(out_redir_name): + with stderr_redirector(err_redir_name): + self.project.down(image_type, self.remove_volumes, self.remove_orphans) except Exception as exc: - self.client.fail("Error stopping project - %s" % str(exc)) + fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, + msg_format="Error stopping project - %s") + self.client.fail(**fail_reason) + else: + cleanup_redirection_tempfiles(out_redir_name, err_redir_name) return result def cmd_stop(self, service_names): @@ -1057,10 +1078,17 @@ class ContainerManager(DockerBaseClass): result['changed'] = True service_res['scale'] = scale - len(containers) if not self.check_mode: + out_redir_name, err_redir_name = make_redirection_tempfiles() try: - service.scale(scale) + with stdout_redirector(out_redir_name): + with stderr_redirector(err_redir_name): + service.scale(scale) except Exception as exc: - self.client.fail("Error scaling %s - %s" % (service.name, str(exc))) + fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, + msg_format="Error scaling {0} - %s".format(service.name)) + self.client.fail(**fail_reason) + else: + cleanup_redirection_tempfiles(out_redir_name, err_redir_name) result['actions'].append(service_res) return result