KVM-test: Fix a bug that about list slice in scan_results.py
PATCH 2/2 KVM-test: Move two 'remote_login' out of try block in kvm_vm.py
In reply to Yolkfull ChowIf vm.remote_login failed 'session.close()' can result in exception in finally clause. This patch fix the problem.
Signed-off-by Yolkfull Chow <[email protected]>
--- client/tests/kvm/kvm_vm.py | 51 +++++++++++++++++++++---------------------- 1 files changed, 25 insertions(+), 26 deletions(-)
client/tests/kvm/kvm_vm.py +25 -26
@@ -827,40 +827,39 @@ class VM: """ Get the cpu count of the VM. """ + session = self.remote_login() + cmd = self.params.get("cpu_chk_cmd") try: - session = self.remote_login() - if session: - cmd = self.params.get("cpu_chk_cmd") - s, count = session.get_command_status_output(cmd) - if s == 0: - return int(count) + s, count = session.get_command_status_output(cmd) + if s == 0: + return int(count) return None finally: - session.close() + if session: + session.close() def get_memory_size(self): """ Get memory size of the VM. """ + session = self.remote_login() + cmd = self.params.get("mem_chk_cmd") try: - session = self.remote_login() - if session: - cmd = self.params.get("mem_chk_cmd") - s, mem_str = session.get_command_status_output(cmd) - if s != 0: - return None - mem = re.findall("([0-9][0-9][0-9]+)", mem_str) - mem_size = 0 - for m in mem: - mem_size += int(m) - if "GB" in mem_str: - mem_size *= 1024 - elif "MB" in mem_str: - pass - else: - mem_size /= 1024 - return int(mem_size) - return None + s, mem_str = session.get_command_status_output(cmd) + if s != 0: + return None + mem = re.findall("([0-9][0-9][0-9]+)", mem_str) + mem_size = 0 + for m in mem: + mem_size += int(m) + if "GB" in mem_str: + mem_size *= 1024 + elif "MB" in mem_str: + pass + else: + mem_size /= 1024 + return int(mem_size) finally: - session.close() + if session: + session.close()
Signature · 1 line
1.6.6
PATCH 1/2 KVM-test: Fix a bug that about list slice in scan_results.py
If 'info_list' is empty slice operation can result in traceback:
...
info_list[-1] = parts[5]
IndexError: list assignment index out of range
Signed-off-by Yolkfull Chow <[email protected]>
--- client/tests/kvm/scan_results.py | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
client/tests/kvm/scan_results.py +1 -0
@@ -45,6 +45,7 @@ def parse_results(text): # Found a FAIL/ERROR/GOOD line -- get failure/success info elif (len(parts) >= 6 and parts[3].startswith("timestamp") and parts[4].startswith("localtime")): + info_list.append("") info_list[-1] = parts[5] return result_list
Signature · 1 line
1.6.6