diff --git a/virttest/env_process.py b/virttest/env_process.py index b6aefdaec75..1aff7529068 100644 --- a/virttest/env_process.py +++ b/virttest/env_process.py @@ -34,12 +34,10 @@ from virttest import storage from virttest import utils_libguestfs from virttest import qemu_storage -from virttest import utils_libvirtd from virttest import data_dir from virttest import utils_net from virttest import nfs from virttest import libvirt_vm -from virttest import virsh from virttest import utils_test from virttest import utils_iptables from virttest import utils_package @@ -1135,6 +1133,7 @@ def preprocess(test, params, env): migrate_setup.migrate_pre_setup(dest_uri, params) # Map hostname and IP address of the hosts to avoid virsh # to error out of resolving + from virttest import virsh hostname_ip = {str(virsh.hostname()): params['local_ip']} session = test_setup.remote_session(params) _, remote_hostname = session.cmd_status_output('hostname') @@ -1269,6 +1268,7 @@ def preprocess(test, params, env): if not params.get("hugepage_path"): params["hugepage_path"] = h.hugepage_path if vm_type == "libvirt": + from virttest import utils_libvirtd if libvirtd_inst is None: libvirtd_inst = utils_libvirtd.Libvirtd() libvirtd_inst.restart() @@ -1744,6 +1744,7 @@ def postprocess(test, params, env): h = test_setup.HugePageConfig(params) h.cleanup() if vm_type == "libvirt": + from virttest import utils_libvirtd if libvirtd_inst is None: libvirtd_inst = utils_libvirtd.Libvirtd() libvirtd_inst.restart() @@ -1781,6 +1782,7 @@ def postprocess(test, params, env): LOG.error(details) if vm_type == "libvirt": + from virttest import utils_libvirtd if params.get("setup_libvirt_polkit") == "yes": try: pol = test_setup.LibvirtPolkitConfig(params) @@ -2053,6 +2055,7 @@ def store_vm_info(vm, log_filename, info_cmd='registers', LOG.warn(err) return False elif vmtype == "libvirt": + from virttest import virsh try: result = virsh.qemu_monitor_command(vm.name, "info %s" % info_cmd, diff --git a/virttest/utils_libvirtd.py b/virttest/utils_libvirtd.py index 0642338b468..c1256ece45e 100644 --- a/virttest/utils_libvirtd.py +++ b/virttest/utils_libvirtd.py @@ -56,6 +56,7 @@ def __init__(self, service_name=None, session=None, all_daemons=False): self.daemons = [] self.service_list = [] + # we only import this module conditionally to make this warning always applicable if LIBVIRTD is None: LOG.warning("Libvirtd service is not available in host, " "utils_libvirtd module will not function normally") diff --git a/virttest/virsh.py b/virttest/virsh.py index 822c798a22a..5a476633e90 100644 --- a/virttest/virsh.py +++ b/virttest/virsh.py @@ -71,6 +71,7 @@ try: VIRSH_EXEC = path.find_command("virsh") except path.CmdNotFoundError: + # we only import this module conditionally to make this warning always applicable logging.getLogger('avocado.app').warning( "Virsh executable not set or found on path, virsh module will not " "function normally")