From e4cc609b726c16475a841ecaea501fc9a0325f58 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Sun, 17 Dec 2023 12:57:46 +0200 Subject: [PATCH] node: stress_object: ignore commas in numbers Some resharding_test dtest, e.g. `test_resharding_counter` fails locally for me: ``` def _run_stress(self, op_cnt, stress_cmd): res = self.node.stress_object(stress_cmd) if not isinstance(res, dict): raise Exception('Error running cassandra-stress: {}'.format(res)) assert res['total errors'] == 0 > assert res['total partitions'] >= op_cnt E assert 10.0 >= 10000 ``` When printing the cassandra-stress stdout I saw that it uses a comma as a 1000s separator: ``` Total partitions : 10,000 [COUNTER_READ: 10,000] ``` This is probably related to the LOCALE on my machine. This change removes any commas from the value in _set_stress_val before converting it to `float` using `locale.atof`. Signed-off-by: Benny Halevy --- ccmlib/node.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ccmlib/node.py b/ccmlib/node.py index f858b07c..5b39ceaa 100644 --- a/ccmlib/node.py +++ b/ccmlib/node.py @@ -1383,22 +1383,24 @@ def _set_keyspace_initial_tablets(stress_options: List[str], initial_tablets:int def _set_stress_val(key, val, res): # Set locale to the user's default value (usually specified in the LANG) locale.setlocale(locale.LC_NUMERIC, '') + def atof(v): + return locale.atof(v.replace(',', '')) if "[" in val: p = re.compile(r'^\s*([\d\.\,]+\d?)\s*\[.*') m = p.match(val) if m: - res[key] = locale.atof(m.group(1)) + res[key] = atof(m.group(1)) p = re.compile(r'^.*READ:\s*([\d\.\,]+\d?)[^\d].*') m = p.match(val) if m: - res[key + ":read"] = locale.atof(m.group(1)) + res[key + ":read"] = atof(m.group(1)) p = re.compile(r'.*WRITE:\s*([\d\.\,]+\d?)[^\d].*') m = p.match(val) if m: - res[key + ":write"] = locale.atof(m.group(1)) + res[key + ":write"] = atof(m.group(1)) else: try: - res[key] = locale.atof(val) + res[key] = atof(val) except ValueError: res[key] = val @@ -1408,6 +1410,9 @@ def stress_object(self, stress_options=None, ignore_errors=None, **kwargs): ret = self.stress(stress_options, **kwargs) p = re.compile(r'^\s*([^:]+)\s*:\s*(\S.*)\s*$') res = {} + res['stdout'] = ret.stdout + res['stderr'] = ret.stderr + res['rc'] = ret.rc start = False for line in [s.strip() for s in ret.stdout.splitlines()]: if start: