Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the libvirt logging verbosity (not needed for qemu vms) #3721

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading