fix erroneous failures in docker_compose due to deprecation warnings … (#61650)

* 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 <felix@fontein.de>

* update error handling

* fix syntax error

* fix indentation

* fix indentation (again)

* remove erroneous line
This commit is contained in:
Scott Luther 2019-09-04 10:34:05 -07:00 committed by Felix Fontein
parent d5c8d325e4
commit 0c73e47a42
2 changed files with 38 additions and 8 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "docker_compose - fix issue where docker deprecation warning results in ansible erroneously reporting a failure"

View file

@ -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:
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:
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:
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:
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