diff --git a/qemu/tests/cpuid.py b/qemu/tests/cpuid.py index e71c46ed1b2bd5909b9e9de020dc793fe481c93a..04e8cef9ccaf60b53eb17b007000c13f6cbf43ff 100644 --- a/qemu/tests/cpuid.py +++ b/qemu/tests/cpuid.py @@ -3,7 +3,6 @@ Group of cpuid tests for X86 CPU """ import re import os -import string import logging from avocado.utils import build @@ -19,6 +18,16 @@ dbg = logger.debug info = logger.info +def isprintable(c): + try: + import string + if c in string.printable: + return True + return False + except ImportError: + return c.isprintable() + + def run(test, params, env): """ Boot guest with different cpu_models and cpu flags and check if guest works correctly. @@ -446,7 +455,7 @@ def run(test, params, env): for i in regs: for shift in range(0, 4): c = chr((r[i] >> (shift * 8)) & 0xFF) - if c in string.printable: + if isprintable(c): signature = signature + c else: signature = "%s\\x%02x" % (signature, ord(c)) diff --git a/qemu/tests/guest_memory_dump_analysis.py b/qemu/tests/guest_memory_dump_analysis.py index 33fb29db9054984eb0c7bad68f10243cefcaa075..02da901b93d0875ac60249b89c47ca8535ef9ecb 100644 --- a/qemu/tests/guest_memory_dump_analysis.py +++ b/qemu/tests/guest_memory_dump_analysis.py @@ -9,7 +9,6 @@ Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=990118 """ import logging -import string import os import gzip import threading @@ -138,7 +137,7 @@ def run(test, params, env): logging.debug("%s", output) output = session.cmd("LC_ALL=C df --portability --block-size=1M .") logging.debug("%s", output) - df_megs = int(string.split(output)[10]) + df_megs = int(output.split()[10]) if (df_megs < REQ_GUEST_DF): test.error("insufficient free disk space: %d < %d" % (df_megs, REQ_GUEST_DF)) @@ -259,8 +258,8 @@ def run(test, params, env): "/usr/lib/debug/lib/modules/$(uname -r)/vmlinux " "%s" % (CRASH_SCRIPT, guest_plain)) logging.debug("%s", output) - if (string.find(output, "crash:") >= 0 or - string.find(output, "WARNING:") >= 0): + if (output.find("crash:") >= 0 or + output.find("WARNING:") >= 0): test.fail("vmcore corrupt") vm = env.get_vm(params["main_vm"]) diff --git a/qemu/tests/multi_disk.py b/qemu/tests/multi_disk.py index 8b7d403c9c0247dd9487498a9e33f43fa6d2e442..76131c191a7242fbf213797b536456dfd729311a 100644 --- a/qemu/tests/multi_disk.py +++ b/qemu/tests/multi_disk.py @@ -6,7 +6,6 @@ multi_disk test for Autotest framework. import logging import re import random -import string from avocado.utils import astring @@ -287,7 +286,7 @@ def run(test, params, env): output = session.cmd_output(cmd, timeout=cmd_timeout) disks = re.findall(re_str, output) - disks = list(map(string.strip, disks)) + disks = [item.strip() for item in disks] disks.sort() logging.debug("Volume list that meet regular expressions: %s", " ".join(disks)) diff --git a/qemu/tests/pci_hotplug.py b/qemu/tests/pci_hotplug.py index 426191011622908d55004e93d63dd49022c46c04..140638f9ce7109b4fe47ae0526c5e88c8cef3845 100644 --- a/qemu/tests/pci_hotplug.py +++ b/qemu/tests/pci_hotplug.py @@ -1,6 +1,5 @@ import re import logging -import string import aexpect from virttest import error_context @@ -209,8 +208,8 @@ def run(test, params, env): # Define a helper function to catch PCI device string def _find_pci(): output = session.cmd_output(params.get("find_pci_cmd")) - output = map(string.strip, output.splitlines()) - ref = map(string.strip, reference.splitlines()) + output = [line.strip() for line in output.splitlines()] + ref = [line.strip() for line in reference.splitlines()] output = [_ for _ in output if _ not in ref] output = "\n".join(output) if re.search(params.get("match_string"), output, re.I | re.M): diff --git a/qemu/tests/pci_hotplug_check.py b/qemu/tests/pci_hotplug_check.py index f1c3f6df844a1d28acaf29a3b3b6d5d52cc59281..71cb7b5e46a07021c8b300ff7feddf908179dba9 100644 --- a/qemu/tests/pci_hotplug_check.py +++ b/qemu/tests/pci_hotplug_check.py @@ -2,7 +2,6 @@ import re import logging import time import random -import string import aexpect @@ -213,8 +212,8 @@ def run(test, params, env): # Define a helper function to catch PCI device string def _find_pci(): output = session.cmd_output(params.get("find_pci_cmd")) - output = map(string.strip, output.splitlines()) - ref = map(string.strip, reference.splitlines()) + output = [line.strip() for line in output.splitlines()] + ref = [line.strip() for line in reference.splitlines()] output = [_ for _ in output if _ not in ref] output = "\n".join(output) if re.search(params.get("match_string"), output, re.I): diff --git a/qemu/tests/physical_resources_check.py b/qemu/tests/physical_resources_check.py index 703ff8169eee01a2f94abb1940a7bc88b076d4d8..2ad5c1162ef827e50ecf284e0ffb9a9844b75de2 100644 --- a/qemu/tests/physical_resources_check.py +++ b/qemu/tests/physical_resources_check.py @@ -1,5 +1,4 @@ import re -import string import logging import random @@ -42,7 +41,7 @@ def run(test, params, env): f_fail.append(fail_log) logging.error(fail_log) - actual_num = string.count(o, check_str) + actual_num = o.count(check_str) if expected_num != actual_num: fail_log = "%s number mismatch:\n" % str(devices) fail_log += " Assigned to VM: %d\n" % expected_num @@ -90,7 +89,7 @@ def run(test, params, env): actual = session.cmd_output(verify_cmd) if not re.findall(expect, actual, re.I): fail_log = "%s mismatch:\n" % name - fail_log += " Assigned to VM: %s\n" % string.upper(expect) + fail_log += " Assigned to VM: %s\n" % expect.upper() fail_log += " Reported by OS: %s" % actual f_fail.append(fail_log) logging.error(fail_log) @@ -121,8 +120,7 @@ def run(test, params, env): logging.error(fail_log) return -2 - logging.info("CPU %s number: %d", - string.capitalize(chk_type), int(num[-1])) + logging.info("CPU %s number: %d", chk_type.capitalize(), int(num[-1])) return int(num[-1]) def check_cpu_number(chk_type, actual_n, expected_n): @@ -149,10 +147,10 @@ def run(test, params, env): f_fail.append(fail_log) return f_fail - logging.info("CPU %s number check", string.capitalize(chk_type)) + logging.info("CPU %s number check", chk_type.capitalize()) if actual_n != expected_n: - fail_log = "%s output mismatch:\n" % string.capitalize(chk_type) + fail_log = "%s output mismatch:\n" % chk_type.capitalize() fail_log += " Assigned to VM: '%s'\n" % expected_n fail_log += " Reported by OS: '%s'" % actual_n f_fail.append(fail_log) @@ -160,7 +158,7 @@ def run(test, params, env): return f_fail logging.debug("%s check pass. Expected: '%s', Actual: '%s'", - string.capitalize(chk_type), expected_n, actual_n) + chk_type.capitalize(), expected_n, actual_n) return f_fail def verify_machine_type(): @@ -344,7 +342,7 @@ def run(test, params, env): num_nics = len(params.objects("nics")) for nic_index in range(num_nics): mac = vm.get_mac_address(nic_index) - if string.lower(mac) not in found_mac_addresses: + if mac.lower() not in found_mac_addresses: fail_log = "MAC address mismatch:\n" fail_log += " Assigned to VM (not found): %s" % mac n_fail.append(fail_log) diff --git a/qemu/tests/virtio_scsi_mq.py b/qemu/tests/virtio_scsi_mq.py index 07baa3948327d09816e77d1f8fed35c5720a65a5..02aeaa4556b111d5cf4c40503c10e677b794cc0b 100644 --- a/qemu/tests/virtio_scsi_mq.py +++ b/qemu/tests/virtio_scsi_mq.py @@ -1,7 +1,6 @@ import logging import re import time -import string from avocado.utils import cpu as utils_cpu from virttest import utils_misc @@ -165,8 +164,7 @@ def run(test, params, env): error_context.context("Load I/O in all targets", logging.info) get_dev_cmd = params.get("get_dev_cmd", "ls /dev/[svh]d*") output = session.cmd_output(get_dev_cmd) - system_dev = re.findall(r"/dev/[svh]d\w+\d+", output)[0] - system_dev = system_dev.rstrip(string.digits) + system_dev = re.findall(r"/dev/[svh]d\w+(?=\d+)", output)[0] dd_timeout = int(re.findall(r"\d+", extra_image_size)[0]) fill_cmd = "" count = 0