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

View File

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