After delete duplicate remote_exec_pexect function, the left function
with same name causes some problem with cases, so update the function
and sync all cases using it.
Signed-off-by: Wayne Sun <gsun(a)redhat.com>
---
repos/domain/cpu_topology.py | 2 +-
repos/snapshot/file_flag.py | 8 ++++----
repos/snapshot/flag_check.py | 12 ++++++------
utils/utils.py | 28 ++++++++++++++--------------
4 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/repos/domain/cpu_topology.py b/repos/domain/cpu_topology.py
index 5f4ef52..cb071c9 100644
--- a/repos/domain/cpu_topology.py
+++ b/repos/domain/cpu_topology.py
@@ -136,7 +136,7 @@ def cpu_topology_chk(ip, username, password,
int = 0
actual_thread = actual_core = actual_socket = ''
- for item in output.strip().split('\r'):
+ for item in output.split('\r'):
if int == 5:
actual_thread = item.split()[-1]
logger.info("the actual thread in the guest is %s" %
actual_thread)
diff --git a/repos/snapshot/file_flag.py b/repos/snapshot/file_flag.py
index e18975e..001f13c 100644
--- a/repos/snapshot/file_flag.py
+++ b/repos/snapshot/file_flag.py
@@ -34,12 +34,12 @@ def check_domain_running(conn, guestname, logger):
def make_flag(ipaddr, username, password, logger):
""" enter guest OS, create a file in /tmp folder """
- ret = utils.remote_exec_pexpect(ipaddr, username, password, MAKE_FLAG)
- if ret == "TIMEOUT!!!":
+ ret, out = utils.remote_exec_pexpect(ipaddr, username, password, MAKE_FLAG)
+ if ret:
logger.error("connecting to guest OS timeout")
return False
- elif ret != '':
- logger.error("failed to make flag in guest OS, %s" % ret)
+ elif out != '':
+ logger.error("failed to make flag in guest OS, %s" % out)
return False
else:
logger.info("flag %s is created in /tmp folder" % FLAG_FILE)
diff --git a/repos/snapshot/flag_check.py b/repos/snapshot/flag_check.py
index 41314d8..f0ddecf 100644
--- a/repos/snapshot/flag_check.py
+++ b/repos/snapshot/flag_check.py
@@ -68,20 +68,20 @@ def flag_check(params):
logger.info("vm %s failed to get ip address" % guestname)
return 1
- ret = utils.remote_exec_pexpect(ipaddr, username, password, FLAG_CHECK)
- if ret == "TIMEOUT!!!":
+ ret, out = utils.remote_exec_pexpect(ipaddr, username, password, FLAG_CHECK)
+ if ret:
logger.error("connecting to guest OS timeout")
return 1
- elif ret == FLAG_FILE and expected_result == "exist":
+ elif out == FLAG_FILE and expected_result == "exist":
logger.info("checking flag %s in guest OS succeeded" % FLAG_FILE)
return 0
- elif ret == FLAG_FILE and expected_result == 'noexist':
+ elif out == FLAG_FILE and expected_result == 'noexist':
logger.error("flag %s still exist, FAILED." % FLAG_FILE)
return 1
- elif ret != None and expected_result == "exist":
+ elif out != None and expected_result == "exist":
logger.error("no flag %s exists in the guest %s " %
(FLAG_FILE,guestname))
return 1
- elif ret != None and expected_result == 'noexist':
+ elif out != None and expected_result == 'noexist':
logger.info("flag %s is not present, checking succeeded" % FLAG_FILE)
return 0
diff --git a/utils/utils.py b/utils/utils.py
index 27ddbc2..e242847 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -427,10 +427,10 @@ def remote_exec_pexpect(hostname, username, password, cmd):
child.sendline(password)
elif index == 2:
child.close()
- return 0, child.before
+ return 0, string.strip(child.before)
elif index == 3:
child.close()
- return 1, ""
+ return 1, "Timeout!!!!"
return 0
@@ -531,8 +531,8 @@ def get_remote_memory(hostname, username, password):
i = 0
while i < 3:
i += 1
- memsize = \
- int(remote_exec_pexpect(hostname, username, password, cmd)) * 1024
+ ret, out = remote_exec_pexpect(hostname, username, password, cmd)
+ memsize = int(out) * 1024
if memsize == -1:
continue
else:
@@ -595,10 +595,10 @@ def libvirt_version(latest_ver = ''):
def create_dir(hostname, username, password):
"""Create new dir"""
cmd = "mkdir /tmp/test"
- mkdir_ret = remote_exec_pexpect(hostname, username, password, cmd)
+ ret, mkdir_ret = remote_exec_pexpect(hostname, username, password, cmd)
if mkdir_ret == '':
cmd = "ls -d /tmp/test"
- check_str = remote_exec_pexpect(hostname, username,
+ ret, check_str = remote_exec_pexpect(hostname, username,
password, cmd)
if check_str == "/tmp/test":
return 0
@@ -613,11 +613,11 @@ def write_file(hostname, username, password):
"""Simple test for writting file on specified host"""
test_string = 'hello word testing'
cmd = """echo '%s'>/tmp/test/test.log""" %
(test_string)
- write_file_ret = remote_exec_pexpect(hostname, username,
+ ret, write_file_ret = remote_exec_pexpect(hostname, username,
password, cmd)
if write_file_ret == '':
cmd = """grep '%s' /tmp/test/test.log""" %
("hello")
- check_str = remote_exec_pexpect(hostname, username,
+ ret, check_str = remote_exec_pexpect(hostname, username,
password, cmd)
if check_str == test_string:
return 0
@@ -649,10 +649,10 @@ def run_wget_app(hostname, username, password, file_url, logger):
"""Simple test for wget app on specified host"""
cmd_line = "wget -P /tmp %s -o /tmp/wget.log" % (file_url)
logger.info("Command: %s" % (cmd_line))
- wget_ret = remote_exec_pexpect(hostname, username,
+ ret, wget_ret = remote_exec_pexpect(hostname, username,
password, cmd_line)
cmd_line = "grep %s %s" % ('100%', '/tmp/wget.log')
- check_ret = remote_exec_pexpect(hostname, username,
+ ret, check_ret = remote_exec_pexpect(hostname, username,
password, cmd_line)
if check_ret == "":
logger.info("grep output is nothing")
@@ -683,9 +683,9 @@ def validate_remote_nic_type(hostname, username,
logger.info("nic_driver = %s" % (nic_driver))
lspci_cmd = "lspci"
lsmod_cmd = "lsmod"
- lspci_cmd_ret = remote_exec_pexpect(hostname, username,
+ ret, lspci_cmd_ret = remote_exec_pexpect(hostname, username,
password, lspci_cmd)
- lsmod_cmd_ret = remote_exec_pexpect(hostname, username,
+ ret, lsmod_cmd_ret = remote_exec_pexpect(hostname, username,
password, lsmod_cmd)
logger.info("------------")
logger.info("lspci_cmd_ret:\n %s" % (lspci_cmd_ret))
@@ -743,9 +743,9 @@ def validate_remote_blk_type(hostname, username, password,
blk_type_to_driver_dict = {'ide':'unknow',
'virtio':'virtio_blk'}
lspci_cmd = "lspci"
lsmod_cmd = "lsmod"
- lspci_cmd_ret = remote_exec_pexpect(hostname, username,
+ ret, lspci_cmd_ret = remote_exec_pexpect(hostname, username,
password, lspci_cmd)
- lsmod_cmd_ret = remote_exec_pexpect(hostname, username,
+ ret, lsmod_cmd_ret = remote_exec_pexpect(hostname, username,
password, lsmod_cmd)
logger.info("------------")
logger.info("lspci_cmd_ret:\n %s" % (lspci_cmd_ret))
--
1.7.1