test: cleanup test_guest_os.py for multiple execution (#10818)

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2025-05-07 12:20:36 +05:30 committed by GitHub
parent f6d0590424
commit c1923a2dcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 10 deletions

View File

@ -47,19 +47,14 @@ class TestGuestOS(cloudstackTestCase):
cls.hypervisor = cls.get_hypervisor_type()
@classmethod
def setUp(self):
self.apiclient = self.testClient.getApiClient()
#build cleanup list
self.cleanup = []
@classmethod
def tearDown(self):
try:
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.debug("Warning! Exception in tearDown: %s" % e)
super(TestGuestOS, self).tearDown()
@classmethod
def get_hypervisor_type(cls):
@ -95,6 +90,7 @@ class TestGuestOS(cloudstackTestCase):
osdisplayname="testCentOS",
oscategoryid=os_category.id
)
self.cleanup.append(self.guestos1)
list_guestos = GuestOS.list(self.apiclient, id=self.guestos1.id, listall=True)
self.assertNotEqual(
len(list_guestos),
@ -112,6 +108,7 @@ class TestGuestOS(cloudstackTestCase):
self.apiclient,
id=self.guestos1.id
)
self.cleanup.remove(self.guestos1)
@attr(tags=['advanced', 'simulator', 'basic', 'sg'], required_hardware=False)
def test_CRUD_operations_guest_OS_mapping(self):
@ -127,6 +124,7 @@ class TestGuestOS(cloudstackTestCase):
osdisplayname="testCentOS",
oscategoryid=os_category.id
)
self.cleanup.append(self.guestos1)
if self.hypervisor.hypervisor.lower() not in ["xenserver", "vmware"]:
raise unittest.SkipTest("OS name check with hypervisor is supported only on XenServer and VMware")
@ -138,6 +136,7 @@ class TestGuestOS(cloudstackTestCase):
hypervisorversion=self.hypervisor.hypervisorversion,
osnameforhypervisor="testOSMappingName"
)
self.cleanup.append(self.guestosmapping1)
list_guestos_mapping = GuestOsMapping.list(self.apiclient, id=self.guestosmapping1.id, listall=True)
self.assertNotEqual(
@ -156,11 +155,13 @@ class TestGuestOS(cloudstackTestCase):
self.apiclient,
id=self.guestosmapping1.id
)
self.cleanup.remove(self.guestosmapping1)
GuestOS.remove(
self.apiclient,
id=self.guestos1.id
)
self.cleanup.remove(self.guestos1)
@attr(tags=['advanced', 'simulator', 'basic', 'sg'], required_hardware=False)
def test_guest_OS_mapping_check_with_hypervisor(self):
@ -176,6 +177,7 @@ class TestGuestOS(cloudstackTestCase):
osdisplayname="testOSname1",
oscategoryid=os_category.id
)
self.cleanup.append(self.guestos1)
if self.hypervisor.hypervisor.lower() not in ["xenserver", "vmware"]:
raise unittest.SkipTest("OS name check with hypervisor is supported only on XenServer and VMware")
@ -193,6 +195,7 @@ class TestGuestOS(cloudstackTestCase):
osnameforhypervisor=testosname,
osmappingcheckenabled=True
)
self.cleanup.append(self.guestosmapping1)
list_guestos_mapping = GuestOsMapping.list(self.apiclient, id=self.guestosmapping1.id, listall=True)
self.assertNotEqual(
@ -211,11 +214,13 @@ class TestGuestOS(cloudstackTestCase):
self.apiclient,
id=self.guestosmapping1.id
)
self.cleanup.remove(self.guestosmapping1)
GuestOS.remove(
self.apiclient,
id=self.guestos1.id
)
self.cleanup.remove(self.guestos1)
@attr(tags=['advanced', 'simulator', 'basic', 'sg'], required_hardware=False)
def test_guest_OS_mapping_check_with_hypervisor_failure(self):
@ -231,6 +236,7 @@ class TestGuestOS(cloudstackTestCase):
osdisplayname="testOSname2",
oscategoryid=os_category.id
)
self.cleanup.append(self.guestos1)
if self.hypervisor.hypervisor.lower() not in ["xenserver", "vmware"]:
raise unittest.SkipTest("OS name check with hypervisor is supported only on XenServer and VMware")
@ -246,10 +252,12 @@ class TestGuestOS(cloudstackTestCase):
osnameforhypervisor=testosname,
osmappingcheckenabled=True
)
self.cleanup.append(self.guestosmapping1)
GuestOsMapping.remove(
self.apiclient,
id=self.guestosmapping1.id
)
self.cleanup.remove(self.guestosmapping1)
self.fail("Since os mapping name is wrong, this API should fail")
except CloudstackAPIException as e:
self.debug("Addition guest OS mapping failed as expected %s " % e)
@ -257,4 +265,5 @@ class TestGuestOS(cloudstackTestCase):
self.apiclient,
id=self.guestos1.id
)
self.cleanup.remove(self.guestos1)
return

View File

@ -4576,6 +4576,7 @@ class Project:
def __init__(self, items):
self.__dict__.update(items)
@classmethod
def create(cls, apiclient, services, account=None, domainid=None, userid=None, accountid=None):
"""Create project"""
@ -6720,7 +6721,7 @@ class GuestOSCategory:
class GuestOS:
"""Manage Guest OS"""
def __init__(self, items, services):
def __init__(self, items):
self.__dict__.update(items)
@classmethod
@ -6735,7 +6736,7 @@ class GuestOS:
if details is not None:
cmd.details = details
return (apiclient.addGuestOs(cmd))
return GuestOS(apiclient.addGuestOs(cmd).__dict__)
@classmethod
def remove(cls, apiclient, id):
@ -6772,10 +6773,13 @@ class GuestOS:
return (apiclient.listOsTypes(cmd))
def delete(self, apiclient):
self.remove(apiclient, self.id)
class GuestOsMapping:
"""Manage Guest OS Mappings"""
def __init__(self, items, services):
def __init__(self, items):
self.__dict__.update(items)
@classmethod
@ -6793,7 +6797,7 @@ class GuestOsMapping:
if forced is not None:
cmd.forced = forced
return (apiclient.addGuestOsMapping(cmd))
return GuestOsMapping(apiclient.addGuestOsMapping(cmd).__dict__)
@classmethod
def remove(cls, apiclient, id):
@ -6837,6 +6841,9 @@ class GuestOsMapping:
return (apiclient.listGuestOsMapping(cmd))
def delete(self, apiclient):
self.remove(apiclient, self.id)
class VMSchedule:
def __init__(self, items):