提交 009c3de5 编写于 作者: X Xiaoling Gao

qemu_guest_agent: new case of test guest-fstrim for windows vm

Signed-off-by: NXiaoling Gao <xiagao@redhat.com>
上级 2b329ae9
......@@ -129,7 +129,6 @@
time_service_start_cmd = net start w32time
pause_time = 180
- check_fstrim:
no Windows
gagent_check_type = fstrim
start_vm = no
disk_size = 1024
......@@ -140,6 +139,19 @@
format_disk_cmd = "yes|mkfs.ext4 DISK"
write_disk_cmd = "dd if=/dev/zero of=${mount_point}/file bs=1M count=800 oflag=direct"
delete_file_cmd = "rm ${mount_point}/file -f; sync"
Windows:
# for windows guest, only support win8+
no Win7,Win2008
start_vm = yes
driver_name = vioscsi
images += " stg"
image_name_stg = "images/storage"
image_format_stg = "qcow2"
image_size_stg = 5G
drv_extra_params = "discard=on"
force_create_image_stg = yes
remove_image_stg = yes
delete_file_cmd = "del /f /q"
- check_get_interfaces:
gagent_check_type = get_interfaces
image_snapshot = yes
......
......@@ -17,6 +17,8 @@ from virttest import utils_misc
from virttest import utils_disk
from virttest import env_process
from virttest import utils_net
from virttest import data_dir
from virttest import storage
class BaseVirtTest(object):
......@@ -2140,6 +2142,95 @@ class QemuGuestAgentBasicCheckWin(QemuGuestAgentBasicCheck):
"stamp in guest file." % write_timeout)
result_check("thaw", write_timeout, session)
@error_context.context_aware
def gagent_check_fstrim(self, test, params, env):
"""
Execute "guest-fstrim" command via guest agent.
Steps:
1) boot up guest with scsi backend device
2) init and format the data disk
3) get the original blocks of data disk
4) create fragment in data disk
5) check the used blocks
6) execute fstrim cmd via guest agent
7) check if the used blocks is decreased
:param test: kvm test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
def get_blocks():
"""
Get the used blocks of data disk.
:return: the used blocks
"""
blocks = process.system_output("stat -t %s" % image_filename_stg)
return blocks.strip().split()[2]
session = self._get_session(params, None)
self._open_session_list.append(session)
error_context.context("Format data disk.", logging.info)
image_size_stg = params["image_size_stg"]
disk_index = utils_misc.wait_for(
lambda: utils_disk.get_windows_disks_index(session,
image_size_stg), 120)
if not disk_index:
test.error("Didn't get windows disk index.")
logging.info("Clear readonly of disk and online it in windows guest.")
if not utils_disk.update_windows_disk_attributes(session, disk_index):
test.error("Failed to update windows disk attributes.")
mnt_point = utils_disk.configure_empty_disk(
session, disk_index[0], image_size_stg, "windows",
labeltype="msdos")
error_context.context("Check the original blocks of data disk.",
logging.info)
image_params_stg = params.object_params("stg")
image_filename_stg = storage.get_image_filename(
image_params_stg, data_dir.get_data_dir())
blocks_init = get_blocks()
logging.info("The blocks original is %s" % blocks_init)
error_context.context("Create fragment in data disk.", logging.info)
guest_dir = r"%s:" % mnt_point[0]
data_file = os.path.join(guest_dir,
"qga_fstrim%s" %
utils_misc.generate_random_string(5))
for i in range(5):
count = 1000 * (i + 1)
logging.info("Create %sM file in guest." % count)
cmd = "dd if=/dev/random of=%s bs=1M count=%d" % (data_file, count)
session.cmd(cmd, timeout=600)
delete_file_cmd = "%s %s" % (params["delete_file_cmd"],
data_file.replace("/", "\\"))
logging.info("Delete the guest file created just now.")
session.cmd(delete_file_cmd)
error_context.context("Check blocks of data disk before fstrim.",
logging.info)
blocks_before_fstrim = get_blocks()
if int(blocks_init) >= int(blocks_before_fstrim):
msg = "Fragment created failed in data disk\n"
msg += "the blocks original is %s\n" % blocks_init
msg += "the blocks before fstrim is %s." % blocks_before_fstrim
test.error("msg")
error_context.context("Execute the guest-fstrim cmd via qga.",
logging.info)
self.gagent.fstrim()
error_context.context("Check blocks of data disk after fstrim.",
logging.info)
blocks_after_fstrim = get_blocks()
if int(blocks_after_fstrim) >= int(blocks_before_fstrim):
msg = "Fstrim failed\n"
msg += "the blocks before fstrim is %s\n" % blocks_before_fstrim
msg += "the blocks after fstrim is %s." % blocks_after_fstrim
test.fail(msg)
def run(test, params, env):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册