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 requirement_checks import from env_process as
all steps are now refactored into Setupers in requirement_checks.

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 <[email protected]>
  • Loading branch information
bgartzi committed Dec 11, 2024
1 parent 09ee087 commit 6ea7c8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 2 additions & 4 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
)
from virttest.test_setup.os_posix import UlimitConfig
from virttest.test_setup.ppc import SwitchSMTOff
from virttest.test_setup import requirement_checks
from virttest.test_setup.requirement_checks import (
CheckInstalledCMDs,
CheckKernelVersion,
Expand All @@ -64,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 @@ -1022,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(requirement_checks.version_info)

libvirtd_inst = None

# If guest is configured to be backed by hugepages, setup hugepages in host
Expand Down
9 changes: 9 additions & 0 deletions virttest/test_setup/requirement_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,12 @@ def setup(self):

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 6ea7c8f

Please sign in to comment.