Skip to content

Commit

Permalink
utils_test/libvirt: Reorg disk related APIs into utils_disk
Browse files Browse the repository at this point in the history
Reorganise disk related method to utils_disk and break circular
imports caused with respect to disk related APIs in utils_misc.

Signed-off-by: Balamuruhan S <[email protected]>
  • Loading branch information
Balamuruhan S committed Jun 5, 2019
1 parent 3852a5c commit 7a34ecb
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 95 deletions.
18 changes: 9 additions & 9 deletions selftests/unit/test_nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from virttest.unittest_utils import mock
from virttest import nfs
from virttest import utils_misc
from virttest import utils_disk
from virttest.staging import service


Expand Down Expand Up @@ -58,16 +58,16 @@ def setup_stubs_setup(self, nfs_obj):
os.makedirs.expect_call(nfs_obj.export_dir)
nfs_obj.exportfs.export.expect_call()
os.makedirs.expect_call(nfs_obj.mount_dir)
utils_misc.mount.expect_call(nfs_obj.mount_src, nfs_obj.mount_dir,
utils_disk.mount.expect_call(nfs_obj.mount_src, nfs_obj.mount_dir,
"nfs", perm=nfs_obj.mount_options)

def setup_stubs_is_mounted(self, nfs_obj):
utils_misc.is_mounted.expect_call(nfs_obj.mount_src,
nfs_obj.mount_dir,
"nfs").and_return(True)
utils_disk.is_mount.expect_call(nfs_obj.mount_src,
nfs_obj.mount_dir,
"nfs").and_return(True)

def setup_stubs_cleanup(self, nfs_obj):
utils_misc.umount.expect_call(nfs_obj.mount_src,
utils_disk.umount.expect_call(nfs_obj.mount_src,
nfs_obj.mount_dir,
"nfs")
nfs_obj.exportfs.reset_export.expect_call()
Expand All @@ -84,9 +84,9 @@ def setUp(self):
self.god.stub_function(process, "system_output")
self.god.stub_function(os.path, "isfile")
self.god.stub_function(os, "makedirs")
self.god.stub_function(utils_misc, "is_mounted")
self.god.stub_function(utils_misc, "mount")
self.god.stub_function(utils_misc, "umount")
self.god.stub_function(utils_disk, "is_mount")
self.god.stub_function(utils_disk, "mount")
self.god.stub_function(utils_disk, "umount")
self.god.stub_function(service.Factory, "create_service")
attr = getattr(nfs, "Exportfs")
setattr(attr, "already_exported", False)
Expand Down
5 changes: 3 additions & 2 deletions virttest/gluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from virttest import data_dir
from virttest import utils_misc
from virttest import utils_disk
from virttest import utils_net
from virttest import error_context
from virttest.compat_52lts import decode_to_text
Expand Down Expand Up @@ -184,7 +185,7 @@ def glusterfs_mount(g_uri, mount_point):
:param g_uri: stripped gluster uri from create_gluster_uri(.., True)
:type g_uri: str
"""
utils_misc.mount(g_uri, mount_point, "glusterfs", None,
utils_disk.mount(g_uri, mount_point, "glusterfs", None,
False, "fuse.glusterfs")


Expand Down Expand Up @@ -272,7 +273,7 @@ def file_exists(params, filename_path):
logging.error("Failed to mount gluster volume %s to"
" mount dir %s: %s" % (sg_uri, tmpdir_path, e))
finally:
if utils_misc.umount(sg_uri, tmpdir_path, "glusterfs", False,
if utils_disk.umount(sg_uri, tmpdir_path, "glusterfs", False,
"fuse.glusterfs"):
try:
os.rmdir(tmpdir_path)
Expand Down
9 changes: 5 additions & 4 deletions virttest/nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from avocado.core import exceptions

from virttest import utils_misc
from virttest import utils_disk
from virttest.utils_iptables import Iptables
from virttest.utils_conn import SSHConnection
from virttest.compat_52lts import results_stdout_52lts, results_stderr_52lts
Expand Down Expand Up @@ -183,20 +184,20 @@ def is_mounted(self):
:return: If the src is mounted as expect
:rtype: Boolean
"""
return utils_misc.is_mounted(self.mount_src, self.mount_dir, "nfs")
return utils_disk.is_mount(self.mount_src, self.mount_dir, "nfs")

def mount(self):
"""
Mount source into given mount point.
"""
return utils_misc.mount(self.mount_src, self.mount_dir, "nfs",
perm=self.mount_options)
return utils_disk.mount(self.mount_src, self.mount_dir, "nfs",
self.mount_options)

def umount(self):
"""
Umount the given mount point.
"""
return utils_misc.umount(self.mount_src, self.mount_dir, "nfs")
return utils_disk.umount(self.mount_src, self.mount_dir, "nfs")

def setup(self):
"""
Expand Down
7 changes: 4 additions & 3 deletions virttest/tests/unattended_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from avocado.utils import process
from avocado.utils import crypto
from avocado.utils import download
from avocado.utils import wait

from virttest import virt_vm
from virttest import asset
Expand Down Expand Up @@ -1120,10 +1121,10 @@ def terminate_syslog_server_thread():
def copy_file_from_nfs(src, dst, mount_point, image_name):
logging.info("Test failed before the install process start."
" So just copy a good image from nfs for following tests.")
utils_misc.mount(src, mount_point, "nfs", perm="ro")
utils_disk.mount(src, mount_point, "nfs", "ro")
image_src = utils_misc.get_path(mount_point, image_name)
shutil.copy(image_src, dst)
utils_misc.umount(src, mount_point, "nfs")
utils_disk.umount(src, mount_point, "nfs")


def string_in_serial_log(serial_log_file_path, string):
Expand Down Expand Up @@ -1390,7 +1391,7 @@ def copy_images():
if params.get("medium", "cdrom") == "import":
vm.shutdown()
try:
if utils_misc.wait_for(vm.is_dead, shutdown_cleanly_timeout, 1, 1):
if wait.wait_for(vm.is_dead, shutdown_cleanly_timeout, 1, 1):
logging.info("Guest managed to shutdown cleanly")
except qemu_monitor.MonitorError as e:
logging.warning("Guest apparently shut down, but got a "
Expand Down
28 changes: 25 additions & 3 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 @@ -65,7 +66,7 @@ def copytree(src, dst, overwrite=True, ignore=''):


def is_mount(src, dst=None, fstype=None, options=None, verbose=False,
session=None):
session=None, fstype_mtab=None):
"""
Check is src or dst mounted.
Expand Down Expand Up @@ -107,7 +108,8 @@ def is_mount(src, dst=None, fstype=None, options=None, verbose=False,
return False


def mount(src, dst, fstype=None, options=None, verbose=False, session=None):
def mount(src, dst, fstype=None, options=None, verbose=False, session=None,
fstype_mtab=None):
"""
Mount src under dst if it's really mounted, then remout with options.
Expand Down Expand Up @@ -135,7 +137,8 @@ def mount(src, dst, fstype=None, options=None, verbose=False, session=None):
return process.system(cmd, verbose=verbose) == 0


def umount(src, dst, fstype=None, verbose=False, session=None):
def umount(src, dst, fstype=None, verbose=False, session=None,
fstype_mtab=None):
"""
Umount src from dst, if src really mounted under dst.
Expand Down Expand Up @@ -835,6 +838,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
51 changes: 0 additions & 51 deletions virttest/utils_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
from virttest import error_context
from virttest import cartesian_config
from virttest import utils_selinux
from virttest import utils_disk
from virttest import logging_manager
from virttest.staging import utils_koji
from virttest.staging import service
Expand Down Expand Up @@ -991,56 +990,6 @@ def safe_rmdir(path, timeout=10):
(path, timeout, attempts))


def umount(src, mount_point, fstype, verbose=False, fstype_mtab=None):
"""
Umount the src mounted in mount_point.
:src: mount source
:mount_point: mount point
:type: file system type
:param fstype_mtab: file system type in mtab could be different
:type fstype_mtab: str
"""
return utils_disk.umount(src, mount_point, fstype, verbose)


def mount(src, mount_point, fstype, perm=None, verbose=False, fstype_mtab=None):
"""
Mount the src into mount_point of the host.
:src: mount source
:mount_point: mount point
:fstype: file system type
:perm: mount permission
:param fstype_mtab: file system type in mtab could be different
:type fstype_mtab: str
"""
return utils_disk.mount(src, mount_point, fstype, perm, verbose)


def is_mounted(src, mount_point, fstype, perm=None, verbose=False,
fstype_mtab=None):
"""
Check mount status from /etc/mtab
:param src: mount source
:type src: string
:param mount_point: mount point
:type mount_point: string
:param fstype: file system type
:type fstype: string
:param perm: mount permission
:type perm: string
:param verbose: if display mtab content
:type verbose: Boolean
:param fstype_mtab: file system type in mtab could be different
:type fstype_mtab: str
:return: if the src is mounted as expect
:rtype: Boolean
"""
return utils_disk.is_mount(src, mount_point, fstype, perm, verbose)


def install_host_kernel(job, params):
"""
Install a host kernel, given the appropriate params.
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
9 changes: 5 additions & 4 deletions virttest/utils_v2v.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from avocado.utils import path
from avocado.utils import process
from avocado.utils import wait
from avocado.core import exceptions
from virttest.compat_52lts import results_stdout_52lts, results_stderr_52lts, decode_to_text

Expand All @@ -21,7 +22,7 @@
from virttest import ppm_utils
from virttest import data_dir
from virttest import remote
from virttest import utils_misc
from virttest import utils_disk

try:
V2V_EXEC = path.find_command('virt-v2v')
Expand Down Expand Up @@ -101,7 +102,7 @@ def __init__(self, target, uri):
def cleanup(self):
# Cleanup NFS mount records
for src, dst, fstype in self.mount_record.values():
utils_misc.umount(src, dst, fstype)
utils_disk.umount(src, dst, fstype)

def get_cmd_options(self, params):
"""
Expand Down Expand Up @@ -154,7 +155,7 @@ def _compose_input_transport_options():
if not os.path.exists(mount_point):
os.makedirs(mount_point)

if not utils_misc.mount(
if not utils_disk.mount(
self.vddk_libdir_src,
mount_point,
'nfs',
Expand Down Expand Up @@ -469,7 +470,7 @@ def wait_for_x_start(self, timeout=30):
cmd = 'xset -q'
if self.run_cmd(cmd)[0] == 127:
return
utils_misc.wait_for(
wait.wait_for(
lambda: not bool(
self.run_cmd(
cmd,
Expand Down

0 comments on commit 7a34ecb

Please sign in to comment.