Skip to content

Commit

Permalink
virttest: change dependency utils_misc -> utils_disk
Browse files Browse the repository at this point in the history
This patch doesn't do any logical changes to the code, all
the disk related API calls are changed from utils_misc to
utils_disk.

Signed-off-by: Balamuruhan S <[email protected]>
  • Loading branch information
balamuruhans committed Aug 19, 2019
1 parent 86817e1 commit 07144ed
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
20 changes: 10 additions & 10 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,
"nfs", perm=nfs_obj.mount_options)
utils_disk.mount.expect_call(nfs_obj.mount_src, nfs_obj.mount_dir,
"nfs", 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
7 changes: 4 additions & 3 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from virttest import test_setup
from virttest import virt_vm
from virttest import utils_misc
from virttest import utils_disk
from virttest import storage
from virttest import utils_libguestfs
from virttest import qemu_storage
Expand Down Expand Up @@ -95,17 +96,17 @@ def preprocess_image(test, params, image_name, vm_process_status=None):
if params.get("force_create_image") == "yes":
create_image = True
elif (params.get("create_image") == "yes" and not
storage.file_exists(params, image_filename)):
utils_disk.file_exists(params, image_filename)):
create_image = True

if params.get("backup_image_before_testing", "no") == "yes":
image = qemu_storage.QemuImg(params, base_dir, image_name)
image.backup_image(params, base_dir, "backup", True, True)
if create_image:
if storage.file_exists(params, image_filename):
if utils_disk.file_exists(params, image_filename):
# As rbd image can not be covered, so need remove it if we need
# force create a new image.
storage.file_remove(params, image_filename)
utils_disk.file_remove(params, image_filename)
image = qemu_storage.QemuImg(params, base_dir, image_name)
logging.info("Create image on %s." % image.storage_type)
image.create(params)
Expand Down
9 changes: 5 additions & 4 deletions virttest/nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from virttest import utils_misc
from virttest import test_setup
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 @@ -212,20 +213,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
5 changes: 3 additions & 2 deletions virttest/qemu_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from avocado.utils import process

from virttest import utils_misc
from virttest import utils_disk
from virttest import virt_vm
from virttest import storage
from virttest import data_dir
Expand Down Expand Up @@ -509,7 +510,7 @@ def check_image(self, params, root_dir, force_share=False):
image_is_checkable = self.image_format in ['qcow2', 'qed']
force_share &= self.cap_force_share

if (storage.file_exists(params, image_filename) or
if (utils_disk.file_exists(params, image_filename) or
self.is_remote_image()) and image_is_checkable:
check_img = self.support_cmd("check") and self.support_cmd("info")
if not check_img:
Expand Down Expand Up @@ -566,7 +567,7 @@ def check_image(self, params, root_dir, force_share=False):
"integrity problem was found "
"though. (%s)" % image_filename)
else:
if not storage.file_exists(params, image_filename):
if not utils_disk.file_exists(params, image_filename):
logging.debug("Image file %s not found, skipping check",
image_filename)
elif not image_is_checkable:
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 @@ -1129,10 +1130,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 @@ -1478,7 +1479,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
22 changes: 19 additions & 3 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 @@ -23,6 +24,7 @@
from virttest import remote
from virttest import utils_misc
from virttest import ssh_key
from virttest import utils_disk

try:
V2V_EXEC = path.find_command('virt-v2v')
Expand Down Expand Up @@ -106,7 +108,10 @@ def cleanup(self):
Cleanup NFS mount records
"""
for src, dst, fstype in self.mount_records.values():
utils_misc.umount(src, dst, fstype)
utils_disk.umount(src, dst, fstype)
# Cleanup NFS mount records
for src, dst, fstype in self.mount_record.values():
utils_disk.umount(src, dst, fstype)

self.cleanup_authorized_keys_in_vmx()

Expand Down Expand Up @@ -201,6 +206,17 @@ def _compose_input_transport_options():

mount_point = v2v_mount(
self.vddk_libdir_src, 'vddk_libdir')
if not os.path.exists(mount_point):
os.makedirs(mount_point)

if not utils_disk.mount(
self.vddk_libdir_src,
mount_point,
'nfs',
verbose=True):
raise exceptions.TestError(
'Mount %s for %s failed' %
(self.vddk_libdir_src, mount_point))
self.vddk_libdir = mount_point
self.mount_records[len(self.mount_records)] = (
self.vddk_libdir_src, self.vddk_libdir, None)
Expand Down Expand Up @@ -523,7 +539,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 Expand Up @@ -1088,7 +1104,7 @@ def v2v_mount(src, dst='v2v_mount_point'):
if not os.path.exists(mount_point):
os.makedirs(mount_point)

if not utils_misc.mount(
if not utils_disk.mount(
src,
mount_point,
'nfs',
Expand Down

0 comments on commit 07144ed

Please sign in to comment.