未验证 提交 45522d60 编写于 作者: L Longxiang Lyu 提交者: GitHub

Merge pull request #2155 from ybduan/umount_wipefs

umount_wipefs: add umount and wipefs steps
......@@ -22,6 +22,7 @@
show_dev_cmd = "ls {0}"
mount_cmd = "mkdir -p /media && mount -t ${fs_type} {0} /media"
show_mount_cmd = "mount | grep {0}"
wipefs_cmd = "wipefs -a {0}"
umount_cmd = "umount {0}"
testfile_name = "/media/format_disk-test.txt"
writefile_cmd = "echo %s > %s"
......
......@@ -231,20 +231,19 @@
drive_index_stg = 1
create_image_stg = yes
remove_image_stg = yes
image_size_stg = 10M
fdisk_string = "10 MB, 10485760 bytes"
format_timeout = 400
image_size_stg = 16G
check_serial_option = yes
check_removable_option = yes
check_io_size_option = yes
# The following parameters will be overridden in guest-os config files.
create_partition_cmd = ""
format_cmd = "yes |mkfs $(readlink -f `ls /dev/disk/by-path/* | grep usb`)"
format_cmd = "yes | mkfs.ext4 {0}"
list_disk_cmd = ""
set_online_cmd = ""
chk_mount_cmd = "grep -qs $(readlink -f `ls /dev/disk/by-path/* | grep usb`) /proc/mounts"
mount_cmd = "mount $(readlink -f `ls /dev/disk/by-path/* | grep usb`) /media"
umount_cmd = "umount $(readlink -f `ls /dev/disk/by-path/* | grep usb`)"
show_mount_cmd = "mount | grep {0}"
wipefs_cmd = "wipefs -a {0}"
mount_cmd = "mkdir -p /media && mount {0} /media"
umount_cmd = "umount {0}"
testfile_name = "/media/usb_storage-test.txt"
writefile_cmd = "echo "set -e" > /media/md5chk.sh;"
writefile_cmd += " out=%s;"
......@@ -317,7 +316,6 @@
force_create_image_image1 = no
remove_image = yes
remove_image_image1 = no
cmd_timeout = 1000
stg_image_size = 1G
stg_image_boot = no
stg_image_format = qcow2
......
......@@ -31,9 +31,10 @@ def run(test, params, env):
error_context.context("Login to the guest", logging.info)
session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
cmd_timeout = int(params.get("cmd_timeout", 360))
os_type = params["os_type"]
drive_path = ""
if params.get("os_type") == 'linux':
if os_type == 'linux':
drive_name = params.objects("images")[-1]
drive_id = params["blk_extra_params_%s" % drive_name].split("=")[1]
# If a device option(bool/str) in qemu cmd line doesn't have a value,
......@@ -50,7 +51,7 @@ def run(test, params, env):
create_partition_cmd = params.get("create_partition_cmd")
if create_partition_cmd:
has_dispart = re.findall("diskpart", create_partition_cmd, re.I)
if (params.get("os_type") == 'windows' and has_dispart):
if (os_type == 'windows' and has_dispart):
error_context.context("Get disk list in guest")
list_disk_cmd = params.get("list_disk_cmd")
status, output = session.cmd_status_output(list_disk_cmd,
......@@ -72,6 +73,19 @@ def run(test, params, env):
format_cmd = params.get("format_cmd", "").format(drive_path)
if format_cmd:
if os_type == 'linux':
show_mount_cmd = params["show_mount_cmd"].format(drive_path)
status = session.cmd_status(show_mount_cmd)
if not status:
error_context.context("Umount before format", logging.info)
umount_cmd = params["umount_cmd"].format(drive_path)
status, output = session.cmd_status_output(umount_cmd,
timeout=cmd_timeout)
if status != 0:
test.fail("Failed to umount with error: %s" % output)
error_context.context("Wipe existing filesystem", logging.info)
wipefs_cmd = params["wipefs_cmd"].format(drive_path)
session.cmd(wipefs_cmd)
error_context.context("Format the disk with cmd '%s'" % format_cmd,
logging.info)
status, output = session.cmd_status_output(format_cmd,
......
......@@ -62,7 +62,8 @@ def run(test, params, env):
logging.debug(string)
test.error("Could not find matched sub-string")
error_context.context("Verify matched string is same as expected")
error_context.context("Verify matched string is same as expected",
logging.info)
actual_result = m[0]
if "removable" in regex_str:
if actual_result in ["on", "yes", "true"]:
......@@ -86,7 +87,7 @@ def run(test, params, env):
test.fail("Could not find expected string:\n %s" %
("\n".join(fail_log)))
def _do_io_test_guest(session):
def _do_io_test_guest():
utils_test.run_virt_sub_test(test, params, env, "format_disk")
@error_context.context_aware
......@@ -118,20 +119,6 @@ def run(test, params, env):
return devname[0]
return "sda"
@error_context.context_aware
def _check_and_umount_usb(session):
chk_status = session.cmd_status(params["chk_mount_cmd"],
timeout=login_timeout)
if chk_status:
return
error_context.context("Unmounting usb disk", logging.info)
# choose to umount usb disk instead of ejecting it
# because if usb is removable it will not available after ejection
status, output = session.cmd_status_output(params["umount_cmd"],
timeout=login_timeout)
if status != 0:
test.error("Failed to umount with error: %s" % output)
@error_context.context_aware
def _check_serial_option(serial, regex_str, expect_str):
error_context.context("Set serial option to '%s'" % serial,
......@@ -148,9 +135,6 @@ def run(test, params, env):
if serial not in ["EMPTY_STRING", "NO_EQUAL_STRING"]:
# Verify in guest when serial is set to empty/null is meaningless.
_verify_string(serial, output, [serial])
_check_and_umount_usb(session)
_do_io_test_guest(session)
session.close()
@error_context.context_aware
......@@ -170,9 +154,6 @@ def run(test, params, env):
cmd = "dmesg | grep %s" % _get_usb_disk_name_in_guest(session)
output = session.cmd(cmd)
_verify_string(expect_str, output, [expect_str], re.I)
_check_and_umount_usb(session)
_do_io_test_guest(session)
session.close()
@error_context.context_aware
......@@ -206,9 +187,6 @@ def run(test, params, env):
expected_min_size = "512"
_verify_string(r"(\d+)\n(\d+)", output,
[expected_min_size, opt_io_size])
_check_and_umount_usb(session)
_do_io_test_guest(session)
session.close()
vm = env.get_vm(params["main_vm"])
......@@ -229,8 +207,8 @@ def run(test, params, env):
# No bus specified, default using "usb.0" for "usb-storage"
for i in params["chk_usb_info_keyword"].split(","):
_verify_string(i, output, [i])
_do_io_test_guest(session)
session.close()
_do_io_test_guest()
# this part is linux only
if params.get("check_serial_option") == "yes":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册