Skip to content

RemoteOperations::exec_command must not raise an exception when 'expect_error' is True (#159) #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
RemoteOperations::exec_command must not raise an exception when 'expe…
…ct_error' is True (#159)

This commit fixes an issue #159.
  • Loading branch information
dmitry-lipetsk committed Dec 7, 2024
commit 45cfbf738e1f5d7f46f8ab053f4a6a481abf53e7
28 changes: 14 additions & 14 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,

exit_status = process.returncode

if encoding:
result = result.decode(encoding)
error = error.decode(encoding)

if expect_error:
raise Exception(result, error)
assert type(result) == bytes # noqa: E721
assert type(error) == bytes # noqa: E721

if not error:
error_found = 0
error_found = False
else:
error = normalize_error(error)
error_found = exit_status != 0 or any(
marker in error for marker in ['error', 'Permission denied', 'fatal', 'No such file or directory']
marker in error for marker in [b'error', b'Permission denied', b'fatal', b'No such file or directory']
)

if not ignore_errors and error_found:
if isinstance(error, bytes):
message = b"Utility exited with non-zero code. Error: " + error
else:
message = f"Utility exited with non-zero code. Error: {error}"
assert type(error_found) == bool # noqa: E721

if encoding:
result = result.decode(encoding)
error = error.decode(encoding)

if not ignore_errors and error_found and not expect_error:
error = normalize_error(error)
assert type(error) == str # noqa: E721
message = "Utility exited with non-zero code. Error: " + error
raise ExecUtilException(message=message, command=cmd, exit_code=exit_status, out=result)

if verbose:
Expand Down