Skip to content

Commit

Permalink
env_process: Refactor version info logging step
Browse files Browse the repository at this point in the history
After checking all test-relevant package versions, the dict carrying
the information must be logged into the test data. That was done in the
preprocess and postprocess functions in virttest.env_process. Write a
Setuper subclass that implements that in the setup method and register
the setuper in the env_process setup_manager.

While on it, remove the version_info dict from virttest.env_process as
it was the last element using it. Move it to the
virttest.test_setup.requirement_checks submodule instead, where a bunch
of classes that we just refactored use it. Now, if we compare the API of
virttest.env_process to the one existing in 753d3f5, it remains the
same.

This is a patch from a larger patch series refactoring the env_process
preprocess and postprocess functions. In each of these patches, a
pre/post process step is identified and replaced with a Setuper subclass
so the following can finally be met:
    - Only cleanup steps of successful setup steps are run to avoid
      possible environment corruption or hard to read errors.
    - Running setup/cleanup steps symmetrically during env pre/post
      process.
    - Reduce explicit pre/post process function code length.

Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
  • Loading branch information
bgartzi committed Dec 10, 2024
1 parent 7b2d3fc commit ba7ced3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 2 additions & 5 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
CheckRunningAsRoot,
CheckVirtioWinVersion,
LogBootloaderVersion,
LogVersionInfo,
)
from virttest.test_setup.storage import StorageConfig
from virttest.test_setup.verify import VerifyHostDMesg
Expand Down Expand Up @@ -110,8 +111,6 @@

LOG = logging.getLogger("avocado." + __name__)

version_info = {}


def preprocess_image(test, params, image_name, vm_process_status=None):
"""
Expand Down Expand Up @@ -1023,15 +1022,13 @@ def preprocess(test, params, env):
_setup_manager.register(LogBootloaderVersion)
_setup_manager.register(CheckVirtioWinVersion)
_setup_manager.register(CheckLibvirtVersion)
_setup_manager.register(LogVersionInfo)
_setup_manager.do_setup()

vm_type = params.get("vm_type")

base_dir = data_dir.get_data_dir()

# Write it as a keyval
test.write_test_keyval(version_info)

libvirtd_inst = None

# If guest is configured to be backed by hugepages, setup hugepages in host
Expand Down
19 changes: 15 additions & 4 deletions virttest/test_setup/requirement_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

LOG = logging.getLogger(__name__)

version_info = {}


class CheckInstalledCMDs(Setuper):
def setup(self):
Expand Down Expand Up @@ -53,7 +55,7 @@ def setup(self):
kvm_version = "Unknown"

LOG.debug("KVM version: %s" % kvm_version)
env_process.version_info["kvm_version"] = str(kvm_version)
version_info["kvm_version"] = str(kvm_version)

# Checking required kernel, if not satisfied, cancel test
if self.params.get("required_kernel"):
Expand Down Expand Up @@ -112,7 +114,7 @@ def setup(self):
)

LOG.debug("KVM userspace version(qemu): %s", kvm_userspace_version)
env_process.version_info["qemu_version"] = str(kvm_userspace_version)
version_info["qemu_version"] = str(kvm_userspace_version)

# Checking required qemu, if not satisfied, cancel test
if self.params.get("required_qemu"):
Expand Down Expand Up @@ -145,7 +147,7 @@ def setup(self):
).stdout_text.strip()
except a_process.CmdError:
vm_bootloader_ver = "Unknown"
env_process.version_info["vm_bootloader_version"] = str(vm_bootloader_ver)
version_info["vm_bootloader_version"] = str(vm_bootloader_ver)
LOG.debug("vm bootloader version: %s", vm_bootloader_ver)

def cleanup(self):
Expand Down Expand Up @@ -214,8 +216,17 @@ def setup(self):
).stdout_text.strip()
except a_process.CmdError:
libvirt_version = "Unknown"
env_process.version_info["libvirt_version"] = str(libvirt_version)
version_info["libvirt_version"] = str(libvirt_version)
LOG.debug("KVM userspace version(libvirt): %s" % libvirt_version)

def cleanup(self):
pass


class LogVersionInfo(Setuper):
def setup(self):
# Write package version info dict as a keyval
self.test.write_test_keyval(version_info)

def cleanup(self):
pass

0 comments on commit ba7ced3

Please sign in to comment.