提交 da7daca3 编写于 作者: X Xu Han

[qemu] Python 3: Replace string

Signed-off-by: NXu Han <xuhan@redhat.com>
上级 96d6e516
...@@ -3,7 +3,6 @@ Group of cpuid tests for X86 CPU ...@@ -3,7 +3,6 @@ Group of cpuid tests for X86 CPU
""" """
import re import re
import os import os
import string
import logging import logging
from avocado.utils import build from avocado.utils import build
...@@ -19,6 +18,16 @@ dbg = logger.debug ...@@ -19,6 +18,16 @@ dbg = logger.debug
info = logger.info 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): def run(test, params, env):
""" """
Boot guest with different cpu_models and cpu flags and check if guest works correctly. Boot guest with different cpu_models and cpu flags and check if guest works correctly.
...@@ -446,7 +455,7 @@ def run(test, params, env): ...@@ -446,7 +455,7 @@ def run(test, params, env):
for i in regs: for i in regs:
for shift in range(0, 4): for shift in range(0, 4):
c = chr((r[i] >> (shift * 8)) & 0xFF) c = chr((r[i] >> (shift * 8)) & 0xFF)
if c in string.printable: if isprintable(c):
signature = signature + c signature = signature + c
else: else:
signature = "%s\\x%02x" % (signature, ord(c)) signature = "%s\\x%02x" % (signature, ord(c))
......
...@@ -9,7 +9,6 @@ Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=990118 ...@@ -9,7 +9,6 @@ Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=990118
""" """
import logging import logging
import string
import os import os
import gzip import gzip
import threading import threading
...@@ -138,7 +137,7 @@ def run(test, params, env): ...@@ -138,7 +137,7 @@ def run(test, params, env):
logging.debug("%s", output) logging.debug("%s", output)
output = session.cmd("LC_ALL=C df --portability --block-size=1M .") output = session.cmd("LC_ALL=C df --portability --block-size=1M .")
logging.debug("%s", output) logging.debug("%s", output)
df_megs = int(string.split(output)[10]) df_megs = int(output.split()[10])
if (df_megs < REQ_GUEST_DF): if (df_megs < REQ_GUEST_DF):
test.error("insufficient free disk space: %d < %d" % test.error("insufficient free disk space: %d < %d" %
(df_megs, REQ_GUEST_DF)) (df_megs, REQ_GUEST_DF))
...@@ -259,8 +258,8 @@ def run(test, params, env): ...@@ -259,8 +258,8 @@ def run(test, params, env):
"/usr/lib/debug/lib/modules/$(uname -r)/vmlinux " "/usr/lib/debug/lib/modules/$(uname -r)/vmlinux "
"%s" % (CRASH_SCRIPT, guest_plain)) "%s" % (CRASH_SCRIPT, guest_plain))
logging.debug("%s", output) logging.debug("%s", output)
if (string.find(output, "crash:") >= 0 or if (output.find("crash:") >= 0 or
string.find(output, "WARNING:") >= 0): output.find("WARNING:") >= 0):
test.fail("vmcore corrupt") test.fail("vmcore corrupt")
vm = env.get_vm(params["main_vm"]) vm = env.get_vm(params["main_vm"])
......
...@@ -6,7 +6,6 @@ multi_disk test for Autotest framework. ...@@ -6,7 +6,6 @@ multi_disk test for Autotest framework.
import logging import logging
import re import re
import random import random
import string
from avocado.utils import astring from avocado.utils import astring
...@@ -287,7 +286,7 @@ def run(test, params, env): ...@@ -287,7 +286,7 @@ def run(test, params, env):
output = session.cmd_output(cmd, timeout=cmd_timeout) output = session.cmd_output(cmd, timeout=cmd_timeout)
disks = re.findall(re_str, output) disks = re.findall(re_str, output)
disks = list(map(string.strip, disks)) disks = [item.strip() for item in disks]
disks.sort() disks.sort()
logging.debug("Volume list that meet regular expressions: %s", logging.debug("Volume list that meet regular expressions: %s",
" ".join(disks)) " ".join(disks))
......
import re import re
import logging import logging
import string
import aexpect import aexpect
from virttest import error_context from virttest import error_context
...@@ -209,8 +208,8 @@ def run(test, params, env): ...@@ -209,8 +208,8 @@ def run(test, params, env):
# Define a helper function to catch PCI device string # Define a helper function to catch PCI device string
def _find_pci(): def _find_pci():
output = session.cmd_output(params.get("find_pci_cmd")) output = session.cmd_output(params.get("find_pci_cmd"))
output = map(string.strip, output.splitlines()) output = [line.strip() for line in output.splitlines()]
ref = map(string.strip, reference.splitlines()) ref = [line.strip() for line in reference.splitlines()]
output = [_ for _ in output if _ not in ref] output = [_ for _ in output if _ not in ref]
output = "\n".join(output) output = "\n".join(output)
if re.search(params.get("match_string"), output, re.I | re.M): if re.search(params.get("match_string"), output, re.I | re.M):
......
...@@ -2,7 +2,6 @@ import re ...@@ -2,7 +2,6 @@ import re
import logging import logging
import time import time
import random import random
import string
import aexpect import aexpect
...@@ -213,8 +212,8 @@ def run(test, params, env): ...@@ -213,8 +212,8 @@ def run(test, params, env):
# Define a helper function to catch PCI device string # Define a helper function to catch PCI device string
def _find_pci(): def _find_pci():
output = session.cmd_output(params.get("find_pci_cmd")) output = session.cmd_output(params.get("find_pci_cmd"))
output = map(string.strip, output.splitlines()) output = [line.strip() for line in output.splitlines()]
ref = map(string.strip, reference.splitlines()) ref = [line.strip() for line in reference.splitlines()]
output = [_ for _ in output if _ not in ref] output = [_ for _ in output if _ not in ref]
output = "\n".join(output) output = "\n".join(output)
if re.search(params.get("match_string"), output, re.I): if re.search(params.get("match_string"), output, re.I):
......
import re import re
import string
import logging import logging
import random import random
...@@ -42,7 +41,7 @@ def run(test, params, env): ...@@ -42,7 +41,7 @@ def run(test, params, env):
f_fail.append(fail_log) f_fail.append(fail_log)
logging.error(fail_log) logging.error(fail_log)
actual_num = string.count(o, check_str) actual_num = o.count(check_str)
if expected_num != actual_num: if expected_num != actual_num:
fail_log = "%s number mismatch:\n" % str(devices) fail_log = "%s number mismatch:\n" % str(devices)
fail_log += " Assigned to VM: %d\n" % expected_num fail_log += " Assigned to VM: %d\n" % expected_num
...@@ -90,7 +89,7 @@ def run(test, params, env): ...@@ -90,7 +89,7 @@ def run(test, params, env):
actual = session.cmd_output(verify_cmd) actual = session.cmd_output(verify_cmd)
if not re.findall(expect, actual, re.I): if not re.findall(expect, actual, re.I):
fail_log = "%s mismatch:\n" % name 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 fail_log += " Reported by OS: %s" % actual
f_fail.append(fail_log) f_fail.append(fail_log)
logging.error(fail_log) logging.error(fail_log)
...@@ -121,8 +120,7 @@ def run(test, params, env): ...@@ -121,8 +120,7 @@ def run(test, params, env):
logging.error(fail_log) logging.error(fail_log)
return -2 return -2
logging.info("CPU %s number: %d", logging.info("CPU %s number: %d", chk_type.capitalize(), int(num[-1]))
string.capitalize(chk_type), int(num[-1]))
return int(num[-1]) return int(num[-1])
def check_cpu_number(chk_type, actual_n, expected_n): def check_cpu_number(chk_type, actual_n, expected_n):
...@@ -149,10 +147,10 @@ def run(test, params, env): ...@@ -149,10 +147,10 @@ def run(test, params, env):
f_fail.append(fail_log) f_fail.append(fail_log)
return f_fail 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: 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 += " Assigned to VM: '%s'\n" % expected_n
fail_log += " Reported by OS: '%s'" % actual_n fail_log += " Reported by OS: '%s'" % actual_n
f_fail.append(fail_log) f_fail.append(fail_log)
...@@ -160,7 +158,7 @@ def run(test, params, env): ...@@ -160,7 +158,7 @@ def run(test, params, env):
return f_fail return f_fail
logging.debug("%s check pass. Expected: '%s', Actual: '%s'", 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 return f_fail
def verify_machine_type(): def verify_machine_type():
...@@ -344,7 +342,7 @@ def run(test, params, env): ...@@ -344,7 +342,7 @@ def run(test, params, env):
num_nics = len(params.objects("nics")) num_nics = len(params.objects("nics"))
for nic_index in range(num_nics): for nic_index in range(num_nics):
mac = vm.get_mac_address(nic_index) 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 = "MAC address mismatch:\n"
fail_log += " Assigned to VM (not found): %s" % mac fail_log += " Assigned to VM (not found): %s" % mac
n_fail.append(fail_log) n_fail.append(fail_log)
......
import logging import logging
import re import re
import time import time
import string
from avocado.utils import cpu as utils_cpu from avocado.utils import cpu as utils_cpu
from virttest import utils_misc from virttest import utils_misc
...@@ -165,8 +164,7 @@ def run(test, params, env): ...@@ -165,8 +164,7 @@ def run(test, params, env):
error_context.context("Load I/O in all targets", logging.info) error_context.context("Load I/O in all targets", logging.info)
get_dev_cmd = params.get("get_dev_cmd", "ls /dev/[svh]d*") get_dev_cmd = params.get("get_dev_cmd", "ls /dev/[svh]d*")
output = session.cmd_output(get_dev_cmd) output = session.cmd_output(get_dev_cmd)
system_dev = re.findall(r"/dev/[svh]d\w+\d+", output)[0] system_dev = re.findall(r"/dev/[svh]d\w+(?=\d+)", output)[0]
system_dev = system_dev.rstrip(string.digits)
dd_timeout = int(re.findall(r"\d+", extra_image_size)[0]) dd_timeout = int(re.findall(r"\d+", extra_image_size)[0])
fill_cmd = "" fill_cmd = ""
count = 0 count = 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册