提交 08d3ad47 编写于 作者: C Chen Qun

provider/qemu_version: add qemu_version version_compare function

The qemu version is different, some scenes behave differently.
We need to distinguish and judge it, so add the qemu_version.version_compare().
Signed-off-by: NChen Qun <kuhn.chenqun@huawei.com>
上级 cc26fa8f
"""
Shared code for tests that need to get the qemu version
"""
import re
import logging
from avocado.utils import process
from virttest.compat_52lts import decode_to_text as to_text
QEMU_LIB_VERSION = 0
def version_compare(major, minor, update):
"""
Determine/use the current qemu library version on the system
and compare input major, minor, and update values against it.
If the running version is greater than or equal to the input
params version, then return True; otherwise, return False
This is designed to handle upstream version comparisons for
test adjustments and/or comparisons as a result of upstream
fixes or changes that could impact test results.
:param major: Major version to compare against
:param minor: Minor version to compare against
:param update: Update value to compare against
:return: True if running version is greater than or
equal to the input qemu version
"""
global QEMU_LIB_VERSION
if QEMU_LIB_VERSION == 0:
try:
regex = r'QEMU\s*emulator\s*version\s*(\d+)\.(\d+)\.(\d+)\s*'
check_cmd = "qemu-kvm -version"
lines = to_text(process.system_output(check_cmd))
mobj = re.search(regex, lines)
if bool(mobj):
QEMU_LIB_VERSION = int(mobj.group(1)) * 1000000 + \
int(mobj.group(2)) * 1000 + \
int(mobj.group(3))
except (ValueError, TypeError, AttributeError):
logging.warning("Error determining qemu version")
return False
compare_version = major * 1000000 + minor * 1000 + update
if QEMU_LIB_VERSION >= compare_version:
return True
return False
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册