Skip to content

Commit

Permalink
feature(scylla_args): publish event when wrong argument faced
Browse files Browse the repository at this point in the history
  • Loading branch information
dkropachev authored and Bentsi committed Jun 28, 2021
1 parent 8356182 commit ae8e4c8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions defaults/severities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ DataValidatorEvent.ImmutableRowsValidator: ERROR
DataValidatorEvent.UpdatedRowsValidator: WARNING
DataValidatorEvent.DeletedRowsValidator: ERROR
ScyllaHelpErrorEvent.duplicate: ERROR
ScyllaHelpErrorEvent.filtered: ERROR
FullScanEvent.start: NORMAL
FullScanEvent.finish: ERROR
DatabaseLogEvent.NO_SPACE_ERROR: ERROR
Expand Down
7 changes: 6 additions & 1 deletion sdcm/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,12 @@ def config_setup(self,
message=f"Scylla help contains duplicate for the following arguments: {','.join(dups)}"
).publish()
)
append_scylla_args = scylla_arg_parser.filter_args(append_scylla_args)
append_scylla_args = scylla_arg_parser.filter_args(
append_scylla_args,
unknown_args_cb=lambda args: ScyllaHelpErrorEvent.filtered(
message="Following arguments are filtered out: " + ','.join(args)
).publish()
)
if self.parent_cluster.params.get('db_nodes_shards_selection') == 'random':
append_scylla_args += f" --smp {self.scylla_random_shards()}"

Expand Down
2 changes: 2 additions & 0 deletions sdcm/sct_events/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def add_info(self: T_log_event, node, line: str, line_number: int) -> T_log_even

class ScyllaHelpErrorEvent(SctEvent, abstract=True):
duplicate: Type[SctEventProtocol]
filtered: Type[SctEventProtocol]
message: str

def __init__(self, message: Optional[str] = None, severity=Severity.ERROR):
Expand All @@ -175,6 +176,7 @@ def msgfmt(self):


ScyllaHelpErrorEvent.add_subevent_type("duplicate")
ScyllaHelpErrorEvent.add_subevent_type("filtered")


class FullScanEvent(SctEvent, abstract=True):
Expand Down
6 changes: 3 additions & 3 deletions sdcm/utils/scylla_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def from_scylla_help(cls, help: Text, duplicate_cb: Callable = None) -> "ScyllaA

return parser

def filter_args(self, args: str) -> str:
def filter_args(self, args: str, unknown_args_cb: Callable = None) -> str:
parsed_args, unknown_args = self.parse_known_args(args.split())
if unknown_args:
LOGGER.warning("Following arguments are filtered out: %s", unknown_args)
if unknown_args and unknown_args_cb:
unknown_args_cb(unknown_args)
filtered_args = []
for arg, val in vars(parsed_args).items():
filtered_args.append(f"--{arg.replace('_', '-')}")
Expand Down
9 changes: 7 additions & 2 deletions unit_tests/test_utils_scylla_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ def test_double_args(self):
)

def test_filter_args(self):
self.assertEqual(self.parser.filter_args("--arg1 arg --version -W arg --arg2 -h --options-file arg"),
"--version --workdir arg --help --options-file arg")
self.assertEqual(
self.parser.filter_args(
"--arg1 arg --version -W arg --arg2 -h --options-file arg",
unknown_args_cb=lambda args: self.assertEqual(['--arg1', 'arg', '--arg2'], args)
),
"--version --workdir arg --help --options-file arg",
)

def test_filter_args_unchanged(self):
args = "--version --workdir arg --help --options-file arg"
Expand Down

0 comments on commit ae8e4c8

Please sign in to comment.