Skip to content

Commit

Permalink
Merge pull request #3994 from bgartzi/env_process_refactoring-host_dm…
Browse files Browse the repository at this point in the history
…esg_verification

Refactor host dmesg verification into a Setuper
  • Loading branch information
YongxueHong authored Oct 9, 2024
2 parents e69c15e + 2894cc5 commit 4365d44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
23 changes: 2 additions & 21 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
CheckRunningAsRoot,
)
from virttest.test_setup.storage import StorageConfig
from virttest.test_setup.verify import VerifyHostDMesg
from virttest.test_setup.vms import UnrequestedVMHandler
from virttest.utils_version import VersionInterval

Expand Down Expand Up @@ -1030,12 +1031,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 +1771,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
25 changes: 25 additions & 0 deletions virttest/test_setup/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from virttest import utils_misc
from virttest.test_setup.core import Setuper


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 4365d44

Please sign in to comment.