Skip to content

Commit

Permalink
utils_disk: move new_disk_vol_name() to utils_disk
Browse files Browse the repository at this point in the history
reorganise disk related method to utils_disk.

Signed-off-by: Balamuruhan S <[email protected]>
  • Loading branch information
Balamuruhan S committed Jun 4, 2019
1 parent 3852a5c commit 43de837
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
20 changes: 20 additions & 0 deletions virttest/utils_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from virttest import error_context
from virttest import utils_numeric
from virttest.libvirt_xml import pool_xml
from virttest.compat_52lts import decode_to_text
from virttest.compat_52lts import results_stdout_52lts

Expand Down Expand Up @@ -835,6 +836,25 @@ def get_disk_by_serial(serial_str, session=None):
return disk


def new_disk_vol_name(pool_name):
"""
According to BZ#1138523, the new volume name must be the next
created partition(sdb1, etc.), so we need to inspect the original
partitions of the disk then count the new partition number.
:param pool_name: Disk pool name
:return: New volume name or none
"""
poolxml = pool_xml.PoolXML.new_from_dumpxml(pool_name)
if poolxml.get_type(pool_name) != "disk":
logging.error("This is not a disk pool")
return None
disk = poolxml.get_source().device_path[5:]
part_num = len(list(filter(lambda s: s.startswith(disk),
get_parts_list())))
return disk + str(part_num)


class Disk(object):

"""
Expand Down
19 changes: 0 additions & 19 deletions virttest/utils_test/libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3287,25 +3287,6 @@ def exec_virsh_edit(source, edit_cmd, connect_uri="qemu:///system"):
return False


def new_disk_vol_name(pool_name):
"""
According to BZ#1138523, the new volume name must be the next
created partition(sdb1, etc.), so we need to inspect the original
partitions of the disk then count the new partition number.
:param pool_name: Disk pool name
:return: New volume name or none
"""
poolxml = pool_xml.PoolXML.new_from_dumpxml(pool_name)
if poolxml.get_type(pool_name) != "disk":
logging.error("This is not a disk pool")
return None
disk = poolxml.get_source().device_path[5:]
part_num = len(list(filter(lambda s: s.startswith(disk),
utils_misc.utils_disk.get_parts_list())))
return disk + str(part_num)


def update_polkit_rule(params, pattern, new_value):
"""
This function help to update the rule during testing.
Expand Down

0 comments on commit 43de837

Please sign in to comment.