]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/usr/bin/env python3 |
2 | import pexpect | |
3 | import os | |
4 | import sys | |
9f95a23c | 5 | import re |
11fdf7f2 TL |
6 | |
7 | ||
8 | def execute_command(cmd, element=None, element_exists=False): | |
9 | child.sendline(cmd) | |
10 | child.expect("/>") | |
11 | if "error response" in child.before.decode(): | |
12 | print("Error in cmd: %s" % cmd) | |
13 | exit(1) | |
14 | ls_tree = cmd.split(" ")[0] | |
15 | if ls_tree and element: | |
16 | child.sendline("ls %s" % ls_tree) | |
17 | child.expect("/>") | |
18 | print("child: %s" % child.before.decode()) | |
19 | if element_exists: | |
20 | if element not in child.before.decode(): | |
21 | print("Element %s not in list" % element) | |
22 | exit(1) | |
23 | else: | |
24 | if element in child.before.decode(): | |
25 | print("Element %s is in list" % element) | |
26 | exit(1) | |
27 | ||
28 | ||
29 | if __name__ == "__main__": | |
30 | socket = "/var/tmp/spdk.sock" | |
9f95a23c TL |
31 | if len(sys.argv) == 3: |
32 | socket = sys.argv[2] | |
11fdf7f2 TL |
33 | testdir = os.path.dirname(os.path.realpath(sys.argv[0])) |
34 | child = pexpect.spawn(os.path.join(testdir, "../../scripts/spdkcli.py") + " -s %s" % socket) | |
35 | child.expect(">") | |
36 | child.sendline("cd /") | |
37 | child.expect("/>") | |
38 | ||
9f95a23c TL |
39 | cmd_lines = sys.argv[1].strip().split("\n") |
40 | for line in cmd_lines: | |
41 | data = line.strip() | |
42 | p = re.compile('\'(.*?)\'') | |
43 | cmd = p.findall(data) | |
44 | if data[-1] != "\'": | |
45 | cmd.append(data.rsplit(" ", 1)[1].strip()) | |
46 | if cmd[-1] == "False": | |
47 | cmd[-1] = False | |
48 | else: | |
49 | cmd[-1] = True | |
50 | else: | |
51 | cmd.append(False) | |
52 | print("Executing command: %s" % cmd) | |
53 | execute_command(*cmd[0:3]) |