提交 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
"""
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))
......
......@@ -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"])
......
......@@ -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))
......
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):
......
......@@ -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):
......
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)
......
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册