Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils_disk/libvirt_disk: add way to handle disk by path #3729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions virttest/utils_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from virttest import error_context
from virttest import utils_numeric
from virttest import utils_misc
from virttest import remote

PARTITION_TABLE_TYPE_MBR = "msdos"
Expand Down Expand Up @@ -1083,6 +1084,19 @@ def linux_disk_check(session, did):
clean_partition_linux(session, did)


def get_parts_list_by_path(session=None):
"""
Get all partitions as listed on /dev/disk/by-path
"""
err, out = utils_misc.cmd_status_output("ls /dev/disk/by-path",
shell=True, session=session)
if err:
raise exceptions.TestError("Failed to list partitions in /dev/disk/by-path")
r = out.split()
LOG.debug("Partitions by path: %s", r)
return r


def get_parts_list(session=None):
"""
Get all partition lists.
Expand Down Expand Up @@ -1118,6 +1132,23 @@ def get_added_parts(session, old_parts):
return added_parts


def get_added_parts_by_path(session, old_parts):
"""
Get newly added partition list comparing to old parts
Uses the information below /dev/disk/by-path instead
of /proc/partitions

:param session: the vm session
:param old_parts: list, the old partition list as listed
below /dev/disk/by-path
:return: list, the newly added partition list
"""
new_parts = get_parts_list_by_path(session)
added_parts = list(set(new_parts).difference(set(old_parts)))
LOG.info("Added parts:%s", added_parts)
return added_parts


def get_first_disk(session=None):
"""
Get the first disk device on host or guest
Expand Down
9 changes: 5 additions & 4 deletions virttest/utils_libvirt/libvirt_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,21 +588,22 @@ def fill_null_in_vm(vm, target, size_value=500):
raise exceptions.TestError(str(e))


def check_virtual_disk_io(vm, partition):
def check_virtual_disk_io(vm, partition, path="/dev/%s"):
"""
Check if the disk partition in vm can be normally used.

:param vm: Vm instance
:param partition: the disk partition in vm to be checked.
:param path: the folder path for the partition
:return: if the disk can be used, return True
"""
session = None
try:
session = vm.wait_for_login()
cmd = ("fdisk -l /dev/{0} && mkfs.ext4 -F /dev/{0} && "
"mkdir -p test && mount /dev/{0} test && echo"
cmd = ("fdisk -l && mkfs.ext4 -F {0} && "
"mkdir -p test && mount {0} test && echo"
" teststring > test/testfile && umount test"
.format(partition))
.format(path % partition))
status, output = session.cmd_status_output(cmd)
LOG.debug("Disk operation in VM:\nexit code:\n%s\noutput:\n%s",
status, output)
Expand Down
Loading