Skip to content

Commit

Permalink
env_process: Refactor host dmesg verification
Browse files Browse the repository at this point in the history
Host dmesg can be checked if the test configuration requires to do so.
It will be in fact be checked both before and after running the test.

However, that was done directly in the preprocess and postprocess
functions in virttest.env_process. Write a Setuper subclass that
implements those in setup/cleanup methods and register the setuper in
the env_process setup_manager.

Signed-off-by: Beñat Gartzia Arruabarrena <[email protected]>
  • Loading branch information
bgartzi committed Sep 3, 2024
1 parent f9f2db1 commit fa3145d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
24 changes: 2 additions & 22 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# lazy imports for dependencies that are not needed in all modes of use
from virttest._wrappers import lazy_import
from virttest.test_setup.core import SetupManager
from virttest.test_setup.host_config import UlimitConfig, VerifyHostDMesg
from virttest.test_setup.libvirt_setup import LibvirtdDebugLogConfig
from virttest.test_setup.migration import MigrationEnvSetup
from virttest.test_setup.networking import (
Expand All @@ -53,7 +54,6 @@
IPSniffer,
NetworkProxies,
)
from virttest.test_setup.host_config import UlimitConfig
from virttest.test_setup.ppc import SwitchSMTOff
from virttest.test_setup.requirement_checks import (
CheckInstalledCMDs,
Expand Down Expand Up @@ -1030,12 +1030,8 @@ def preprocess(test, params, env):
)
a_process.system(reset_cmd, shell=True)

# Check host for any errors to start with and just report and
# clear it off, so that we do not get the false test failures.
if params.get("verify_host_dmesg", "yes") == "yes":
utils_misc.verify_dmesg(ignore_result=True)

_setup_manager.initialize(test, params, env)
_setup_manager.register(VerifyHostDMesg)
_setup_manager.register(SwitchSMTOff)
_setup_manager.register(CheckRunningAsRoot)
_setup_manager.register(CheckInstalledCMDs)
Expand Down Expand Up @@ -1774,22 +1770,6 @@ def postprocess(test, params, env):
err += "\nPostprocess command: %s" % str(details).replace("\n", "\n ")
LOG.error(details)

if params.get("verify_host_dmesg", "yes") == "yes":
dmesg_log_file = params.get("host_dmesg_logfile", "host_dmesg.log")
level = params.get("host_dmesg_level", 3)
expected_host_dmesg = params.get("expected_host_dmesg", "")
ignore_result = params.get("host_dmesg_ignore", "no") == "yes"
dmesg_log_file = utils_misc.get_path(test.debugdir, dmesg_log_file)
try:
utils_misc.verify_dmesg(
dmesg_log_file=dmesg_log_file,
ignore_result=ignore_result,
level_check=level,
expected_dmesg=expected_host_dmesg,
)
except exceptions.TestFail as details:
err += "\nHost dmesg verification failed: %s" % details

err += "\n".join(_setup_manager.do_cleanup())

# Run this hook after any vms are actually off to ensure data is
Expand Down
24 changes: 24 additions & 0 deletions virttest/test_setup/host_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import resource

from virttest import utils_misc
from virttest.test_setup.core import Setuper

LOG = logging.getLogger("avocado." + __name__)
Expand Down Expand Up @@ -58,3 +59,26 @@ def setup(self):

def cleanup(self):
self._restore()


class VerifyHostDMesg(Setuper):
def setup(self):
# Check host for any errors to start with and just report and
# clear it off, so that we do not get the false test failures.
if self.params.get("verify_host_dmesg", "yes") == "yes":
utils_misc.verify_dmesg(ignore_result=True)

def cleanup(self):
if self.params.get("verify_host_dmesg", "yes") == "yes":
dmesg_log_file = self.params.get("host_dmesg_logfile", "host_dmesg.log")
level = self.params.get("host_dmesg_level", 3)
expected_host_dmesg = self.params.get("expected_host_dmesg", "")
ignore_result = self.params.get("host_dmesg_ignore", "no") == "yes"
dmesg_log_file = utils_misc.get_path(self.test.debugdir, dmesg_log_file)
# exception will be propagated so setup_manager handles it instead
utils_misc.verify_dmesg(
dmesg_log_file=dmesg_log_file,
ignore_result=ignore_result,
level_check=level,
expected_dmesg=expected_host_dmesg,
)

0 comments on commit fa3145d

Please sign in to comment.