@@ -775,13 +775,14 @@ def fill_null_in_vm(vm, target, size_value=500):
775775 raise exceptions .TestError (str (e ))
776776
777777
778- def check_virtual_disk_io (vm , partition , path = "/dev/%s" ):
778+ def check_virtual_disk_io (vm , partition , path = "/dev/%s" , umount = True ):
779779 """
780780 Check if the disk partition in vm can be normally used.
781781
782782 :param vm: Vm instance
783783 :param partition: the disk partition in vm to be checked.
784784 :param path: the folder path for the partition
785+ :param umount: bool, if need to umount disk.
785786 :return: if the disk can be used, return True
786787 """
787788 session = None
@@ -790,11 +791,21 @@ def check_virtual_disk_io(vm, partition, path="/dev/%s"):
790791 cmd = (
791792 "fdisk -l && mkfs.ext4 -F {0} && "
792793 "mkdir -p test && mount {0} test && echo"
793- " teststring > test/testfile && umount test " .format (path % partition )
794+ " teststring > test/testfile" .format (path % partition )
794795 )
795796 status , output = session .cmd_status_output (cmd )
796797 LOG .debug ("Disk operation in VM:\n exit code:\n %s\n output:\n %s" , status , output )
797- return status == 0
798+ if status != 0 :
799+ return False
800+ if umount :
801+ umount_cmd = "umount test"
802+ u_status , u_output = session .cmd_status_output (umount_cmd )
803+ LOG .debug (
804+ "Disk operation in VM:\n exit code:\n %s\n output:\n %s" , u_status , u_output
805+ )
806+ if u_status != 0 :
807+ return False
808+ return True
798809 except Exception as err :
799810 LOG .debug ("Error happens when check disk io in vm: %s" , str (err ))
800811 return False
0 commit comments