]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: make remote_executables test able to handle ast.BinOp
authorAdam King <adking@redhat.com>
Wed, 17 Apr 2024 14:07:09 +0000 (10:07 -0400)
committerAdam King <adking@redhat.com>
Mon, 22 Apr 2024 20:14:57 +0000 (16:14 -0400)
Was adding a line to serve.py that did

if ((datetime_now() - t).total_seconds() < 60)

and this was causing the remote_executables test to fail with

ValueError: _names: unexpected type: <ast.BinOp object at 0x7f0985c8d670>

where it seems the (datetime_now() - t) was resolving to an
ast.BinOp node which had no case in _names.

This patch makes it so the remote_executables test can also
handle these BinOp nodes and the binary operations that
could be within the node

Signed-off-by: Adam King <adking@redhat.com>
src/pybind/mgr/cephadm/tests/test_remote_executables.py

index a98f81a8df1edb2d73ee9832e2d2b9680669d9bd..9d5bd458254c316aaf70499e973d58dd01c4c4b0 100644 (file)
@@ -102,6 +102,24 @@ def _names(node):
         return [f"<JoinedStr: {node.values!r}>"]
     if isinstance(node, ast.Subscript):
         return [f"<Subscript: {node.value}{node.slice}>"]
+    if isinstance(node, ast.BinOp):
+        return [f"<BinaryOp: {_names(node.left)} {_names(node.op)} {_names(node.right)}"]
+    if (
+        isinstance(node, ast.Add)
+        or isinstance(node, ast.Sub)
+        or isinstance(node, ast.Mult)
+        or isinstance(node, ast.Div)
+        or isinstance(node, ast.FloorDiv)
+        or isinstance(node, ast.Mod)
+        or isinstance(node, ast.Pow)
+        or isinstance(node, ast.LShift)
+        or isinstance(node, ast.RShift)
+        or isinstance(node, ast.ButOr)
+        or isinstance(node, ast.BitXor)
+        or isinstance(node, ast.BitAnd)
+        or isinstance(node, ast.MatMult)
+    ):
+        return [repr(node)]
     raise ValueError(f"_names: unexpected type: {node}")