Skip to content

Commit

Permalink
tools/scylla-nodetool: return 1 when viewbuild not succeeds
Browse files Browse the repository at this point in the history
this change introduces a new exception which carries the status code
so that an operation can return a non-zero exit code without printing
any errors. this mimics the behavior of "viewbuildstatus" command of
C* nodetool.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb#17359
  • Loading branch information
tchaikov authored and denesb committed Feb 16, 2024
1 parent eedb997 commit 47fec04
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 4 additions & 9 deletions test/nodetool/test_viewbuildstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,11 @@ def test_viewbuildstatus(request, nodetool, args, statuses, returncode):
assert exc_info.value.stdout == expected_stdout
assert expected_stderr in exc_info.value.stderr
else:
if is_scylla:
# scylla nodetool does not return status code of 1 if not all building are finished
with pytest.raises(CalledProcessError) as exc_info:
actual_output = nodetool("viewbuildstatus", *args, expected_requests=expected_requests)
assert actual_output == expected_output
else:
with pytest.raises(CalledProcessError) as exc_info:
actual_output = nodetool("viewbuildstatus", *args, expected_requests=expected_requests)
assert exc_info.type is CalledProcessError
assert exc_info.value.returncode == 1
assert exc_info.value.output == expected_output
assert exc_info.type is CalledProcessError
assert exc_info.value.returncode == 1
assert exc_info.value.output == expected_output
else:
actual_output = nodetool("viewbuildstatus", *args, expected_requests=expected_requests)
assert actual_output == expected_output
12 changes: 11 additions & 1 deletion tools/scylla-nodetool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ struct operation_failed_on_scylladb : public std::runtime_error {
using std::runtime_error::runtime_error;
};

struct operation_failed_with_status : public std::runtime_error {
const int exit_status;
explicit operation_failed_with_status(int status)
: std::runtime_error::runtime_error("exit")
, exit_status(status)
{}
};

struct api_request_failed : public std::runtime_error {
using std::runtime_error::runtime_error;
};
Expand Down Expand Up @@ -1083,7 +1091,7 @@ void viewbuildstatus_operation(scylla_rest_client& client, const bpo::variables_
fmt::print("{}.{} has not finished building; node status is below.\n", keyspace, view);
fmt::print("\n");
table.print();
// TODO: should return with status code of 1 in this case
throw operation_failed_with_status(1);
}
}

Expand Down Expand Up @@ -1818,6 +1826,8 @@ For more information, see: https://opensource.docs.scylladb.com/stable/operating
} catch (api_request_failed& e) {
fmt::print(std::cerr, "{}\n", e.what());
return 4;
} catch (operation_failed_with_status& e) {
return e.exit_status;
} catch (...) {
fmt::print(std::cerr, "error running operation: {}\n", std::current_exception());
return 2;
Expand Down

0 comments on commit 47fec04

Please sign in to comment.