summaryrefslogtreecommitdiffstats
path: root/src/spdk/test/spdkcli/spdkcli_job.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/spdk/test/spdkcli/spdkcli_job.py
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/spdk/test/spdkcli/spdkcli_job.py')
-rwxr-xr-xsrc/spdk/test/spdkcli/spdkcli_job.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/spdk/test/spdkcli/spdkcli_job.py b/src/spdk/test/spdkcli/spdkcli_job.py
new file mode 100755
index 000000000..ce6530a90
--- /dev/null
+++ b/src/spdk/test/spdkcli/spdkcli_job.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+import pexpect
+import os
+import sys
+import re
+
+
+def execute_command(cmd, element=None, element_exists=False):
+ child.sendline(cmd)
+ child.expect("/>")
+ if "error response" in child.before.decode():
+ print("Error in cmd: %s" % cmd)
+ exit(1)
+ ls_tree = cmd.split(" ")[0]
+ if ls_tree and element:
+ child.sendline("ls %s" % ls_tree)
+ child.expect("/>")
+ if element_exists:
+ if element not in child.before.decode():
+ print("Element %s not in list:\n%s" % (element, child.before.decode()))
+ exit(1)
+ else:
+ if element in child.before.decode():
+ print("Element %s is in list:\n%s" % (element, child.before.decode()))
+ exit(1)
+
+
+if __name__ == "__main__":
+ socket = "/var/tmp/spdk.sock"
+ port = None
+ if len(sys.argv) == 3:
+ socket = sys.argv[2]
+ elif len(sys.argv) == 4:
+ port = sys.argv[3]
+ testdir = os.path.dirname(os.path.realpath(sys.argv[0]))
+
+ if port is None:
+ child = pexpect.spawn(os.path.join(testdir, "../../scripts/spdkcli.py") + " -s %s" % socket)
+ else:
+ child = pexpect.spawn(os.path.join(testdir, "../../scripts/spdkcli.py") + " -s %s -p %s" % (socket, port))
+ child.expect(">")
+ child.sendline("cd /")
+ child.expect("/>")
+
+ cmd_lines = sys.argv[1].strip().split("\n")
+ for line in cmd_lines:
+ data = line.strip()
+ p = re.compile('\'(.*?)\'')
+ cmd = p.findall(data)
+ if data[-1] != "\'":
+ cmd.append(data.rsplit(" ", 1)[1].strip())
+ if cmd[-1] == "False":
+ cmd[-1] = False
+ else:
+ cmd[-1] = True
+ else:
+ cmd.append(False)
+ print("Executing command: %s" % cmd)
+ execute_command(*cmd[0:3])