提交 0beb99ae 编写于 作者: Y Yiqiao Pu

Merge pull request #142 from xutian/change_media_windows

qemu.tests: add change_media test windows support
- change_media: - change_media:
no Windows
only RHEL
type = change_media type = change_media
virt_test_type = qemu virt_test_type = qemu
kill_vm = yes
monitor_type = qmp monitor_type = qmp
pre_command += "dd if=/dev/urandom of=/tmp/orig bs=10M count=1 && dd if=/dev/urandom of=/tmp/new bs=10M count=1 && mkisofs -o /tmp/orig.iso /tmp/orig && mkisofs -o /tmp/new.iso /tmp/new;" pre_command += "dd if=/dev/urandom of=/tmp/orig bs=10M count=1 && dd if=/dev/urandom of=/tmp/new bs=10M count=1 && mkisofs -o /tmp/orig.iso /tmp/orig && mkisofs -o /tmp/new.iso /tmp/new;"
post_command += "rm -rf /tmp/orig.iso /tmp/new.iso /tmp/orig /tmp/new;" post_command += "rm -rf /tmp/orig.iso /tmp/new.iso /tmp/orig /tmp/new;"
orig_img_name = /tmp/orig.iso orig_img_name = /tmp/orig.iso
new_img_name = /tmp/new.iso new_img_name = /tmp/new.iso
cd_mount_cmd = mount %s /mnt
cd_umount_cmd = umount /mnt
cdrom_cd1 = /tmp/orig.iso cdrom_cd1 = /tmp/orig.iso
Linux:
cd_mount_cmd = mount %s /mnt
cd_umount_cmd = umount /mnt
import logging import re
import time import time
import logging
from autotest.client.shared import error from autotest.client.shared import error
from virttest import utils_test, utils_misc from virttest import utils_test, utils_misc, data_dir
@error.context_aware @error.context_aware
...@@ -58,6 +59,7 @@ def run(test, params, env): ...@@ -58,6 +59,7 @@ def run(test, params, env):
time.sleep(10) time.sleep(10)
cdrom = params.get("cdrom_cd1") cdrom = params.get("cdrom_cd1")
cdrom = utils_misc.get_path(data_dir.get_data_dir(), cdrom)
device_name = vm.get_block({"file": cdrom}) device_name = vm.get_block({"file": cdrom})
if device_name is None: if device_name is None:
msg = "Unable to detect qemu block device for cdrom %s" % cdrom msg = "Unable to detect qemu block device for cdrom %s" % cdrom
...@@ -75,14 +77,30 @@ def run(test, params, env): ...@@ -75,14 +77,30 @@ def run(test, params, env):
if check_block_locked(device_name): if check_block_locked(device_name):
raise error.TestFail("Unused device is locked.") raise error.TestFail("Unused device is locked.")
error.context("mount cdrom to make status to locked", logging.info) if params.get("os_type") != "windows":
cdrom = utils_test.get_readable_cdroms(params, session)[0] error.context("mount cdrom to make status to locked", logging.info)
mount_cmd = params.get("cd_mount_cmd") % cdrom cdrom = utils_test.get_readable_cdroms(params, session)[0]
(status, output) = session.cmd_status_output(mount_cmd, timeout=360) mount_cmd = params.get("cd_mount_cmd") % cdrom
if status: (status, output) = session.cmd_status_output(mount_cmd, timeout=360)
msg = "Unable to mount cdrom. command: %s\nOutput: %s" % (mount_cmd, if status:
output) msg = "Unable to mount cdrom. "
raise error.TestError(msg) msg += "command: %s\nOutput: %s" % (mount_cmd, output)
raise error.TestError(msg)
else:
error.context("lock cdrom in guest", logging.info)
tmp_dir = params.get("tmp_dir", "c:\\")
eject_tool = utils_misc.get_path(data_dir.get_deps_dir(),
"cdrom/eject.exe")
vm.copy_files_to(eject_tool, tmp_dir)
output = session.cmd("wmic cdrom get Drive", timeout=120)
cd_vol = re.findall("[d-z]:", output, re.I)[0]
lock_cmd = "%s\\eject.exe -i on %s" % (tmp_dir, cd_vol)
(status, output) = session.cmd_status_output(lock_cmd)
if status:
msg = "Unable to lock cdrom. command: %s\n" % lock_cmd
msg += "Output: %s" % output
raise error.TestError(msg)
if not check_block_locked(device_name): if not check_block_locked(device_name):
raise error.TestFail("device is not locked after mount it in guest.") raise error.TestFail("device is not locked after mount it in guest.")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册