Thanks to visit codestin.com
Credit goes to github.com

Skip to content

test: cleanup test_guest_os.py for multiple execution #10818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions test/integration/smoke/test_guest_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,14 @@ def setUpClass(cls):

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):
Expand Down Expand Up @@ -95,6 +90,7 @@ def test_CRUD_operations_guest_OS(self):
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),
Expand All @@ -112,6 +108,7 @@ def test_CRUD_operations_guest_OS(self):
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):
Expand All @@ -127,6 +124,7 @@ def test_CRUD_operations_guest_OS_mapping(self):
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")
Expand All @@ -138,6 +136,7 @@ def test_CRUD_operations_guest_OS_mapping(self):
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(
Expand All @@ -156,11 +155,13 @@ def test_CRUD_operations_guest_OS_mapping(self):
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):
Expand All @@ -176,6 +177,7 @@ def test_guest_OS_mapping_check_with_hypervisor(self):
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")
Expand All @@ -193,6 +195,7 @@ def test_guest_OS_mapping_check_with_hypervisor(self):
osnameforhypervisor=testosname,
osmappingcheckenabled=True
)
self.cleanup.append(self.guestosmapping1)

list_guestos_mapping = GuestOsMapping.list(self.apiclient, id=self.guestosmapping1.id, listall=True)
self.assertNotEqual(
Expand All @@ -211,11 +214,13 @@ def test_guest_OS_mapping_check_with_hypervisor(self):
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):
Expand All @@ -231,6 +236,7 @@ def test_guest_OS_mapping_check_with_hypervisor_failure(self):
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")
Expand All @@ -246,15 +252,18 @@ def test_guest_OS_mapping_check_with_hypervisor_failure(self):
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)
GuestOS.remove(
self.apiclient,
id=self.guestos1.id
)
self.cleanup.remove(self.guestos1)
return
15 changes: 11 additions & 4 deletions tools/marvin/marvin/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -6720,7 +6721,7 @@ def list(cls, apiclient, id=None, name=None, **kwargs):
class GuestOS:
"""Manage Guest OS"""

def __init__(self, items, services):
def __init__(self, items):
self.__dict__.update(items)

@classmethod
Expand All @@ -6735,7 +6736,7 @@ def add(cls, apiclient, osdisplayname=None,
if details is not None:
cmd.details = details

return (apiclient.addGuestOs(cmd))
return GuestOS(apiclient.addGuestOs(cmd).__dict__)

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

return (apiclient.listOsTypes(cmd))

def delete(self, apiclient):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, where is this used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would imagine the cleanup_resources method of cloudstackTestcase needs these.

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
Expand All @@ -6793,7 +6797,7 @@ def add(cls, apiclient, ostypeid=None,
if forced is not None:
cmd.forced = forced

return (apiclient.addGuestOsMapping(cmd))
return GuestOsMapping(apiclient.addGuestOsMapping(cmd).__dict__)

@classmethod
def remove(cls, apiclient, id):
Expand Down Expand Up @@ -6837,6 +6841,9 @@ def list(cls, apiclient, id=None, ostypeid=None, osdisplayname=None,

return (apiclient.listGuestOsMapping(cmd))

def delete(self, apiclient):
self.remove(apiclient, self.id)

class VMSchedule:

def __init__(self, items):
Expand Down
Loading