Skip to content

Commit

Permalink
Merge pull request avocado-framework#3110 from chunfuwen/add_fill_sth…
Browse files Browse the repository at this point in the history
…_in_vm_as_common_api

Add fill_sth_in_vm as common API in libvirt_disk.py
  • Loading branch information
kylazhang authored Aug 9, 2021
2 parents 0495e03 + d92ad63 commit 6143b1b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions virttest/utils_libvirt/libvirt_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from virttest import utils_misc
from virttest import utils_disk
from virttest import virsh
from virttest import utils_package

from virttest.libvirt_xml import vm_xml
from virttest.utils_test import libvirt
Expand Down Expand Up @@ -538,3 +539,33 @@ def create_remote_disk_by_same_metadata(vm, params):

remote_session.close()
return blk_source


def fill_null_in_vm(vm, target, size_value=500):
"""
File sth in the disk of VM
:param vm: VM guest
:param target: disk dev in VM
:param size_value: number in MiB
"""
try:
session = vm.wait_for_login()
if not utils_package.package_install(["parted"], session, timeout=300):
logging.error("Failed to install the required 'parted' package")
device_source = os.path.join(os.sep, 'dev', target)
libvirt.mk_label(device_source, session=session)
libvirt.mk_part(device_source, size="%sM" % size_value, session=session)
# Run partprobe to make the change take effect.
process.run("partprobe", ignore_status=True, shell=True)
libvirt.mkfs("/dev/%s1" % target, "ext3", session=session)
count_number = size_value - 100
cmd = ("mount /dev/%s1 /mnt && dd if=/dev/zero of=/mnt/testfile bs=1024 count=1024x%s "
" && umount /mnt" % (target, count_number))
s, o = session.cmd_status_output(cmd)
logging.info("Check disk operation in VM:\n%s", o)
session.close()
if s != 0:
raise exceptions.TestError("Error happened when executing command:\n%s" % cmd)
except Exception as e:
raise exceptions.TestError(str(e))

0 comments on commit 6143b1b

Please sign in to comment.