Skip to content

Commit

Permalink
env_process: Refactor libvirt version verification step
Browse files Browse the repository at this point in the history
libvirt version is checked and compared to the required version,
if there's one. 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.

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 b9e10dc commit 7b2d3fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
16 changes: 2 additions & 14 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from virttest.test_setup.requirement_checks import (
CheckInstalledCMDs,
CheckKernelVersion,
CheckLibvirtVersion,
CheckQEMUVersion,
CheckRunningAsRoot,
CheckVirtioWinVersion,
Expand Down Expand Up @@ -1021,26 +1022,13 @@ def preprocess(test, params, env):
_setup_manager.register(CheckQEMUVersion)
_setup_manager.register(LogBootloaderVersion)
_setup_manager.register(CheckVirtioWinVersion)
_setup_manager.register(CheckLibvirtVersion)
_setup_manager.do_setup()

vm_type = params.get("vm_type")

base_dir = data_dir.get_data_dir()

# Get the Libvirt version
if vm_type == "libvirt":
libvirt_ver_cmd = params.get(
"libvirt_ver_cmd", "libvirtd -V|awk -F' ' '{print $3}'"
)
try:
libvirt_version = a_process.run(
libvirt_ver_cmd, shell=True
).stdout_text.strip()
except a_process.CmdError:
libvirt_version = "Unknown"
version_info["libvirt_version"] = str(libvirt_version)
LOG.debug("KVM userspace version(libvirt): %s" % libvirt_version)

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

Expand Down
21 changes: 21 additions & 0 deletions virttest/test_setup/requirement_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,24 @@ def setup(self):

def cleanup(self):
pass


class CheckLibvirtVersion(Setuper):
def setup(self):
# Get the Libvirt version
vm_type = self.params.get("vm_type")
if vm_type == "libvirt":
libvirt_ver_cmd = self.params.get(
"libvirt_ver_cmd", "libvirtd -V|awk -F' ' '{print $3}'"
)
try:
libvirt_version = a_process.run(
libvirt_ver_cmd, shell=True
).stdout_text.strip()
except a_process.CmdError:
libvirt_version = "Unknown"
env_process.version_info["libvirt_version"] = str(libvirt_version)
LOG.debug("KVM userspace version(libvirt): %s" % libvirt_version)

def cleanup(self):
pass

0 comments on commit 7b2d3fc

Please sign in to comment.