Skip to content

Commit

Permalink
Merge pull request #3721 from pevogam/libvirt-verbosity
Browse files Browse the repository at this point in the history
Reduce the libvirt logging verbosity (not needed for qemu vms)
  • Loading branch information
luckyh committed Aug 28, 2023
2 parents d36e741 + df6175e commit 7c6bf78
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions virttest/_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import sys
import importlib
import importlib.util
from importlib.machinery import (SourceFileLoader, SOURCE_SUFFIXES,
SourcelessFileLoader, BYTECODE_SUFFIXES,
ExtensionFileLoader, EXTENSION_SUFFIXES)
Expand Down Expand Up @@ -70,3 +71,20 @@ def load_source(name, path):
"""
spec = importlib.util.spec_from_file_location(name, path)
return _load_from_spec(spec)


def lazy_import(name):
""" Allows for an early import that is initialized upon use (lazy import).
:param name: Name of the module that is going to be imported
:type name: String
"""
spec = importlib.util.find_spec(name)
if spec is None:
raise ImportError(f"Could not import module {name}")
loader = importlib.util.LazyLoader(spec.loader)
spec.loader = loader
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
loader.exec_module(module)
return module
8 changes: 6 additions & 2 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,6 +53,12 @@
from virttest.test_setup.networking import NetworkProxies


# lazy imports for dependencies that are not needed in all modes of use
from virttest._wrappers import lazy_import
utils_libvirtd = lazy_import("virttest.utils_libvirtd")
virsh = lazy_import("virttest.virsh")


try:
import PIL.Image
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions virttest/utils_libvirtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions virttest/virsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 7c6bf78

Please sign in to comment.