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_libvirt/libvirt_disk: add function to get disk by serial #3814

Closed
Closed
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
25 changes: 25 additions & 0 deletions virttest/utils_libvirt/libvirt_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ def get_non_root_disk_name(session):
return name.strip(), mpoint.strip()


def get_disk_by_serial(session, serial):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have same function in utils_disk.py.

def get_disk_by_serial(serial_str, session=None):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer. I'll close this one.

"""
Gets the disk by its serial value

:param session: VM session
:param serial: The expected serial value
:return path: absolute path of disk
e.g. /dev/sda
:raises TestError: If the disk cannot be found.
"""
cmd = "lsblk -n -p -l -o NAME,SERIAL"
s, o = utils_misc.cmd_status_output(cmd,
ignore_status=False,
shell=True,
verbose=True,
session=session)
if s:
raise exceptions.TestError("Couldn't list block devices: '%s'" % o)
for line in o.split("\n"):
match = re.match(r'(/dev/[a-z]+)[\s\t]+%s' % serial, line)
if match:
return match.groups()[0]
raise exceptions.TestError("Couldn't find disk with serial in:\n%s" % o)


def create_disk(disk_type, path=None, size="500M", disk_format="raw", extra='',
session=None):
"""
Expand Down
Loading