diff --git a/ccmlib/node.py b/ccmlib/node.py index 6245830d..7b9dce3d 100644 --- a/ccmlib/node.py +++ b/ccmlib/node.py @@ -78,6 +78,9 @@ def __decode(self, value): # Groups: 0 = ks, 1 = cf, 2 = tmp or none, 3 = version, 4 = identifier (generation), 4 = "big-" or none, 5 = suffix (Compacted or Data.db) _sstable_regexp = re.compile(r'((?P[^\s-]+)-(?P[^\s-]+)-)?(?Ptmp(link)?-)?(?P[^\s-]+)-(?P[^-]+)-(?Pbig-)?(?P[a-zA-Z]+)\.[a-zA-Z0-9]+$') +# Regexes for parsing nodetool compactionstats +_pending_tasks_pattern = re.compile(r'- (?P\w+)\.(?P\w+): (?P\d+)') +_active_tasks_pattern = re.compile(r'\s*([\w-]+)\s+\w+\s+(?P\w+)\s+(?P\w+)\s+\d+\s+\d+\s+\w+\s+\d+\.\d+%') class Node(object): @@ -763,14 +766,12 @@ def _parse_tasks(output: str, keyspace: str, column_family: str): """ lines = output.strip().splitlines() tasks = defaultdict(int) - pending_tasks_pattern = re.compile(r'- (?P\w+)\.(?P\w+): (?P\d+)') - active_tasks_pattern = re.compile(r'\s*([\w-]+)\s+\w+\s+(?P\w+)\s+(?P\w+)\s+\d+\s+\d+\s+\w+\s+\d+\.\d+%') for line in lines: line = line.strip() - if match := pending_tasks_pattern.match(line): + if match := _pending_tasks_pattern.match(line): tasks[(match.group("ks"), match.group("cf"))] += int(match.group("tasks")) - elif match := active_tasks_pattern.match(line): + elif match := _active_tasks_pattern.match(line): tasks[(match.group("ks"), match.group("cf"))] += 1 if keyspace is None and column_family is None: @@ -786,8 +787,8 @@ def wait_for_compactions(self, keyspace: str=None, column_family: str=None, idle :param keyspace: only wait for the compactions performed for specified keyspace. If not specified, all keyspaces are waited. Must be provided if collumn_family is provided. - :param column_family: only wait for the compactions performed for specified column_family. - If not specified, all keyspaces are waited. + :param column_family: only wait for the compactions performed for specified column family. + If not specified, all column families are waited. :param idle_timeout: the time in seconds to wait for progress. Total time to wait is undeteremined, as long as we observe forward progress. """ diff --git a/tests/test_internal_functions.py b/tests/test_internal_functions.py index 76ca06fb..f69497e1 100644 --- a/tests/test_internal_functions.py +++ b/tests/test_internal_functions.py @@ -85,11 +85,8 @@ } ] -@pytest.mark.parametrize("test_case", test_cases, ids=[tc["id"] for tc in test_cases]) -def test_parse_tasks(test_case): - output = test_case["output"] - expected_tasks = test_case["expected_tasks"] - +@pytest.mark.parametrize("output, expected_tasks", [pytest.param(t["output"], t["expected_tasks"], id=t["id"]) for t in test_cases]) +def test_parse_tasks(output, expected_tasks): for ks, cf, expected in expected_tasks: n = Node._parse_tasks(output, ks, cf) assert n == expected, f"Expected {expected} tasks for {ks}.{cf}, but got {n}"