提交 7a500698 编写于 作者: X Xu Han

single_driver_install: Rework the test

Rework the test to improve the stability.
Signed-off-by: NXu Han <xuhan@redhat.com>
上级 f41ef572
- single_driver_install:
type = single_driver_install
cd_format_fixed = ide
q35:
cd_format_fixed = ahci
only Windows
cdroms += " virtio winutils"
kill_vm = yes
login_timeout = 360
need_uninstall = no
driver_install_timeout = 600
tmp_folder = C:\tmp
guest_alias = "Win7-32:w7\x86,Win7-64:w7\amd64,Win8-32:w8\x86,Win8-64:w8\amd64,Win8-32.1:w8.1\x86,Win8-64.1:w8.1\amd64,Win10-32:w10\x86,Win10-64:w10\amd64,Win2008-sp2-32:2k8\x86,Win2008-sp2-64:2k8\amd64,Win2008-r2-64:2k8R2\amd64,Win2012-64:2k12\amd64,Win2012-64r2:2k12R2\amd64,Win2016-64:2k16\amd64"
driver_install_cmd = "python WIN_UTILS:\win_driver_install.py %s %s %s %s %s"
show_file_ext_cmd = "reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f"
# cert_files: a list of certification files whose element is a pair of
# cert store and cert file path.
# (e.g. 'trustedpublisher=X:\virtio-win.cer')
cert_files = ""
devcon_dirname = "win7_"
Win2008..sp2:
devcon_dirname = "wlh_"
WinXP, Win2003:
devcon_dirname = "wxp_"
i386:
devcon_dirname += "x86"
x86_64:
devcon_dirname += "amd64"
devcon_path = "WIN_UTILS:\devcon\${devcon_dirname}\devcon.exe"
del devcon_dirname
variants:
- virtio_win_iso_media:
virtio_win_media_type = iso
cdroms += " virtio"
- virtio_win_vfd_media:
only with_netkvm with_viostor with_vioscsi
virtio_win_media_type = vfd
floppies = "virtio"
i386:
floppy_name_virtio = isos/windows/virtio-win_x86.vfd
x86_64:
floppy_name_virtio = isos/windows/virtio-win_amd64.vfd
floppy_readonly_virtio = yes
variants:
- with_netkvm:
driver_name = netkvm
nics += " nic2"
flexible_nic_index = yes
nic_model_nic1 = virtio
nic_model_nic2 = rtl8139
device_name = "Red Hat VirtIO Ethernet Adapter"
device_hwid = '"PCI\VEN_1AF4&DEV_1000" "PCI\VEN_1AF4&DEV_1041"'
nics += " nic2"
nic_model_nic1 = rtl8139
nic_model_nic2 = virtio
- with_viorng:
driver_name = viorng
device_name = "VirtIO RNG Device"
device_hwid = '"PCI\VEN_1AF4&DEV_1005" "PCI\VEN_1AF4&DEV_1044"'
no_virtio_rng:
virtio_rngs += " rng0"
backend_rng0 = rng-random
......@@ -33,6 +56,7 @@
no virtio_scsi
driver_name = viostor
device_name = "Red Hat VirtIO SCSI controller"
device_hwid = '"PCI\VEN_1AF4&DEV_1001" "PCI\VEN_1AF4&DEV_1042"'
drive_format_image1 = ide
q35:
drive_format_image1 = ahci
......@@ -49,10 +73,9 @@
no virtio_blk
driver_name = vioscsi
device_name = "Red Hat VirtIO SCSI pass-through controller"
cd_format_fixed = ide
device_hwid = '"PCI\VEN_1AF4&DEV_1004" "PCI\VEN_1AF4&DEV_1048"'
drive_format_image1 = ide
q35:
cd_format_fixed = ahci
drive_format_image1 = ahci
images += " stg"
image_name_stg = "images/storage"
......@@ -63,11 +86,13 @@
- with_vioserial:
driver_name = vioser
device_name = "VirtIO Serial Driver"
device_hwid = '"PCI\VEN_1AF4&DEV_1003" "PCI\VEN_1AF4&DEV_1043"'
virtio_ports = "vs"
virtio_port_type = serialport
- with_balloon:
driver_name = balloon
device_name = "VirtIO Balloon Driver"
device_hwid = '"PCI\VEN_1AF4&DEV_1002" "PCI\VEN_1AF4&DEV_1045"'
balloon = balloon0
balloon_dev_devid = balloon0
balloon_dev_add_bus = yes
......@@ -75,3 +100,4 @@
no Host_RHEL.m6
driver_name = pvpanic
device_name = "QEMU PVPanic Device"
device_hwid = '"ACPI\QEMU0001"'
import os
import re
import logging
from virttest import utils_misc
from virttest import error_context
from aexpect import ShellCmdError
from aexpect import ShellProcessTerminatedError
from virttest import utils_misc
from virttest.utils_windows import virtio_win, wmic
from virttest.utils_test.qemu import windrv_verify_running
QUERY_TIMEOUT = 360
INSTALL_TIMEOUT = 360
OPERATION_TIMEOUT = 120
def _chk_cert(session, cert_path):
chk_cmd = "certutil -verify %s"
chk_cmd %= cert_path
# it may take a while to verify cert file so lets wait a little longer
out = session.cmd(chk_cmd, timeout=QUERY_TIMEOUT)
if re.search("Expired certificate", out, re.I):
logging.warning("Certificate '%s' is expired!", cert_path)
if re.search("Incomplete certificate chain", out, re.I):
logging.warning("Incomplete certificate chain! Details:\n%s", out)
def _add_cert(session, cert_path, store):
add_cmd = "certutil -addstore -f %s %s"
add_cmd %= (store, cert_path)
session.cmd(add_cmd, timeout=OPERATION_TIMEOUT)
def _pnpdrv_info(session, name_pattern, props=None):
cmd = wmic.make_query("path win32_pnpsigneddriver",
"DeviceName like '%s'" % name_pattern,
props=props, get_swch=wmic.FMT_TYPE_LIST)
return wmic.parse_list(session.cmd(cmd, timeout=QUERY_TIMEOUT))
@error_context.context_aware
......@@ -17,153 +45,106 @@ def run(test, params, env):
3) Reboot vm (Based on step 2)
4) Update / Downgrade / Install driver
5) Reboot vm
6) Backup driver installation logs
6) Verify installed driver
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""
inst_timeout = int(params.get("driver_install_timeout", INSTALL_TIMEOUT))
driver_name = params["driver_name"]
device_name = params["device_name"]
device_hwid = params["device_hwid"]
def show_file_extentions(session):
"""
Show file extentions in windows guest.
:param session: VM session.
"""
show_file_ext_cmd = params.get("show_file_ext_cmd")
session.cmd(show_file_ext_cmd)
def get_installation_logs(session):
"""
Get driver installation log.
:param session: VM session.
"""
tmp_debug = r"C:\Windows\DPINST.log, C:\driver_install.log"
driver_logs = params.get("driver_debug_file", tmp_debug)
def retrieve_log(file_path):
"""
Retrieve logfile from guest to log
:param file_path: file path in guest.
:return file path save to host.
"""
basename = re.split(r'\\', file_path)[-1]
logfile = os.path.join(test.resultsdir, basename)
if not session.cmd_status("dir %s" % file_path):
content = session.cmd_output("type %s" % file_path)
with open(logfile, 'w') as fd:
fd.writelines(content)
return logfile
return map(retrieve_log, driver_logs.split(','))
def reboot(vm, timeout=600):
"""
Reboot guest.
:param vm: VM onject.
"""
nic_idx = len(vm.virtnet) - 1
while nic_idx >= 0:
try:
return vm.reboot(nic_index=nic_idx, timeout=timeout)
except Exception:
nic_idx -= 1
if nic_idx < 0:
raise
logging.warn("Unable to login guest, "
"try to login via nic %d" % nic_idx)
def get_driver_path(session, driver_name):
"""
Get the driver path which would be installed.
:param session: VM session.
:param driver_name: Driver name.
:return driver_path: Return the driver path.
"""
guest_name = params["guest_name"]
alias_map = params.get("guest_alias")
vol_virtio_key = "VolumeName like '%virtio-win%'"
vol_virtio = utils_misc.get_win_disk_vol(session, vol_virtio_key)
logging.debug("vol_virtio is %s" % vol_virtio)
if alias_map:
guest_list = dict([x.split(":") for x in alias_map.split(",")])
guest_name = guest_list[guest_name]
# For driver virtio serial, the path name is not same as driver name,
# need udpate the path here.
if driver_name == "vioser":
driver_name = "vioserial"
driver_path = r"%s:\%s\%s" % (vol_virtio, driver_name, guest_name)
logging.debug("The driver which would be installed is %s" % driver_path)
return driver_path
def install_driver(session, operation):
"""
Install / Uninstall / Query driver.
:param session: VM session.
:param operation: Install / Uninstall / Query driver.
"""
driver_name = params["driver_name"]
device_name = params["device_name"]
driver_path = get_driver_path(session, driver_name)
driver_install_cmd = params["driver_install_cmd"]
driver_name = r"--driver_name %s" % driver_name
device_name = "--device_name \"%s\"" % device_name
operation = r"--%s" % operation
vol_utils = utils_misc.get_winutils_vol(session)
driver_install_cmd = re.sub("WIN_UTILS", vol_utils, driver_install_cmd)
vol_utils = r"--vol_utils %s:" % vol_utils
driver_path = r"--driver_path %s" % driver_path
driver_install_cmd = driver_install_cmd % (operation, driver_path,
driver_name, device_name,
vol_utils)
install_timeout = int(params.get("driver_install_timeout", 600))
session.cmd(driver_install_cmd, timeout=install_timeout)
error_context.context("Boot up guest with setup parameters", logging.info)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
login_timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=login_timeout)
session = vm.wait_for_login()
# wait for cdroms having driver installed in case that
# they are new appeared in this test
utils_misc.wait_for(lambda: utils_misc.get_winutils_vol(session),
timeout=OPERATION_TIMEOUT, step=10)
devcon_path = utils_misc.set_winutils_letter(session,
params["devcon_path"])
status, output = session.cmd_status_output("dir %s" % devcon_path,
timeout=OPERATION_TIMEOUT)
if status:
test.error("Not found devcon.exe, details: %s" % output)
media_type = params["virtio_win_media_type"]
try:
error_context.context("Show file extentions", logging.info)
show_file_extentions(session)
session.close()
session = reboot(vm)
uninstall_flag = params.get("need_uninstall", "no")
if uninstall_flag == "yes":
operation = "uninstall_driver"
error_context.context("Uninstall driver", logging.info)
install_driver(session, operation)
session = reboot(vm)
operation = "install_driver"
error_context.context("Install driver", logging.info)
install_driver(session, operation)
session = reboot(vm)
if uninstall_flag == "no":
operation = "verify_driver"
error_context.context("Verify driver is same as expected", logging.info)
install_driver(session, operation)
finally:
if session:
error_context.context("Get driver installation log", logging.info)
try:
get_installation_logs(session)
except (ShellCmdError, ShellProcessTerminatedError):
pass
session.close()
get_drive_letter = getattr(virtio_win, "drive_letter_%s" % media_type)
get_product_dirname = getattr(virtio_win,
"product_dirname_%s" % media_type)
get_arch_dirname = getattr(virtio_win, "arch_dirname_%s" % media_type)
except AttributeError:
test.error("Not supported virtio win media type '%s'", media_type)
viowin_ltr = get_drive_letter(session)
if not viowin_ltr:
test.error("Could not find virtio-win drive in guest")
guest_name = get_product_dirname(session)
if not guest_name:
test.error("Could not get product dirname of the vm")
guest_arch = get_arch_dirname(session)
if not guest_arch:
test.error("Could not get architecture dirname of the vm")
inf_middle_path = ("{name}\\{arch}" if media_type == "iso"
else "{arch}\\{name}").format(name=guest_name,
arch=guest_arch)
inf_find_cmd = 'dir /b /s %s\\%s.inf | findstr "\\%s\\\\"'
inf_find_cmd %= (viowin_ltr, driver_name, inf_middle_path)
inf_path = session.cmd(inf_find_cmd, timeout=OPERATION_TIMEOUT).strip()
logging.info("Found inf file '%s'", inf_path)
expected_ver = session.cmd("findstr DriverVer= %s" % inf_path,
timeout=OPERATION_TIMEOUT)
expected_ver = expected_ver.strip().split(",", 1)[-1]
if not expected_ver:
test.error("Failed to find driver version from inf file")
logging.info("Target version is '%s'", expected_ver)
if params.get("need_uninstall", "no") == "yes":
error_context.context("Uninstalling previous installed driver",
logging.info)
for inf_name in _pnpdrv_info(session, device_name, ["InfName"]):
uninst_store_cmd = "pnputil /f /d %s" % inf_name
status, output = session.cmd_status_output(uninst_store_cmd,
inst_timeout)
if status:
test.error("Failed to uninstall driver '%s' from store, "
"details:\n%s" % (driver_name, output))
uninst_cmd = "%s remove %s" % (devcon_path, device_hwid)
status, output = session.cmd_status_output(uninst_cmd, inst_timeout)
# acceptable status: OK(0), REBOOT(1)
if status > 1:
test.error("Failed to uninstall driver '%s', details:\n"
"%s" % (driver_name, output))
session = vm.reboot(session)
error_context.context("Installing certificates", logging.info)
cert_files = utils_misc.set_winutils_letter(session,
params.get("cert_files", ""))
cert_files = [cert.split("=", 1) for cert in cert_files.split()]
for store, cert in cert_files:
_chk_cert(session, cert)
_add_cert(session, cert, store)
error_context.context("Installing target driver", logging.info)
inst_cmd = "%s updateni %s %s" % (devcon_path, inf_path, device_hwid)
status, output = session.cmd_status_output(inst_cmd, inst_timeout)
if status > 1:
test.fail("Failed to install driver '%s', "
"details:\n%s" % (driver_name, output))
error_context.context("Verifying target driver", logging.info)
session = vm.reboot(session)
windrv_verify_running(session, test, driver_name)
ver_list = _pnpdrv_info(session, device_name, ["DriverVersion"])
if expected_ver not in ver_list:
test.fail("The expected driver version is '%s', but "
"found '%s'" % (expected_ver, ver_list))
session.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册