test,refactor: fix test_project_resources cleanup (#8097)

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2023-10-16 19:54:59 +05:30 committed by GitHub
parent ba24a18f27
commit 065abe2a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -551,66 +551,59 @@ class TestTemplates(cloudstackTestCase):
cls.hypervisor = cls.testClient.getHypervisorInfo()
if cls.hypervisor.lower() in ['lxc']:
raise unittest.SkipTest("create template from volume is not supported on %s" % cls.hypervisor.lower())
cls._cleanup = []
cls.template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
cls.services["server"]["zoneid"] = cls.zone.id
# Create Domains, Account etc
cls.domain = Domain.create(
cls.api_client,
cls.services["domain"]
)
cls.api_client,
cls.services["domain"]
)
cls._cleanup.append(cls.domain)
cls.account = Account.create(
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.user = Account.create(
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.user)
# Create project as a domain admin
cls.project = Project.create(
cls.api_client,
cls.services["project"],
account=cls.account.name,
domainid=cls.account.domainid
)
cls.api_client,
cls.services["project"],
account=cls.account.name,
domainid=cls.account.domainid
)
cls._cleanup.append(cls.project)
cls.services["account"] = cls.account.name
# Create Service offering and disk offerings etc
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
cls.api_client,
cls.services["service_offering"]
)
cls._cleanup.append(cls.service_offering)
cls.userapiclient = cls.testClient.getUserApiClient(
UserName=cls.account.name,
DomainName=cls.domain.name
)
cls._cleanup = [
cls.project,
cls.service_offering,
cls.account,
cls.user,
cls.domain
]
UserName=cls.account.name,
DomainName=cls.domain.name
)
return
@classmethod
def tearDownClass(cls):
try:
#Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestTemplates, cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -619,12 +612,7 @@ class TestTemplates(cloudstackTestCase):
return
def tearDown(self):
try:
#Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestTemplates, self).tearDown()
@attr(tags=["advanced", "basic", "sg", "eip", "advancedns"], required_hardware="false")
def test_04_public_private_template_use_in_project(self):