Skip to content

Commit

Permalink
env_process: Refactor virtio_win version verification step
Browse files Browse the repository at this point in the history
virtio_win 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 ad953a7 commit b9e10dc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
41 changes: 2 additions & 39 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
CheckKernelVersion,
CheckQEMUVersion,
CheckRunningAsRoot,
CheckVirtioWinVersion,
LogBootloaderVersion,
)
from virttest.test_setup.storage import StorageConfig
from virttest.test_setup.verify import VerifyHostDMesg
from virttest.test_setup.vms import ProcessVMOff, UnrequestedVMHandler
from virttest.utils_version import VersionInterval

utils_libvirtd = lazy_import("virttest.utils_libvirtd")
virsh = lazy_import("virttest.virsh")
Expand Down Expand Up @@ -1020,50 +1020,13 @@ def preprocess(test, params, env):
_setup_manager.register(CheckKernelVersion)
_setup_manager.register(CheckQEMUVersion)
_setup_manager.register(LogBootloaderVersion)
_setup_manager.register(CheckVirtioWinVersion)
_setup_manager.do_setup()

vm_type = params.get("vm_type")

base_dir = data_dir.get_data_dir()

# Checking required virtio-win version, if not satisfied, cancel test
if params.get("required_virtio_win") or params.get("required_virtio_win_prewhql"):
if params.get("cdrom_virtio"):
cdrom_virtio = params["cdrom_virtio"]
cdrom_virtio_path = os.path.basename(
utils_misc.get_path(data_dir.get_data_dir(), cdrom_virtio)
)
virtio_win_range = (
params.get("required_virtio_win_prewhql")
if re.search("prewhql", cdrom_virtio_path)
else params.get("required_virtio_win")
)
if virtio_win_range:
LOG.info("Checking required virtio-win version: %s" % virtio_win_range)
match = re.search(
"virtio-win-(?:prewhql-)?(\d+\.\d+(?:\.\d+)?-\d+)",
cdrom_virtio_path,
)
if match.group(1) is None:
test.error(
'Can not get virtio-win version from "cdrom_virtio": %s'
% cdrom_virtio
)
cdrom_virtio_version = re.sub("-", ".", match.group(1))
if cdrom_virtio_version not in VersionInterval(virtio_win_range):
test.cancel(
"Got virtio-win version:%s, which is not in %s"
% (cdrom_virtio_version, virtio_win_range)
)
else:
test.error(
"The limitation for virtio-win is not suitable for the cdrom_virtio"
)
else:
LOG.warning(
"required_virtio_win(prewhql) can not take effect without cdrom_virtio"
)

# Get the Libvirt version
if vm_type == "libvirt":
libvirt_ver_cmd = params.get(
Expand Down
50 changes: 49 additions & 1 deletion virttest/test_setup/requirement_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from avocado.utils import path
from avocado.utils import process as a_process

from virttest import env_process, utils_misc
from virttest import data_dir, env_process, utils_misc
from virttest.test_setup.core import Setuper
from virttest.utils_version import VersionInterval

Expand Down Expand Up @@ -150,3 +150,51 @@ def setup(self):

def cleanup(self):
pass


class CheckVirtioWinVersion(Setuper):
def setup(self):
# Checking required virtio-win version, if not satisfied, cancel test
if self.params.get("required_virtio_win") or self.params.get(
"required_virtio_win_prewhql"
):
if self.params.get("cdrom_virtio"):
cdrom_virtio = self.params["cdrom_virtio"]
cdrom_virtio_path = os.path.basename(
utils_misc.get_path(data_dir.get_data_dir(), cdrom_virtio)
)
virtio_win_range = (
self.params.get("required_virtio_win_prewhql")
if re.search("prewhql", cdrom_virtio_path)
else self.params.get("required_virtio_win")
)
if virtio_win_range:
LOG.info(
"Checking required virtio-win version: %s" % virtio_win_range
)
match = re.search(
"virtio-win-(?:prewhql-)?(\d+\.\d+(?:\.\d+)?-\d+)",
cdrom_virtio_path,
)
if match.group(1) is None:
self.test.error(
'Can not get virtio-win version from "cdrom_virtio": %s'
% cdrom_virtio
)
cdrom_virtio_version = re.sub("-", ".", match.group(1))
if cdrom_virtio_version not in VersionInterval(virtio_win_range):
self.test.cancel(
"Got virtio-win version:%s, which is not in %s"
% (cdrom_virtio_version, virtio_win_range)
)
else:
self.test.error(
"The limitation for virtio-win is not suitable for the cdrom_virtio"
)
else:
LOG.warning(
"required_virtio_win(prewhql) can not take effect without cdrom_virtio"
)

def cleanup(self):
pass

0 comments on commit b9e10dc

Please sign in to comment.