提交 7415b2d8 编写于 作者: J Jiří Župka 提交者: Lucas Meneghel Rodrigues

virt: Cpuflags test repair for new version of qemu

Qemu 1.3.50 changes cpu command line from -cpu ?cpuid,?dump,?models
to one command -cpu ?. -cpu ? command show joined information
only -cpu ?cpuid and -cpu ?models command. And developers don't
want add this functionality again because nobody use -cpu ?dump any more.
libvirt use file cpu_map.xml where should be all information about
cpu flags. And by this reason cpuflag test have to add this file too.
Moreover, it should help with check of qemu cpu flags stability.
Signed-off-by: NJiří Župka <jzupka@redhat.com>
上级 e11c1919
import logging, re, random, os, time, pickle, sys, traceback import logging, re, random, os, time, pickle, sys, traceback
from xml.parsers import expat
from autotest.client.shared import error, utils from autotest.client.shared import error, utils
from autotest.client.shared import test as test_module from virttest import qemu_vm, virt_vm
from virttest import qemu_vm
from virttest import utils_misc, utils_test, aexpect from virttest import utils_misc, utils_test, aexpect
...@@ -17,13 +17,14 @@ def run_cpuflags(test, params, env): ...@@ -17,13 +17,14 @@ def run_cpuflags(test, params, env):
qemu_binary = utils_misc.get_path('.', params.get("qemu_binary", "qemu")) qemu_binary = utils_misc.get_path('.', params.get("qemu_binary", "qemu"))
cpuflags_src = os.path.join(test.virtdir, "deps", "test_cpu_flags") cpuflags_src = os.path.join(test.virtdir, "deps", "test_cpu_flags")
cpuflags_def = os.path.join(test.virtdir, "deps", "cpu_map.xml")
smp = int(params.get("smp", 1)) smp = int(params.get("smp", 1))
all_host_supported_flags = params.get("all_host_supported_flags", "no") all_host_supported_flags = params.get("all_host_supported_flags", "no")
mig_timeout = float(params.get("mig_timeout", "3600")) mig_timeout = float(params.get("mig_timeout", "3600"))
mig_protocol = params.get("migration_protocol", "tcp") mig_protocol = params.get("migration_protocol", "tcp")
mig_speed = params.get("mig_speed", "100M") mig_speed = params.get("mig_speed", "1G")
cpu_model_black_list = params.get("cpu_model_blacklist", "").split(" ") cpu_model_black_list = params.get("cpu_model_blacklist", "").split(" ")
...@@ -100,7 +101,7 @@ def run_cpuflags(test, params, env): ...@@ -100,7 +101,7 @@ def run_cpuflags(test, params, env):
flags = flags_re.search(out).groups()[0].split() flags = flags_re.search(out).groups()[0].split()
return set(map(utils_misc.Flag, flags)) return set(map(utils_misc.Flag, flags))
def get_guest_host_cpuflags(cpumodel): def get_guest_host_cpuflags_legacy(cpumodel):
""" """
Get cpu flags correspond with cpumodel parameters. Get cpu flags correspond with cpumodel parameters.
...@@ -121,12 +122,83 @@ def run_cpuflags(test, params, env): ...@@ -121,12 +122,83 @@ def run_cpuflags(test, params, env):
flags += flag_group.split() flags += flag_group.split()
return set(map(utils_misc.Flag, flags)) return set(map(utils_misc.Flag, flags))
def get_all_qemu_flags():
class ParseCpuFlags(object):
def __init__(self, encoding=None):
self.cpus = {}
self.parser = expat.ParserCreate(encoding)
self.parser.StartElementHandler = self.start_element
self.parser.EndElementHandler = self.end_element
self.last_arch = None
self.last_model = None
self.sub_model = False
def start_element(self, name, attrs):
if name == "cpus":
self.cpus = {}
elif name == "arch":
self.last_arch = self.cpus[attrs['name']] = {}
elif name == "model":
if self.last_model is None:
self.last_model = self.last_arch[attrs['name']] = []
else:
self.last_model += self.last_arch[attrs['name']]
self.sub_model = True
elif name == "feature":
if not self.last_model is None:
self.last_model.append(attrs['name'])
def end_element(self, name):
if name == "arch":
self.last_arch = None
elif name == "model":
if self.sub_model == False:
self.last_model = None
else:
self.sub_model = False
def parse_file(self, file_path):
self.parser.ParseFile(open(file_path, 'r'))
return self.cpus
def get_guest_host_cpuflags_1350(cpumodel):
"""
Get cpu flags correspond with cpumodel parameters.
@param cpumodel: Cpumodel parameter sended to <qemu-kvm-cmd>.
@return: [corespond flags]
"""
p = ParseCpuFlags()
cpus = p.parse_file(cpuflags_def)
for arch in cpus.values():
if cpumodel in arch.keys():
flags = arch[cpumodel]
return set(map(utils_misc.Flag, flags))
def get_all_qemu_flags_legacy():
cmd = qemu_binary + " -cpu ?cpuid" cmd = qemu_binary + " -cpu ?cpuid"
output = utils.run(cmd).stdout output = utils.run(cmd).stdout
flags_re = re.compile(r".*\n.*f_edx:(.*)\n.*f_ecx:(.*)\n.*extf_edx:" flags_re = re.compile(r".*\n.*f_edx:(.*)\n.*f_ecx:(.*)\n"
"(.*)\n.*extf_ecx:(.*)") ".*extf_edx:(.*)\n.*extf_ecx:(.*)")
m = flags_re.search(output)
flags = []
for a in m.groups():
flags += a.split()
return set(map(utils_misc.Flag, flags))
def get_all_qemu_flags_1350():
cmd = qemu_binary + " -cpu ?"
output = utils.run(cmd).stdout
flags_re = re.compile(r".*Recognized CPUID flags:\n(.*)", re.DOTALL)
m = flags_re.search(output) m = flags_re.search(output)
flags = [] flags = []
for a in m.groups(): for a in m.groups():
...@@ -134,6 +206,49 @@ def run_cpuflags(test, params, env): ...@@ -134,6 +206,49 @@ def run_cpuflags(test, params, env):
return set(map(utils_misc.Flag, flags)) return set(map(utils_misc.Flag, flags))
def get_cpu_models_legacy():
"""
Get all cpu models from qemu.
@return: cpu models.
"""
cmd = qemu_binary + " -cpu ?"
output = utils.run(cmd).stdout
cpu_re = re.compile("\w+\s+\[?(\w+)\]?")
return cpu_re.findall(output)
def get_cpu_models_1350():
"""
Get all cpu models from qemu.
@return: cpu models.
"""
cmd = qemu_binary + " -cpu ?"
output = utils.run(cmd).stdout
cpu_re = re.compile("x86\s+\[?(\w+)\]?")
return cpu_re.findall(output)
def get_qemu_cpu_cmd_version():
cmd = qemu_binary + " -cpu ?"
output = utils.run(cmd).stdout
if "CPUID" in output:
return "1350"
else:
return "legacy"
qcver = get_qemu_cpu_cmd_version()
get_guest_host_cpuflags = locals()["get_guest_host_cpuflags_%s" % qcver]
get_all_qemu_flags = locals()["get_all_qemu_flags_%s" % qcver]
get_cpu_models = locals()["get_cpu_models_%s" % qcver]
def get_flags_full_name(cpu_flag): def get_flags_full_name(cpu_flag):
""" """
Get all name of Flag. Get all name of Flag.
...@@ -170,18 +285,6 @@ def run_cpuflags(test, params, env): ...@@ -170,18 +285,6 @@ def run_cpuflags(test, params, env):
return real_flags return real_flags
def get_cpu_models():
"""
Get all cpu models from qemu.
@return: cpu models.
"""
cmd = qemu_binary + " -cpu ?"
output = utils.run(cmd).stdout
cpu_re = re.compile("\w+\s+\[?(\w+)\]?")
return cpu_re.findall(output)
def check_cpuflags(cpumodel, vm_session): def check_cpuflags(cpumodel, vm_session):
""" """
Check if vm flags are same like flags select by cpumodel. Check if vm flags are same like flags select by cpumodel.
...@@ -318,9 +421,10 @@ def run_cpuflags(test, params, env): ...@@ -318,9 +421,10 @@ def run_cpuflags(test, params, env):
extra_flags = set([]) extra_flags = set([])
return (cpu_model, extra_flags) return (cpu_model, extra_flags)
class MiniSubtest(test_module.Subtest):
class MiniSubtest(object):
def __new__(cls, *args, **kargs): def __new__(cls, *args, **kargs):
self = test.Subtest.__new__() self = super(MiniSubtest, cls).__new__(cls)
ret = None ret = None
if args is None: if args is None:
args = [] args = []
...@@ -341,6 +445,7 @@ def run_cpuflags(test, params, env): ...@@ -341,6 +445,7 @@ def run_cpuflags(test, params, env):
exc_type, exc_value, exc_type, exc_value,
exc_traceback.tb_next))) exc_traceback.tb_next)))
class Test_temp(MiniSubtest): class Test_temp(MiniSubtest):
def clean(self): def clean(self):
logging.info("cleanup") logging.info("cleanup")
...@@ -351,44 +456,53 @@ def run_cpuflags(test, params, env): ...@@ -351,44 +456,53 @@ def run_cpuflags(test, params, env):
# 1) <qemu-kvm-cmd> -cpu ?model # 1) <qemu-kvm-cmd> -cpu ?model
class test_qemu_cpu_model(MiniSubtest): class test_qemu_cpu_model(MiniSubtest):
def test(self): def test(self):
cpu_models = params.get("cpu_models", "core2duo").split() if qcver == "legacy":
cmd = qemu_binary + " -cpu ?model" cpu_models = params.get("cpu_models", "core2duo").split()
result = utils.run(cmd) cmd = qemu_binary + " -cpu ?model"
missing = [] result = utils.run(cmd)
cpu_models = map(separe_cpu_model, cpu_models) missing = []
for cpu_model in cpu_models: cpu_models = map(separe_cpu_model, cpu_models)
if not cpu_model in result.stdout: for cpu_model in cpu_models:
missing.append(cpu_model) if not cpu_model in result.stdout:
if missing: missing.append(cpu_model)
raise error.TestFail("CPU models %s are not in output " if missing:
"'%s' of command \n%s" % raise error.TestFail("CPU models %s are not in output "
(missing, cmd, result.stdout)) "'%s' of command \n%s" %
(missing, cmd, result.stdout))
elif qcver == "1350":
raise error.TestNAError("New qemu use new -cpu ? cmd.")
# 2) <qemu-kvm-cmd> -cpu ?dump # 2) <qemu-kvm-cmd> -cpu ?dump
class test_qemu_dump(MiniSubtest): class test_qemu_dump(MiniSubtest):
def test(self): def test(self):
cpu_models = params.get("cpu_models", "core2duo").split() if qcver == "legacy":
cmd = qemu_binary + " -cpu ?dump" cpu_models = params.get("cpu_models", "core2duo").split()
result = utils.run(cmd) cmd = qemu_binary + " -cpu ?dump"
cpu_models = map(separe_cpu_model, cpu_models) result = utils.run(cmd)
missing = [] cpu_models = map(separe_cpu_model, cpu_models)
for cpu_model in cpu_models: missing = []
if not cpu_model in result.stdout: for cpu_model in cpu_models:
missing.append(cpu_model) if not cpu_model in result.stdout:
if missing: missing.append(cpu_model)
raise error.TestFail("CPU models %s are not in output " if missing:
"'%s' of command \n%s" % raise error.TestFail("CPU models %s are not in output "
(missing, cmd, result.stdout)) "'%s' of command \n%s" %
(missing, cmd, result.stdout))
elif qcver == "1350":
raise error.TestNAError("New qemu does not support -cpu ?dump.")
# 3) <qemu-kvm-cmd> -cpu ?cpuid # 3) <qemu-kvm-cmd> -cpu ?cpuid
class test_qemu_cpuid(MiniSubtest): class test_qemu_cpuid(MiniSubtest):
def test(self): def test(self):
cmd = qemu_binary + " -cpu ?cpuid" if qcver == "legacy":
result = utils.run(cmd) cmd = qemu_binary + " -cpu ?cpuid"
if result.stdout is "": result = utils.run(cmd)
raise error.TestFail("There aren't any cpu Flag in output" if result.stdout is "":
" '%s' of command \n%s" % raise error.TestFail("There aren't any cpu Flag in output"
(cmd, result.stdout)) " '%s' of command \n%s" %
(cmd, result.stdout))
elif qcver == "1350":
raise error.TestNAError("New qemu use new -cpu ? cmd.")
# 1) boot with cpu_model # 1) boot with cpu_model
class test_boot_cpu_model(Test_temp): class test_boot_cpu_model(Test_temp):
...@@ -403,6 +517,7 @@ def run_cpuflags(test, params, env): ...@@ -403,6 +517,7 @@ def run_cpuflags(test, params, env):
raise error.TestFail("Flags defined on host but not found " raise error.TestFail("Flags defined on host but not found "
"on guest: %s" % (not_enable_flags)) "on guest: %s" % (not_enable_flags))
# 2) success boot with supported flags # 2) success boot with supported flags
class test_boot_cpu_model_and_additional_flags(Test_temp): class test_boot_cpu_model_and_additional_flags(Test_temp):
def test(self): def test(self):
...@@ -473,7 +588,9 @@ def run_cpuflags(test, params, env): ...@@ -473,7 +588,9 @@ def run_cpuflags(test, params, env):
cpuf_model += ",+" + str(fadd) cpuf_model += ",+" + str(fadd)
vnc_port = utils_misc.find_free_port(5900, 6100) - 5900 vnc_port = utils_misc.find_free_port(5900, 6100) - 5900
cmd = "%s -cpu %s -vnc :%d" % (qemu_binary, cpuf_model, vnc_port) cmd = "%s -cpu %s -vnc :%d -enable-kvm" % (qemu_binary,
cpuf_model,
vnc_port)
out = None out = None
try: try:
...@@ -509,7 +626,9 @@ def run_cpuflags(test, params, env): ...@@ -509,7 +626,9 @@ def run_cpuflags(test, params, env):
cpuf_model += ",+" + str(fadd) cpuf_model += ",+" + str(fadd)
vnc_port = utils_misc.find_free_port(5900, 6100) - 5900 vnc_port = utils_misc.find_free_port(5900, 6100) - 5900
cmd = "%s -cpu %s -vnc :%d" % (qemu_binary, cpuf_model, vnc_port) cmd = "%s -cpu %s -vnc :%d -enable-kvm" % (qemu_binary,
cpuf_model,
vnc_port)
out = None out = None
try: try:
try: try:
...@@ -637,10 +756,27 @@ def run_cpuflags(test, params, env): ...@@ -637,10 +756,27 @@ def run_cpuflags(test, params, env):
time.sleep(5) time.sleep(5)
self.vm.monitor.migrate_set_speed(mig_speed) self.vm.monitor.migrate_set_speed(mig_speed)
self.vm.migrate(mig_timeout, mig_protocol, offline=False) self.clone = self.vm.migrate(mig_timeout, mig_protocol, offline=False,
not_wait_for_migration=True)
time.sleep(5) time.sleep(5)
try:
self.vm.wait_for_migration(10)
except virt_vm.VMMigrateTimeoutError:
self.vm.monitor.migrate_set_downtime(1)
self.vm.wait_for_migration(mig_timeout)
# Swap due to test cleaning.
temp = self.vm.clone(copy_state=True)
self.vm.__dict__ = self.clone.__dict__
self.clone = temp
self.vm.resume()
self.clone.destroy(gracefully=False)
stress_session = self.vm.wait_for_login()
#If cpuflags-test hang up during migration test raise exception #If cpuflags-test hang up during migration test raise exception
try: try:
stress_session.cmd('killall cpuflags-test') stress_session.cmd('killall cpuflags-test')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册