Skip to content

Commit 36fedce

Browse files
DaanHooglandCopilotDaan Hoogland
authored
test: cleanup resources in test_deploy_vm_iso, use base class tearDown (#13136)
* test: cleanup resources in test_deploy_vm_iso and code * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: dahn <daan.hoogland@gmail.com> * style and syntaxt --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Daan Hoogland <dahn@apache.org>
1 parent a97c510 commit 36fedce

1 file changed

Lines changed: 58 additions & 40 deletions

File tree

test/integration/smoke/test_deploy_vm_iso.py

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
# Import Local Modules
2121
from nose.plugins.attrib import attr
2222
from marvin.cloudstackTestCase import cloudstackTestCase
23-
from marvin.lib.utils import cleanup_resources
2423
from marvin.lib.base import (Account,
2524
VirtualMachine,
2625
ServiceOffering,
@@ -38,49 +37,42 @@ class TestDeployVMFromISO(cloudstackTestCase):
3837
def setUpClass(cls):
3938

4039
cls.testClient = super(TestDeployVMFromISO, cls).getClsTestClient()
41-
cls.api_client = cls.testClient.getApiClient()
40+
cls.apiclient = cls.testClient.getApiClient()
4241

4342
cls.testdata = cls.testClient.getParsedTestDataConfig()
4443
# Get Zone, Domain and templates
45-
cls.domain = get_domain(cls.api_client)
46-
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
44+
cls.domain = get_domain(cls.apiclient)
45+
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
4746
cls.hypervisor = cls.testClient.getHypervisorInfo()
47+
cls._cleanup = []
4848

4949
cls.template = get_test_template(
50-
cls.api_client,
50+
cls.apiclient,
5151
cls.zone.id,
5252
cls.hypervisor
5353
)
5454

5555
# Create service, disk offerings etc
5656
cls.service_offering = ServiceOffering.create(
57-
cls.api_client,
57+
cls.apiclient,
5858
cls.testdata["service_offering"]
5959
)
60+
cls._cleanup.append(cls.service_offering)
6061

6162
cls.disk_offering = DiskOffering.create(
62-
cls.api_client,
63+
cls.apiclient,
6364
cls.testdata["disk_offering"]
6465
)
66+
cls._cleanup.append(cls.disk_offering)
6567

66-
cls._cleanup = [
67-
cls.service_offering,
68-
cls.disk_offering
69-
]
7068
return
7169

72-
@classmethod
73-
def tearDownClass(cls):
74-
try:
75-
cleanup_resources(cls.api_client, cls._cleanup)
76-
except Exception as e:
77-
raise Exception("Warning: Exception during cleanup : %s" % e)
78-
7970
def setUp(self):
8071

8172
self.apiclient = self.testClient.getApiClient()
8273
self.dbclient = self.testClient.getDbConnection()
8374
self.hypervisor = self.testClient.getHypervisorInfo()
75+
self.cleanup = []
8476
self.testdata["virtual_machine"]["zoneid"] = self.zone.id
8577
self.testdata["virtual_machine"]["template"] = self.template.id
8678
self.testdata["iso"]["zoneid"] = self.zone.id
@@ -89,38 +81,27 @@ def setUp(self):
8981
self.testdata["account"],
9082
domainid=self.domain.id
9183
)
92-
self.cleanup = [self.account]
84+
self.cleanup.append(self.account)
9385
return
9486

95-
def tearDown(self):
96-
try:
97-
self.debug("Cleaning up the resources")
98-
cleanup_resources(self.apiclient, self.cleanup)
99-
self.debug("Cleanup complete!")
100-
except Exception as e:
101-
self.debug("Warning! Exception in tearDown: %s" % e)
102-
10387
@attr(
10488
tags=[
10589
"advanced",
10690
"eip",
10791
"advancedns",
10892
"basic",
109-
"sg"],
110-
required_hardware="true")
93+
"sg"
94+
],
95+
required_hardware="true"
96+
)
11197
def test_deploy_vm_from_iso(self):
11298
"""Test Deploy Virtual Machine from ISO
11399
"""
114100

115101
# Validate the following:
116-
# 1. deploy VM using ISO
117-
# 2. listVM command should return the deployed VM. State of this VM
118-
# should be "Running".
119-
self.hypervisor = self.testClient.getHypervisorInfo()
120-
if self.hypervisor.lower() in ['lxc']:
121-
self.skipTest(
122-
"vm deploy from ISO feature is not supported on %s" %
123-
self.hypervisor.lower())
102+
# 1. Create an ISO
103+
# 2. Deploy a VM from the ISO
104+
# 3. VM should be in 'Running' state
124105

125106
self.iso = Iso.create(
126107
self.apiclient,
@@ -129,16 +110,28 @@ def test_deploy_vm_from_iso(self):
129110
domainid=self.account.domainid,
130111
zoneid=self.zone.id
131112
)
113+
self.cleanup.append(self.iso)
114+
115+
self.debug("ISO created with ID: %s" % self.iso.id)
116+
list_iso_response = Iso.list(
117+
self.apiclient,
118+
id=self.iso.id
119+
)
120+
while not isinstance(list_iso_response, list):
121+
list_iso_response = Iso.list(
122+
self.apiclient,
123+
id=self.iso.id
124+
)
125+
132126
try:
133127
# Download the ISO
134128
self.iso.download(self.apiclient)
135129
except Exception as e:
136130
raise Exception("Exception while downloading ISO %s: %s"
137131
% (self.iso.id, e))
138132

139-
self.debug("Registered ISO: %s" % self.iso.name)
140-
self.debug("Deploying instance in the account: %s" %
141-
self.account.name)
133+
self.debug(f"Registered ISO: {self.iso.name}")
134+
self.debug(f"Deploying instance in the account: {self.account.name}")
142135
self.virtual_machine = VirtualMachine.create(
143136
self.apiclient,
144137
self.testdata["virtual_machine"],
@@ -149,9 +142,34 @@ def test_deploy_vm_from_iso(self):
149142
diskofferingid=self.disk_offering.id,
150143
hypervisor=self.hypervisor
151144
)
145+
self.cleanup.append(self.virtual_machine)
146+
147+
self.debug("VM created with ID: %s" % self.virtual_machine.id)
148+
149+
list_vm_response = VirtualMachine.list(
150+
self.apiclient,
151+
id=self.virtual_machine.id
152+
)
153+
154+
self.assertEqual(
155+
isinstance(list_vm_response, list),
156+
True,
157+
"Check list response returns a valid list"
158+
)
159+
vm_response = list_vm_response[0]
160+
vm_state = self.virtual_machine.getState(
161+
self.apiclient,
162+
VirtualMachine.RUNNING
163+
)
152164

153165
response = self.virtual_machine.getState(
154166
self.apiclient,
155167
VirtualMachine.RUNNING)
156168
self.assertEqual(response[0], PASS, response[1])
169+
170+
self.assertEqual(
171+
vm_response.isoid,
172+
self.iso.id,
173+
"Check virtual machine is booted from the ISO"
174+
)
157175
return

0 commit comments

Comments
 (0)