test: cleanup resources in test_deploy_vm_iso and code

This commit is contained in:
dahn 2026-05-08 14:38:36 +02:00 committed by Daan Hoogland
parent 72b99a3f8c
commit acf78ab6cf
1 changed files with 54 additions and 38 deletions

View File

@ -20,7 +20,6 @@
# Import Local Modules
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.utils import cleanup_resources
from marvin.lib.base import (Account,
VirtualMachine,
ServiceOffering,
@ -38,28 +37,28 @@ class TestDeployVMFromISO(cloudstackTestCase):
def setUpClass(cls):
cls.testClient = super(TestDeployVMFromISO, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.apiclient = cls.testClient.getApiClient()
cls.testdata = cls.testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
cls.hypervisor = cls.testClient.getHypervisorInfo()
cls.template = get_test_template(
cls.api_client,
cls.apiclient,
cls.zone.id,
cls.hypervisor
)
# Create service, disk offerings etc
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.apiclient,
cls.testdata["service_offering"]
)
cls.disk_offering = DiskOffering.create(
cls.api_client,
cls.apiclient,
cls.testdata["disk_offering"]
)
@ -69,13 +68,6 @@ class TestDeployVMFromISO(cloudstackTestCase):
]
return
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -92,35 +84,24 @@ class TestDeployVMFromISO(cloudstackTestCase):
self.cleanup = [self.account]
return
def tearDown(self):
try:
self.debug("Cleaning up the resources")
cleanup_resources(self.apiclient, self.cleanup)
self.debug("Cleanup complete!")
except Exception as e:
self.debug("Warning! Exception in tearDown: %s" % e)
@attr(
tags=[
"advanced",
"eip",
"advancedns",
"basic",
"sg"],
required_hardware="true")
"sg"
],
required_hardware="true"
)
def test_deploy_vm_from_iso(self):
"""Test Deploy Virtual Machine from ISO
"""
# Validate the following:
# 1. deploy VM using ISO
# 2. listVM command should return the deployed VM. State of this VM
# should be "Running".
self.hypervisor = self.testClient.getHypervisorInfo()
if self.hypervisor.lower() in ['lxc']:
self.skipTest(
"vm deploy from ISO feature is not supported on %s" %
self.hypervisor.lower())
# 1. Create an ISO
# 2. Deploy a VM from the ISO
# 3. VM should be in 'Running' state
self.iso = Iso.create(
self.apiclient,
@ -129,6 +110,20 @@ class TestDeployVMFromISO(cloudstackTestCase):
domainid=self.account.domainid,
zoneid=self.zone.id
)
self.cleanup.append(self.iso)
self.debug("ISO created with ID: %s" % self.iso.id)
list_iso_response = Iso.list(
self.apiclient,
id=self.iso.id
)
self.assertEqual(
isinstance(list_iso_response, list),
True,
"Check list response returns a valid list"
)
try:
# Download the ISO
self.iso.download(self.apiclient)
@ -136,9 +131,8 @@ class TestDeployVMFromISO(cloudstackTestCase):
raise Exception("Exception while downloading ISO %s: %s"
% (self.iso.id, e))
self.debug("Registered ISO: %s" % self.iso.name)
self.debug("Deploying instance in the account: %s" %
self.account.name)
self.debug(f"Registered ISO: {self.iso.name}")
self.debug(f"Deploying instance in the account: {self.account.name}")
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
@ -149,9 +143,31 @@ class TestDeployVMFromISO(cloudstackTestCase):
diskofferingid=self.disk_offering.id,
hypervisor=self.hypervisor
)
self.cleanup.append(self.virtual_machine)
response = self.virtual_machine.getState(
self.debug("VM created with ID: %s" % self.virtual_machine.id)
list_vm_response = VirtualMachine.list(
self.apiclient,
VirtualMachine.RUNNING)
self.assertEqual(response[0], PASS, response[1])
id=self.virtual_machine.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.state,
"Running",
"Check virtual machine is in running state"
)
self.assertEqual(
vm_response.isoid,
self.iso.id,
"Check virtual machine is booted from the ISO"
)
return