diff options
author | Guillaume Chauvel <guillaume.chauvel@gmail.com> | 2020-06-13 19:21:56 +0200 |
---|---|---|
committer | Guillaume CHAUVEL <guillaume.chauvel@gmail.com> | 2022-06-17 21:26:08 +0200 |
commit | 6a53da691fbf6470b2f092b70e2f3b52b70eb98a (patch) | |
tree | 75d7c80ef03dcfc45d4e52c2ba82c73cfb805ca2 /zuul/ansible | |
parent | c5b55e59c8644060f01137e8d771777c6b5d56dc (diff) | |
download | zuul-6a53da691fbf6470b2f092b70e2f3b52b70eb98a.tar.gz |
Fix zuul_run_command ret when command is not found
If the command didn't exist:
- Popen would throw an exception
- 't' would not be updated (t is None)
- return code would not be written to the console
- zuul_stream would wait unecessary for 10 seconds
As rc is defined in normal case or in both exceptions, it can be written
in each case to the console.
Change-Id: I77a4e1bdc6cd163143eacda06555b62c9195ee38
Diffstat (limited to 'zuul/ansible')
-rwxr-xr-x | zuul/ansible/2.8/library/command.py | 21 | ||||
-rwxr-xr-x | zuul/ansible/2.9/library/command.py | 21 | ||||
-rwxr-xr-x | zuul/ansible/base/library/command.py | 21 |
3 files changed, 30 insertions, 33 deletions
diff --git a/zuul/ansible/2.8/library/command.py b/zuul/ansible/2.8/library/command.py index f4511ad18..26830e4a7 100755 --- a/zuul/ansible/2.8/library/command.py +++ b/zuul/ansible/2.8/library/command.py @@ -493,17 +493,16 @@ def zuul_run_command(self, args, zuul_log_id, check_rc=False, close_fds=True, ex # ZUUL: store fail_json_kwargs and fail later in finally fail_json_kwargs = dict(rc=257, msg=to_native(e), exception=traceback.format_exc(), cmd=clean_args) finally: - if t: - with Console(zuul_log_id) as console: - if t.is_alive(): - console.addLine("[Zuul] standard output/error still open " - "after child exited") - if fail_json_kwargs: - # we hit an exception and need to use the rc from - # fail_json_kwargs - rc = fail_json_kwargs['rc'] - - console.addLine("[Zuul] Task exit code: %s\n" % rc) + with Console(zuul_log_id) as console: + if t and t.is_alive(): + console.addLine("[Zuul] standard output/error still open " + "after child exited") + if fail_json_kwargs: + # we hit an exception and need to use the rc from + # fail_json_kwargs + rc = fail_json_kwargs['rc'] + + console.addLine("[Zuul] Task exit code: %s\n" % rc) if fail_json_kwargs: self.fail_json(**fail_json_kwargs) diff --git a/zuul/ansible/2.9/library/command.py b/zuul/ansible/2.9/library/command.py index f4511ad18..26830e4a7 100755 --- a/zuul/ansible/2.9/library/command.py +++ b/zuul/ansible/2.9/library/command.py @@ -493,17 +493,16 @@ def zuul_run_command(self, args, zuul_log_id, check_rc=False, close_fds=True, ex # ZUUL: store fail_json_kwargs and fail later in finally fail_json_kwargs = dict(rc=257, msg=to_native(e), exception=traceback.format_exc(), cmd=clean_args) finally: - if t: - with Console(zuul_log_id) as console: - if t.is_alive(): - console.addLine("[Zuul] standard output/error still open " - "after child exited") - if fail_json_kwargs: - # we hit an exception and need to use the rc from - # fail_json_kwargs - rc = fail_json_kwargs['rc'] - - console.addLine("[Zuul] Task exit code: %s\n" % rc) + with Console(zuul_log_id) as console: + if t and t.is_alive(): + console.addLine("[Zuul] standard output/error still open " + "after child exited") + if fail_json_kwargs: + # we hit an exception and need to use the rc from + # fail_json_kwargs + rc = fail_json_kwargs['rc'] + + console.addLine("[Zuul] Task exit code: %s\n" % rc) if fail_json_kwargs: self.fail_json(**fail_json_kwargs) diff --git a/zuul/ansible/base/library/command.py b/zuul/ansible/base/library/command.py index ced439747..d496b037c 100755 --- a/zuul/ansible/base/library/command.py +++ b/zuul/ansible/base/library/command.py @@ -545,17 +545,16 @@ def zuul_run_command(self, args, zuul_log_id, check_rc=False, close_fds=True, ex # ZUUL: store fail_json_kwargs and fail later in finally fail_json_kwargs = dict(rc=257, stdout=b'', stderr=b'', msg=to_native(e), exception=traceback.format_exc(), cmd=self._clean_args(args)) finally: - if t: - with Console(zuul_log_id) as console: - if t.is_alive(): - console.addLine("[Zuul] standard output/error still open " - "after child exited") - if fail_json_kwargs: - # we hit an exception and need to use the rc from - # fail_json_kwargs - rc = fail_json_kwargs['rc'] - - console.addLine("[Zuul] Task exit code: %s\n" % rc) + with Console(zuul_log_id) as console: + if t and t.is_alive(): + console.addLine("[Zuul] standard output/error still open " + "after child exited") + if fail_json_kwargs: + # we hit an exception and need to use the rc from + # fail_json_kwargs + rc = fail_json_kwargs['rc'] + + console.addLine("[Zuul] Task exit code: %s\n" % rc) if fail_json_kwargs: self.fail_json(**fail_json_kwargs) |