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 #3811

Closed
wants to merge 1 commit into from
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 @@ -24,6 +24,31 @@
LOG = logging.getLogger('avocado.' + __name__)


def get_disk_by_serial(session, serial):
"""
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 new disk in:\n%s" % o)


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