From: Rishabh Dave Date: Thu, 25 Aug 2022 17:26:26 +0000 (+0530) Subject: qa/cephfs: handle non-numeric values for json.loads() X-Git-Tag: v18.1.0~1032^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=38fdf6df664e7fc28f1e381ce1bb590fc74926ae;p=ceph.git qa/cephfs: handle non-numeric values for json.loads() Not handling values infinity, negative infinity and "NaN" properly leads to JSONDecodeError. Replace "inf" by "Infinity" in string before loading JSON and pass a method to json.load() to handle these values to fix this issue. Introduced-by: a8f138cd3623e42c4f74a18d54ec7dfcc1e89e58 Fixes: https://tracker.ceph.com/issues/57299 Signed-off-by: Rishabh Dave --- diff --git a/qa/tasks/cephfs/filesystem.py b/qa/tasks/cephfs/filesystem.py index 354583e047e3..d1c9a7be87d7 100644 --- a/qa/tasks/cephfs/filesystem.py +++ b/qa/tasks/cephfs/filesystem.py @@ -255,7 +255,14 @@ class CephCluster(object): proc = self.mon_manager.admin_socket(service_type, service_id, command, timeout=timeout) response_data = proc.stdout.getvalue().strip() if len(response_data) > 0: - j = json.loads(response_data) + + def get_nonnumeric_values(value): + c = {"NaN": float("nan"), "Infinity": float("inf"), + "-Infinity": -float("inf")} + return c[value] + + j = json.loads(response_data.replace('inf', 'Infinity'), + parse_constant=get_nonnumeric_values) pretty = json.dumps(j, sort_keys=True, indent=2) log.debug(f"_json_asok output\n{pretty}") return j