From 38fdf6df664e7fc28f1e381ce1bb590fc74926ae Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Thu, 25 Aug 2022 22:56:26 +0530 Subject: [PATCH] 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 --- qa/tasks/cephfs/filesystem.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 -- 2.47.3