]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: handle non-numeric values for json.loads() 54187/head
authorRishabh Dave <ridave@redhat.com>
Thu, 25 Aug 2022 17:26:26 +0000 (22:56 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 25 Oct 2023 11:59:53 +0000 (17:29 +0530)
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 <ridave@redhat.com>
(cherry picked from commit 38fdf6df664e7fc28f1e381ce1bb590fc74926ae)

qa/tasks/cephfs/filesystem.py

index 269a818a41cd2c3fea78939784d89cee944bae71..1ea82b5aa0e6331b7d2a12019037250cb297f34c 100644 (file)
@@ -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