forked from avocado-framework/avocado-vt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request avocado-framework#3979 from bgartzi/env_process_re…
…factoring-kill_unrequested_vms env_process: Destroy unrequested VMs via a Setuper
- Loading branch information
Showing
2 changed files
with
36 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
|
||
from virttest import virt_vm | ||
from virttest.test_setup.core import Setuper | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class UnrequestedVMHandler(Setuper): | ||
def setup(self): | ||
# Destroy and remove VMs that are no longer needed in the environment or | ||
# leave them untouched if they have to be disregarded only for this test | ||
requested_vms = self.params.objects("vms") | ||
keep_unrequested_vms = self.params.get_boolean("keep_unrequested_vms", False) | ||
kill_unrequested_vms_gracefully = self.params.get_boolean( | ||
"kill_unrequested_vms_gracefully", True | ||
) | ||
for key in list(self.env.keys()): | ||
vm = self.env[key] | ||
if not isinstance(vm, virt_vm.BaseVM): | ||
continue | ||
if vm.name not in requested_vms: | ||
if keep_unrequested_vms: | ||
LOG.debug( | ||
"The vm %s is registered in the env and disregarded " | ||
"in the current test", | ||
vm.name, | ||
) | ||
else: | ||
vm.destroy(gracefully=kill_unrequested_vms_gracefully) | ||
del self.env[key] | ||
|
||
def cleanup(self): | ||
pass |