* 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
(cherry picked from commit 0c73e47a42f69901ea892f9d0e58acb554f4e668)
... | ... |
@@ -886,11 +886,18 @@ class ContainerManager(DockerBaseClass): |
886 | 886 |
except Exception as exc: |
887 | 887 |
self.client.fail("Error: service image lookup failed - %s" % str(exc)) |
888 | 888 |
|
889 |
+ out_redir_name, err_redir_name = make_redirection_tempfiles() |
|
889 | 890 |
# pull the image |
890 | 891 |
try: |
891 |
- service.pull(ignore_pull_failures=False) |
|
892 |
+ with stdout_redirector(out_redir_name): |
|
893 |
+ with stderr_redirector(err_redir_name): |
|
894 |
+ service.pull(ignore_pull_failures=False) |
|
892 | 895 |
except Exception as exc: |
893 |
- self.client.fail("Error: pull failed with %s" % str(exc)) |
|
896 |
+ fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, |
|
897 |
+ msg_format="Error: pull failed with %s") |
|
898 |
+ self.client.fail(**fail_reason) |
|
899 |
+ else: |
|
900 |
+ cleanup_redirection_tempfiles(out_redir_name, err_redir_name) |
|
894 | 901 |
|
895 | 902 |
# store the new image ID |
896 | 903 |
new_image_id = '' |
... | ... |
@@ -933,11 +940,18 @@ class ContainerManager(DockerBaseClass): |
933 | 933 |
except Exception as exc: |
934 | 934 |
self.client.fail("Error: service image lookup failed - %s" % str(exc)) |
935 | 935 |
|
936 |
+ out_redir_name, err_redir_name = make_redirection_tempfiles() |
|
936 | 937 |
# build the image |
937 | 938 |
try: |
938 |
- new_image_id = service.build(pull=self.pull, no_cache=self.nocache) |
|
939 |
+ with stdout_redirector(out_redir_name): |
|
940 |
+ with stderr_redirector(err_redir_name): |
|
941 |
+ new_image_id = service.build(pull=self.pull, no_cache=self.nocache) |
|
939 | 942 |
except Exception as exc: |
940 |
- self.client.fail("Error: build failed with %s" % str(exc)) |
|
943 |
+ fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, |
|
944 |
+ msg_format="Error: build failed with %s") |
|
945 |
+ self.client.fail(**fail_reason) |
|
946 |
+ else: |
|
947 |
+ cleanup_redirection_tempfiles(out_redir_name, err_redir_name) |
|
941 | 948 |
|
942 | 949 |
if new_image_id not in old_image_id: |
943 | 950 |
# if a new image was built |
... | ... |
@@ -966,10 +980,17 @@ class ContainerManager(DockerBaseClass): |
966 | 966 |
)) |
967 | 967 |
if not self.check_mode and result['changed']: |
968 | 968 |
image_type = image_type_from_opt('--rmi', self.remove_images) |
969 |
+ out_redir_name, err_redir_name = make_redirection_tempfiles() |
|
969 | 970 |
try: |
970 |
- self.project.down(image_type, self.remove_volumes, self.remove_orphans) |
|
971 |
+ with stdout_redirector(out_redir_name): |
|
972 |
+ with stderr_redirector(err_redir_name): |
|
973 |
+ self.project.down(image_type, self.remove_volumes, self.remove_orphans) |
|
971 | 974 |
except Exception as exc: |
972 |
- self.client.fail("Error stopping project - %s" % str(exc)) |
|
975 |
+ fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, |
|
976 |
+ msg_format="Error stopping project - %s") |
|
977 |
+ self.client.fail(**fail_reason) |
|
978 |
+ else: |
|
979 |
+ cleanup_redirection_tempfiles(out_redir_name, err_redir_name) |
|
973 | 980 |
return result |
974 | 981 |
|
975 | 982 |
def cmd_stop(self, service_names): |
... | ... |
@@ -1057,10 +1078,17 @@ class ContainerManager(DockerBaseClass): |
1057 | 1057 |
result['changed'] = True |
1058 | 1058 |
service_res['scale'] = scale - len(containers) |
1059 | 1059 |
if not self.check_mode: |
1060 |
+ out_redir_name, err_redir_name = make_redirection_tempfiles() |
|
1060 | 1061 |
try: |
1061 |
- service.scale(scale) |
|
1062 |
+ with stdout_redirector(out_redir_name): |
|
1063 |
+ with stderr_redirector(err_redir_name): |
|
1064 |
+ service.scale(scale) |
|
1062 | 1065 |
except Exception as exc: |
1063 |
- self.client.fail("Error scaling %s - %s" % (service.name, str(exc))) |
|
1066 |
+ fail_reason = get_failure_info(exc, out_redir_name, err_redir_name, |
|
1067 |
+ msg_format="Error scaling {0} - %s".format(service.name)) |
|
1068 |
+ self.client.fail(**fail_reason) |
|
1069 |
+ else: |
|
1070 |
+ cleanup_redirection_tempfiles(out_redir_name, err_redir_name) |
|
1064 | 1071 |
result['actions'].append(service_res) |
1065 | 1072 |
return result |
1066 | 1073 |
|