Skip to content

Commit

Permalink
Merge pull request #4031 from bgartzi/env_process_refactoring-vm_off_…
Browse files Browse the repository at this point in the history
…hook

env_process: Refactor {pre,post}process_vm_off_hook execution
  • Loading branch information
YongxueHong authored Nov 28, 2024
2 parents 15fbf53 + 86786d9 commit 1760004
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
21 changes: 5 additions & 16 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
)
from virttest.test_setup.storage import StorageConfig
from virttest.test_setup.verify import VerifyHostDMesg
from virttest.test_setup.vms import UnrequestedVMHandler
from virttest.test_setup.vms import ProcessVMOff, UnrequestedVMHandler
from virttest.utils_version import VersionInterval

utils_libvirtd = lazy_import("virttest.utils_libvirtd")
Expand Down Expand Up @@ -1005,17 +1005,17 @@ def preprocess(test, params, env):
"""
error_context.context("preprocessing")

# Run this hook before any network setup stage and vm creation.
if callable(preprocess_vm_off_hook):
preprocess_vm_off_hook(test, params, env) # pylint: disable=E1102

# Add migrate_vms to vms
migrate_vms = params.objects("migrate_vms")
if migrate_vms:
vms = list(set(params.objects("vms") + migrate_vms))
params["vms"] = " ".join(vms)

_setup_manager.initialize(test, params, env)
# Keep ProcessVMOff registered first. That way VM Off hooks will be first
# and last running during pre/postprocess. That way vms will be actually
# off to ensure data is written to disk.
_setup_manager.register(ProcessVMOff)
_setup_manager.register(ResetQemuGCov)
_setup_manager.register(VerifyHostDMesg)
_setup_manager.register(SwitchSMTOff)
Expand Down Expand Up @@ -1758,17 +1758,6 @@ def postprocess(test, params, env):

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

# Run this hook after any vms are actually off to ensure data is
# written to disk.
if callable(postprocess_vm_off_hook):
try:
postprocess_vm_off_hook(test, params, env) # pylint: disable=E1102
except Exception as details:
err += "\nPostprocessing dead vm hook: %s" % str(details).replace(
"\\n", "\n "
)
LOG.error(details)

if err:
raise RuntimeError("Failures occurred while postprocess:\n%s" % err)
elif _post_hugepages_surp > _pre_hugepages_surp:
Expand Down
23 changes: 22 additions & 1 deletion virttest/test_setup/vms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from virttest import virt_vm
from virttest import env_process, virt_vm
from virttest.test_setup.core import Setuper

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -32,3 +32,24 @@ def setup(self):

def cleanup(self):
pass


class ProcessVMOff(Setuper):
def setup(self):
# Run this hook before any network setup stage and vm creation.
if callable(env_process.preprocess_vm_off_hook):
env_process.preprocess_vm_off_hook(
self.test, self.params, self.env
) # pylint: disable=E1102

def cleanup(self):
if callable(env_process.postprocess_vm_off_hook):
try:
env_process.postprocess_vm_off_hook(
self.test, self.params, self.env
) # pylint: disable=E1102
except Exception as details:
raise Exception(
"\nPostprocessing dead vm hook: %s"
% str(details).replace("\\n", "\n ")
) from None

0 comments on commit 1760004

Please sign in to comment.