719ee8be1f
Don't print output of spdkcli command if not error happened. Such logging only polutes the CI output. On failed commands, the output is still printed. Mismatch between `element_exist` and `element in child.before.decode()' also counts as fail so we show the output in that case too. This commit is related to trello task: https://trello.com/c/GlJnWmkR/150-spdkcli-improve-tests-output Change-Id: I7b20dc2bbd1a3b15a3701be27bec023614e18621 Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459305 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Pawel Kaminski <pawelx.kaminski@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com> Reviewed-by: Karol Latecki <karol.latecki@intel.com> Reviewed-by: Seth Howell <seth.howell5141@gmail.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
53 lines
1.6 KiB
Python
Executable File
53 lines
1.6 KiB
Python
Executable File
#!/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"
|
|
if len(sys.argv) == 3:
|
|
socket = sys.argv[2]
|
|
testdir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
|
child = pexpect.spawn(os.path.join(testdir, "../../scripts/spdkcli.py") + " -s %s" % socket)
|
|
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])
|