Skip to content

Commit 68281dc

Browse files
shwstpprdhslove
authored andcommitted
test: cleanup test_guest_os.py for multiple execution (apache#10818)
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 0d9bc77 commit 68281dc

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
@@ -4591,6 +4591,7 @@ class Project:
45914591
def __init__(self, items):
45924592
self.__dict__.update(items)
45934593

4594+
45944595
@classmethod
45954596
def create(cls, apiclient, services, account=None, domainid=None, userid=None, accountid=None):
45964597
"""Create project"""
@@ -6735,7 +6736,7 @@ def list(cls, apiclient, id=None, name=None, **kwargs):
67356736
class GuestOS:
67366737
"""Manage Guest OS"""
67376738

6738-
def __init__(self, items, services):
6739+
def __init__(self, items):
67396740
self.__dict__.update(items)
67406741

67416742
@classmethod
@@ -6750,7 +6751,7 @@ def add(cls, apiclient, osdisplayname=None,
67506751
if details is not None:
67516752
cmd.details = details
67526753

6753-
return (apiclient.addGuestOs(cmd))
6754+
return GuestOS(apiclient.addGuestOs(cmd).__dict__)
67546755

67556756
@classmethod
67566757
def remove(cls, apiclient, id):
@@ -6787,10 +6788,13 @@ def list(cls, apiclient, id=None, oscategoryid=None, description=None, **kwargs)
67876788

67886789
return (apiclient.listOsTypes(cmd))
67896790

6791+
def delete(self, apiclient):
6792+
self.remove(apiclient, self.id)
6793+
67906794
class GuestOsMapping:
67916795
"""Manage Guest OS Mappings"""
67926796

6793-
def __init__(self, items, services):
6797+
def __init__(self, items):
67946798
self.__dict__.update(items)
67956799

67966800
@classmethod
@@ -6808,7 +6812,7 @@ def add(cls, apiclient, ostypeid=None,
68086812
if forced is not None:
68096813
cmd.forced = forced
68106814

6811-
return (apiclient.addGuestOsMapping(cmd))
6815+
return GuestOsMapping(apiclient.addGuestOsMapping(cmd).__dict__)
68126816

68136817
@classmethod
68146818
def remove(cls, apiclient, id):
@@ -6852,6 +6856,9 @@ def list(cls, apiclient, id=None, ostypeid=None, osdisplayname=None,
68526856

68536857
return (apiclient.listGuestOsMapping(cmd))
68546858

6859+
def delete(self, apiclient):
6860+
self.remove(apiclient, self.id)
6861+
68556862
class VMSchedule:
68566863

68576864
def __init__(self, items):

0 commit comments

Comments
 (0)