Skip to content

Commit c1923a2

Browse files
authored
test: cleanup test_guest_os.py for multiple execution (#10818)
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent f6d0590 commit c1923a2

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

test/integration/smoke/test_guest_os.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,14 @@ def setUpClass(cls):
4747

4848
cls.hypervisor = cls.get_hypervisor_type()
4949

50-
@classmethod
5150
def setUp(self):
5251
self.apiclient = self.testClient.getApiClient()
5352

5453
#build cleanup list
5554
self.cleanup = []
5655

57-
@classmethod
5856
def tearDown(self):
59-
try:
60-
cleanup_resources(self.apiclient, self.cleanup)
61-
except Exception as e:
62-
self.debug("Warning! Exception in tearDown: %s" % e)
57+
super(TestGuestOS, self).tearDown()
6358

6459
@classmethod
6560
def get_hypervisor_type(cls):
@@ -95,6 +90,7 @@ def test_CRUD_operations_guest_OS(self):
9590
osdisplayname="testCentOS",
9691
oscategoryid=os_category.id
9792
)
93+
self.cleanup.append(self.guestos1)
9894
list_guestos = GuestOS.list(self.apiclient, id=self.guestos1.id, listall=True)
9995
self.assertNotEqual(
10096
len(list_guestos),
@@ -112,6 +108,7 @@ def test_CRUD_operations_guest_OS(self):
112108
self.apiclient,
113109
id=self.guestos1.id
114110
)
111+
self.cleanup.remove(self.guestos1)
115112

116113
@attr(tags=['advanced', 'simulator', 'basic', 'sg'], required_hardware=False)
117114
def test_CRUD_operations_guest_OS_mapping(self):
@@ -127,6 +124,7 @@ def test_CRUD_operations_guest_OS_mapping(self):
127124
osdisplayname="testCentOS",
128125
oscategoryid=os_category.id
129126
)
127+
self.cleanup.append(self.guestos1)
130128

131129
if self.hypervisor.hypervisor.lower() not in ["xenserver", "vmware"]:
132130
raise unittest.SkipTest("OS name check with hypervisor is supported only on XenServer and VMware")
@@ -138,6 +136,7 @@ def test_CRUD_operations_guest_OS_mapping(self):
138136
hypervisorversion=self.hypervisor.hypervisorversion,
139137
osnameforhypervisor="testOSMappingName"
140138
)
139+
self.cleanup.append(self.guestosmapping1)
141140

142141
list_guestos_mapping = GuestOsMapping.list(self.apiclient, id=self.guestosmapping1.id, listall=True)
143142
self.assertNotEqual(
@@ -156,11 +155,13 @@ def test_CRUD_operations_guest_OS_mapping(self):
156155
self.apiclient,
157156
id=self.guestosmapping1.id
158157
)
158+
self.cleanup.remove(self.guestosmapping1)
159159

160160
GuestOS.remove(
161161
self.apiclient,
162162
id=self.guestos1.id
163163
)
164+
self.cleanup.remove(self.guestos1)
164165

165166
@attr(tags=['advanced', 'simulator', 'basic', 'sg'], required_hardware=False)
166167
def test_guest_OS_mapping_check_with_hypervisor(self):
@@ -176,6 +177,7 @@ def test_guest_OS_mapping_check_with_hypervisor(self):
176177
osdisplayname="testOSname1",
177178
oscategoryid=os_category.id
178179
)
180+
self.cleanup.append(self.guestos1)
179181

180182
if self.hypervisor.hypervisor.lower() not in ["xenserver", "vmware"]:
181183
raise unittest.SkipTest("OS name check with hypervisor is supported only on XenServer and VMware")
@@ -193,6 +195,7 @@ def test_guest_OS_mapping_check_with_hypervisor(self):
193195
osnameforhypervisor=testosname,
194196
osmappingcheckenabled=True
195197
)
198+
self.cleanup.append(self.guestosmapping1)
196199

197200
list_guestos_mapping = GuestOsMapping.list(self.apiclient, id=self.guestosmapping1.id, listall=True)
198201
self.assertNotEqual(
@@ -211,11 +214,13 @@ def test_guest_OS_mapping_check_with_hypervisor(self):
211214
self.apiclient,
212215
id=self.guestosmapping1.id
213216
)
217+
self.cleanup.remove(self.guestosmapping1)
214218

215219
GuestOS.remove(
216220
self.apiclient,
217221
id=self.guestos1.id
218222
)
223+
self.cleanup.remove(self.guestos1)
219224

220225
@attr(tags=['advanced', 'simulator', 'basic', 'sg'], required_hardware=False)
221226
def test_guest_OS_mapping_check_with_hypervisor_failure(self):
@@ -231,6 +236,7 @@ def test_guest_OS_mapping_check_with_hypervisor_failure(self):
231236
osdisplayname="testOSname2",
232237
oscategoryid=os_category.id
233238
)
239+
self.cleanup.append(self.guestos1)
234240

235241
if self.hypervisor.hypervisor.lower() not in ["xenserver", "vmware"]:
236242
raise unittest.SkipTest("OS name check with hypervisor is supported only on XenServer and VMware")
@@ -246,15 +252,18 @@ def test_guest_OS_mapping_check_with_hypervisor_failure(self):
246252
osnameforhypervisor=testosname,
247253
osmappingcheckenabled=True
248254
)
255+
self.cleanup.append(self.guestosmapping1)
249256
GuestOsMapping.remove(
250257
self.apiclient,
251258
id=self.guestosmapping1.id
252259
)
260+
self.cleanup.remove(self.guestosmapping1)
253261
self.fail("Since os mapping name is wrong, this API should fail")
254262
except CloudstackAPIException as e:
255263
self.debug("Addition guest OS mapping failed as expected %s " % e)
256264
GuestOS.remove(
257265
self.apiclient,
258266
id=self.guestos1.id
259267
)
268+
self.cleanup.remove(self.guestos1)
260269
return

tools/marvin/marvin/lib/base.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4576,6 +4576,7 @@ class Project:
45764576
def __init__(self, items):
45774577
self.__dict__.update(items)
45784578

4579+
45794580
@classmethod
45804581
def create(cls, apiclient, services, account=None, domainid=None, userid=None, accountid=None):
45814582
"""Create project"""
@@ -6720,7 +6721,7 @@ def list(cls, apiclient, id=None, name=None, **kwargs):
67206721
class GuestOS:
67216722
"""Manage Guest OS"""
67226723

6723-
def __init__(self, items, services):
6724+
def __init__(self, items):
67246725
self.__dict__.update(items)
67256726

67266727
@classmethod
@@ -6735,7 +6736,7 @@ def add(cls, apiclient, osdisplayname=None,
67356736
if details is not None:
67366737
cmd.details = details
67376738

6738-
return (apiclient.addGuestOs(cmd))
6739+
return GuestOS(apiclient.addGuestOs(cmd).__dict__)
67396740

67406741
@classmethod
67416742
def remove(cls, apiclient, id):
@@ -6772,10 +6773,13 @@ def list(cls, apiclient, id=None, oscategoryid=None, description=None, **kwargs)
67726773

67736774
return (apiclient.listOsTypes(cmd))
67746775

6776+
def delete(self, apiclient):
6777+
self.remove(apiclient, self.id)
6778+
67756779
class GuestOsMapping:
67766780
"""Manage Guest OS Mappings"""
67776781

6778-
def __init__(self, items, services):
6782+
def __init__(self, items):
67796783
self.__dict__.update(items)
67806784

67816785
@classmethod
@@ -6793,7 +6797,7 @@ def add(cls, apiclient, ostypeid=None,
67936797
if forced is not None:
67946798
cmd.forced = forced
67956799

6796-
return (apiclient.addGuestOsMapping(cmd))
6800+
return GuestOsMapping(apiclient.addGuestOsMapping(cmd).__dict__)
67976801

67986802
@classmethod
67996803
def remove(cls, apiclient, id):
@@ -6837,6 +6841,9 @@ def list(cls, apiclient, id=None, ostypeid=None, osdisplayname=None,
68376841

68386842
return (apiclient.listGuestOsMapping(cmd))
68396843

6844+
def delete(self, apiclient):
6845+
self.remove(apiclient, self.id)
6846+
68406847
class VMSchedule:
68416848

68426849
def __init__(self, items):

0 commit comments

Comments
 (0)