-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
env_process: Destroy unrequested VMs via a Setuper
Refactor the piece of code that destroyed the unrequested VMs (if asked so) into a setuper. Import that class into env_process and register it into the setup_manager. Signed-off-by: Beñat Gartzia Arruabarrena <[email protected]>
- 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 DestroyUnrequestedVMs(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 |