提交 282eaa5e 编写于 作者: Y ybduan

umount_wipefs: add umount and wipefs steps

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