default teardown methods with reversed() handling (#4289)

Co-authored-by: Daan Hoogland <dahn@onecht.net>
This commit is contained in:
dahn 2020-11-13 08:56:28 +01:00 committed by GitHub
parent fb78fb24c7
commit a348afe91b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 153 additions and 277 deletions

View File

@ -1454,11 +1454,7 @@ class TestMigrateVolume(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestMigrateVolume,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -1470,8 +1466,7 @@ class TestMigrateVolume(cloudstackTestCase):
return
def tearDown(self):
cleanup_resources(self.apiclient, self.cleanup)
return
super(TestMigrateVolume,self).tearDown()
@attr(tags=["advanced", "sg", "advancedsg"], required_hardware='true')
def test_01_migrateVolume(self):

View File

@ -153,12 +153,7 @@ class TestAccounts(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestAccounts,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -167,12 +162,7 @@ class TestAccounts(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestAccounts,self).tearDown()
@attr(
tags=[
@ -352,12 +342,7 @@ class TestRemoveUserFromAccount(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestRemoveUserFromAccount,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -366,12 +351,7 @@ class TestRemoveUserFromAccount(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created instance, users etc
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestRemoveUserFromAccount,self).tearDown()
@attr(
tags=[
@ -513,12 +493,7 @@ class TestNonRootAdminsPrivileges(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestNonRootAdminsPrivileges,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -527,12 +502,7 @@ class TestNonRootAdminsPrivileges(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created accounts
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestNonRootAdminsPrivileges,self).tearDown()
@attr(
tags=[
@ -642,12 +612,7 @@ class TestServiceOfferingSiblings(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestServiceOfferingSiblings,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -656,12 +621,7 @@ class TestServiceOfferingSiblings(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created domains, accounts
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestServiceOfferingSiblings,self).tearDown()
@attr(
tags=[
@ -766,12 +726,7 @@ class TestServiceOfferingHierarchy(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestServiceOfferingHierarchy,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -780,12 +735,7 @@ class TestServiceOfferingHierarchy(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestServiceOfferingHierarchy,self).tearDown()
@attr(
tags=[
@ -908,12 +858,7 @@ class TestTemplateHierarchy(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestTemplateHierarchy,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -922,12 +867,7 @@ class TestTemplateHierarchy(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestTemplateHierarchy,self).tearDown()
@attr(tags=["advanced", "basic", "eip", "advancedns", "sg"], required_hardware="true")
def test_01_template_hierarchy(self):
@ -1064,12 +1004,7 @@ class TestAddVmToSubDomain(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Clean up, terminate the created resources
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestAddVmToSubDomain,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -1078,12 +1013,7 @@ class TestAddVmToSubDomain(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created resources
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestAddVmToSubDomain,self).tearDown()
@attr(
tags=[
@ -1160,12 +1090,7 @@ class TestUserDetails(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestUserDetails,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -1174,12 +1099,7 @@ class TestUserDetails(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestUserDetails,self).tearDown()
@attr(tags=[
"role",
@ -1459,12 +1379,7 @@ class TestUserLogin(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestUserLogin,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -1473,12 +1388,7 @@ class TestUserLogin(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestUserLogin,self).tearDown()
@attr(tags=["login", "accounts", "simulator", "advanced",
"advancedns", "basic", "eip", "sg"])
@ -1716,12 +1626,7 @@ class TestUserAPIKeys(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestUserAPIKeys,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -1730,12 +1635,7 @@ class TestUserAPIKeys(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestUserAPIKeys,self).tearDown()
@attr(tags=[
"role",
@ -1868,13 +1768,7 @@ class TestDomainForceRemove(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Clean up, terminate the created resources
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestDomainForceRemove,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -1883,12 +1777,7 @@ class TestDomainForceRemove(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created resources
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestDomainForceRemove,self).tearDown()
@attr(
tags=[
@ -2247,13 +2136,7 @@ class TestMoveUser(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
# Clean up, terminate the created resources
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestMoveUser,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
@ -2284,12 +2167,7 @@ class TestMoveUser(cloudstackTestCase):
return
def tearDown(self):
try:
# Clean up, terminate the created resources
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestMoveUser,self).tearDownClass()
@attr(tags=["domains", "advanced", "advancedns", "simulator","dvs"], required_hardware="false")
def test_move_user_to_accountID(self):

View File

@ -33,9 +33,6 @@ from marvin.lib.base import (Account,
Host,
GuestOs)
# utils - utility classes for common cleanup, external library wrappers etc
from marvin.lib.utils import cleanup_resources, get_hypervisor_type, validateList
# common - commonly used methods for all tests are listed here
from marvin.lib.common import get_zone, get_domain, get_pod
@ -96,7 +93,7 @@ class TestDeployVirtioSCSIVM(cloudstackTestCase):
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.pod = get_pod(cls.apiclient, cls.zone.id)
cls.services['mode'] = cls.zone.networktype
cls.cleanup = []
cls._cleanup = []
if cls.hypervisor.lower() not in ['kvm']:
cls.hypervisorNotSupported = True
return
@ -108,6 +105,7 @@ class TestDeployVirtioSCSIVM(cloudstackTestCase):
hypervisor=cls.hypervisor.lower(),
domainid=cls.domain.id)
cls.template.download(cls.apiclient)
cls._cleanup.append(cls.template)
if cls.template == FAILED:
assert False, "get_template() failed to return template"
@ -120,16 +118,19 @@ class TestDeployVirtioSCSIVM(cloudstackTestCase):
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["small"]
)
cls._cleanup.append(cls.service_offering)
cls.sparse_disk_offering = DiskOffering.create(
cls.apiclient,
cls.services["sparse_disk_offering"]
)
cls._cleanup.append(cls.sparse_disk_offering)
cls.virtual_machine = VirtualMachine.create(
cls.apiclient,
@ -158,29 +159,20 @@ class TestDeployVirtioSCSIVM(cloudstackTestCase):
# Start VM after password reset
cls.virtual_machine.start(cls.apiclient)
cls._cleanup.append(cls.virtual_machine)
cls.cleanup = [
cls.template,
cls.service_offering,
cls.sparse_disk_offering,
cls.account
]
@classmethod
def tearDownClass(cls):
try:
cls.apiclient = super(
TestDeployVirtioSCSIVM,
cls
).getClsTestClient().getApiClient()
# Cleanup resources used
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
super(TestDeployVirtioSCSIVM, cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
def tearDown(self):
super(TestDeployVirtioSCSIVM, self).tearDown()
def verifyVirshState(self, diskcount):
host = self.vmhost.ipaddress

View File

@ -19,7 +19,6 @@ from marvin.codes import FAILED
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.base import Account, VirtualMachine, ServiceOffering, Host, Cluster
from marvin.lib.common import get_zone, get_domain, get_test_template
from marvin.lib.utils import cleanup_resources
from nose.plugins.attrib import attr
class TestDeployVmWithVariedPlanners(cloudstackTestCase):
@ -57,9 +56,8 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase):
)
cls.hosts = Host.list(cls.apiclient, type='Routing')
cls.clusters = Cluster.list(cls.apiclient)
cls.cleanup = [
cls.account
]
cls._cleanup = []
cls._cleanup.append(cls.account)
@attr(tags=["advanced", "basic", "sg"], required_hardware="false")
def test_deployvm_firstfit(self):
@ -230,7 +228,4 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
super(TestDeployVmWithVariedPlanners,cls).tearDownClass()

View File

@ -30,7 +30,6 @@ from marvin.lib.common import (get_domain,
get_test_template,
list_ssvms,
list_routers)
from marvin.lib.utils import (cleanup_resources)
from nose.plugins.attrib import attr
@ -61,16 +60,20 @@ class TestRemoteDiagnostics(cloudstackTestCase):
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls._cleanup = []
# Create an account, network, VM and IP addresses
cls.account = Account.create(
cls.apiclient,
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["tiny"]
)
cls._cleanup.append(cls.service_offering)
cls.vm_1 = VirtualMachine.create(
cls.apiclient,
cls.services["virtual_machine"],
@ -79,27 +82,19 @@ class TestRemoteDiagnostics(cloudstackTestCase):
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id
)
cls.cleanup = [
cls.account,
cls.service_offering
]
cls._cleanup.append(cls.vm_1)
@classmethod
def tearDownClass(cls):
try:
cls.apiclient = super(
TestRemoteDiagnostics,
cls
).getClsTestClient().getApiClient()
# Clean up, terminate the created templates
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
super(TestRemoteDiagnostics,cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.cleanup = []
def tearDown(self):
super(TestRemoteDiagnostics,self).tearDown()
@attr(tags=["advanced", "advancedns", "ssh", "smoke"], required_hardware="true")
def test_01_ping_in_vr_success(self):

View File

@ -69,16 +69,20 @@ class TestRouterServices(cloudstackTestCase):
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls._cleanup = []
# Create an account, network, VM and IP addresses
cls.account = Account.create(
cls.apiclient,
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create(
cls.apiclient,
cls.services["service_offerings"]["tiny"]
)
cls._cleanup.append(cls.service_offering)
cls.vm_1 = VirtualMachine.create(
cls.apiclient,
cls.services["virtual_machine"],
@ -87,30 +91,20 @@ class TestRouterServices(cloudstackTestCase):
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id
)
cls.cleanup = [
cls.account,
cls.service_offering
]
cls._cleanup.append(cls.vm_1)
return
@classmethod
def tearDownClass(cls):
try:
cls.apiclient = super(
TestRouterServices,
cls
).getClsTestClient().getApiClient()
# Clean up, terminate the created templates
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
super(TestRouterServices, cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
return
self.cleanup = []
def tearDown(self):
super(TestRouterServices, self).tearDown()
@attr(tags=["advanced", "basic", "sg", "smoke"], required_hardware="true")
def test_01_router_internal_basic(self):

View File

@ -20,13 +20,9 @@
from marvin.codes import PASS, FAILED
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.utils import (validateList,
cleanup_resources,
get_process_status,
wait_until)
from marvin.lib.base import (Domain,
Account,
Configurations,
from marvin.lib.base import (Account,
VPC,
VpcOffering,
ServiceOffering,
@ -34,14 +30,8 @@ from marvin.lib.base import (Domain,
Network,
PublicIPAddress,
NATRule,
NetworkACL,
NetworkACLList,
LoadBalancerRule,
ApplicationLoadBalancer,
VirtualMachine,
Template,
FireWallRule,
StaticNATRule,
Vpn,
VpnCustomerGateway,
VpnUser
@ -52,8 +42,7 @@ from marvin.sshClient import SshClient
from marvin.lib.common import (get_zone,
get_domain,
get_test_template,
list_network_offerings)
get_test_template)
from nose.plugins.attrib import attr
@ -236,12 +225,16 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase):
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.domain = get_domain(cls.apiclient)
cls._cleanup = []
cls.compute_offering = ServiceOffering.create(
cls.apiclient,
cls.services["compute_offering"]
)
cls._cleanup.append(cls.compute_offering)
cls.account = Account.create(
cls.apiclient, services=cls.services["account"])
cls._cleanup.append(cls.account)
cls.hypervisor = testClient.getHypervisorInfo()
@ -253,7 +246,6 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase):
%s" % (cls.account.name,
cls.account.id))
cls.cleanup = [cls.account, cls.compute_offering]
return
@attr(tags=["advanced"], required_hardware="true")
@ -285,6 +277,7 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase):
account=self.account.name,
domainid=self.domain.id
)
self.cleanup.append(vpc)
except Exception as e:
self.fail(e)
finally:
@ -306,6 +299,7 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assertIsNotNone(ntwk, "Network failed to create")
self.cleanup.append(ntwk)
self.logger.debug(
"Network %s created in VPC %s" % (ntwk.id, vpc.id))
@ -321,6 +315,7 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase):
hypervisor=self.hypervisor
)
self.assert_(vm is not None, "VM failed to deploy")
self.cleanup.append(vm)
self.assert_(vm.state == 'Running', "VM is not running")
self.debug("VM %s deployed in VPC %s" % (vm.id, vpc.id))
except Exception as e:
@ -387,12 +382,15 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
super(TestVpcRemoteAccessVpn, cls).tearDownClass()
try:
cls.logger.debug("Cleaning up resources")
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception, e:
raise Exception("Cleanup failed with %s" % e)
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.cleanup = []
def tearDown(self):
super(TestVpcRemoteAccessVpn, self).tearDown()
class TestVpcSite2SiteVpn(cloudstackTestCase):
@ -411,13 +409,17 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.domain = get_domain(cls.apiclient)
cls._cleanup = []
cls.compute_offering = ServiceOffering.create(
cls.apiclient,
cls.services["compute_offering"]
)
cls._cleanup.append(cls.compute_offering)
cls.account = Account.create(
cls.apiclient, services=cls.services["account"])
cls._cleanup.append(cls.account)
cls.hypervisor = testClient.getHypervisorInfo()
@ -428,10 +430,13 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
cls.logger.debug("Successfully created account: %s, id: \
%s" % (cls.account.name,
cls.account.id))
cls.cleanup = [cls.account, cls.compute_offering]
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.cleanup = []
def _get_ssh_client(self, virtual_machine, services, retries):
""" Setup ssh client connection and return connection
vm requires attributes public_ip, public_port, username, password """
@ -547,7 +552,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assert_(vpc1 is not None, "VPC1 creation failed")
self.cleanup.append(vpc1)
self.logger.debug("VPC1 %s created" % vpc1.id)
vpc2 = None
@ -566,7 +571,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assert_(vpc2 is not None, "VPC2 creation failed")
self.cleanup.append(vpc2)
self.logger.debug("VPC2 %s created" % vpc2.id)
default_acl = NetworkACLList.list(
@ -589,7 +594,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assertIsNotNone(ntwk1, "Network failed to create")
self.cleanup.append(ntwk1)
self.logger.debug("Network %s created in VPC %s" % (ntwk1.id, vpc1.id))
ntwk2 = None
@ -609,7 +614,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assertIsNotNone(ntwk2, "Network failed to create")
self.cleanup.append(ntwk2)
self.logger.debug("Network %s created in VPC %s" % (ntwk2.id, vpc2.id))
vm1 = None
@ -629,7 +634,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
finally:
self.assert_(vm1 is not None, "VM failed to deploy")
self.assert_(vm1.state == 'Running', "VM is not running")
self.cleanup.append(vm1)
self.logger.debug("VM %s deployed in VPC %s" % (vm1.id, vpc1.id))
vm2 = None
@ -649,7 +654,7 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
finally:
self.assert_(vm2 is not None, "VM failed to deploy")
self.assert_(vm2.state == 'Running', "VM is not running")
self.cleanup.append(vm2)
self.debug("VM %s deployed in VPC %s" % (vm2.id, vpc2.id))
# 4) Enable Site-to-Site VPN for VPC
@ -758,10 +763,10 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception, e:
raise Exception("Cleanup failed with %s" % e)
super(TestVpcSite2SiteVpn, cls).tearDownClass()
def tearDown(self):
super(TestVpcSite2SiteVpn, self).tearDown()
class TestRVPCSite2SiteVpn(cloudstackTestCase):
@ -779,14 +784,17 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.domain = get_domain(cls.apiclient)
cls._cleanup = []
cls.compute_offering = ServiceOffering.create(
cls.apiclient,
cls.services["compute_offering"]
)
cls._cleanup.append(cls.compute_offering)
cls.account = Account.create(
cls.apiclient, services=cls.services["account"])
cls._cleanup.append(cls.account)
cls.hypervisor = testClient.getHypervisorInfo()
@ -797,8 +805,6 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
cls.logger.debug("Successfully created account: %s, id: \
%s" % (cls.account.name,
cls.account.id))
cls.cleanup = [cls.account, cls.compute_offering]
return
def _validate_vpc_offering(self, vpc_offering):
@ -901,7 +907,6 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
'redundant_vpc_offering')
self.assert_(redundant_vpc_offering is not None,
"Failed to create redundant VPC Offering")
redundant_vpc_offering.update(self.apiclient, state='Enabled')
# Create VPC 1
@ -920,7 +925,7 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assert_(vpc1 is not None, "VPC1 creation failed")
self.cleanup.append(vpc1)
self.logger.debug("VPC1 %s created" % vpc1.id)
# Create VPC 2
@ -939,7 +944,7 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assert_(vpc2 is not None, "VPC2 creation failed")
self.cleanup.append(vpc2)
self.logger.debug("VPC2 %s created" % vpc2.id)
default_acl = NetworkACLList.list(
@ -962,7 +967,7 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assertIsNotNone(ntwk1, "Network failed to create")
self.cleanup.append(ntwk1)
self.logger.debug("Network %s created in VPC %s" % (ntwk1.id, vpc1.id))
# Create network in VPC 2
@ -982,7 +987,7 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
self.fail(e)
finally:
self.assertIsNotNone(ntwk2, "Network failed to create")
self.cleanup.append(ntwk2)
self.logger.debug("Network %s created in VPC %s" % (ntwk2.id, vpc2.id))
# Deploy a vm in network 2
@ -1002,7 +1007,7 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
finally:
self.assert_(vm1 is not None, "VM failed to deploy")
self.assert_(vm1.state == 'Running', "VM is not running")
self.cleanup.append(vm1)
self.logger.debug("VM %s deployed in VPC %s" % (vm1.id, vpc1.id))
# Deploy a vm in network 2
@ -1022,7 +1027,7 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
finally:
self.assert_(vm2 is not None, "VM failed to deploy")
self.assert_(vm2.state == 'Running', "VM is not running")
self.cleanup.append(vm2)
self.debug("VM %s deployed in VPC %s" % (vm2.id, vpc2.id))
# 4) Enable Site-to-Site VPN for VPC
@ -1130,11 +1135,15 @@ class TestRVPCSite2SiteVpn(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception, e:
raise Exception("Cleanup failed with %s" % e)
super(TestRVPCSite2SiteVpn, cls).tearDownClass()
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.cleanup = []
def tearDown(self):
super(TestRVPCSite2SiteVpn, self).tearDown()
class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
@ -1152,13 +1161,17 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.domain = get_domain(cls.apiclient)
cls._cleanup = []
cls.compute_offering = ServiceOffering.create(
cls.apiclient,
cls.services["compute_offering"]
)
cls._cleanup.append(cls.compute_offering)
cls.account = Account.create(
cls.apiclient, services=cls.services["account"])
cls._cleanup.append(cls.account)
cls.hypervisor = testClient.getHypervisorInfo()
@ -1169,10 +1182,13 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
cls.logger.debug("Successfully created account: %s, id: \
%s" % (cls.account.name,
cls.account.id))
cls.cleanup = [cls.account, cls.compute_offering]
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.cleanup = []
def _get_ssh_client(self, virtual_machine, services, retries):
""" Setup ssh client connection and return connection
vm requires attributes public_ip, public_port, username, password """
@ -1288,7 +1304,7 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
self.fail(e)
finally:
self.assert_(vpc1 is not None, "VPC1 creation failed")
self.cleanup.append(vpc1)
self.logger.debug("VPC1 %s created" % vpc1.id)
vpc2 = None
@ -1307,7 +1323,7 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
self.fail(e)
finally:
self.assert_(vpc2 is not None, "VPC2 creation failed")
self.cleanup.append(vpc2)
self.logger.debug("VPC2 %s created" % vpc2.id)
default_acl = NetworkACLList.list(
@ -1330,7 +1346,7 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
self.fail(e)
finally:
self.assertIsNotNone(ntwk1, "Network failed to create")
self.cleanup.append(ntwk1)
self.logger.debug("Network %s created in VPC %s" % (ntwk1.id, vpc1.id))
ntwk2 = None
@ -1350,7 +1366,7 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
self.fail(e)
finally:
self.assertIsNotNone(ntwk2, "Network failed to create")
self.cleanup.append(ntwk2)
self.logger.debug("Network %s created in VPC %s" % (ntwk2.id, vpc2.id))
vm1 = None
@ -1370,7 +1386,7 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
finally:
self.assert_(vm1 is not None, "VM failed to deploy")
self.assert_(vm1.state == 'Running', "VM is not running")
self.cleanup.append(vm1)
self.logger.debug("VM %s deployed in VPC %s" % (vm1.id, vpc1.id))
vm2 = None
@ -1390,7 +1406,7 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
finally:
self.assert_(vm2 is not None, "VM failed to deploy")
self.assert_(vm2.state == 'Running', "VM is not running")
self.cleanup.append(vm2)
self.debug("VM %s deployed in VPC %s" % (vm2.id, vpc2.id))
# default config
@ -1567,10 +1583,6 @@ class TestVPCSite2SiteVPNMultipleOptions(cloudstackTestCase):
out['esplifetime'] = c['esp_life']
return out
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.apiclient, cls.cleanup)
except Exception, e:
raise Exception("Cleanup failed with %s" % e)
super(TestVPCSite2SiteVPNMultipleOptions, cls).tearDownClass()

View File

@ -324,7 +324,7 @@ class TestStorageMigration(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.apiclient, cls._cleanup)
cleanup_resources(cls.apiclient, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@ -335,13 +335,9 @@ class TestStorageMigration(cloudstackTestCase):
self.cleanup = []
def tearDown(self):
try:
for storagePool in self.pools:
StoragePool.update(self.apiclient, id=storagePool.id, tags="")
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
for storagePool in self.pools:
StoragePool.update(self.apiclient, id=storagePool.id, tags="")
super(TestStorageMigration,self).tearDown()
@attr(tags=["advanced", "basic"], required_hardware="true")
def test_01_migrate_root_and_data_disk_nonlive(self):

View File

@ -16,7 +16,7 @@
# under the License.
import unittest
from marvin.lib.utils import verifyElementInList
from marvin.lib.utils import verifyElementInList, cleanup_resources
from marvin.codes import PASS
@ -56,3 +56,22 @@ class cloudstackTestCase(unittest.case.TestCase):
@classmethod
def getClsConfig(cls):
return cls.config
@classmethod
def tearDownClass(cls):
try:
if hasattr(cls,'_cleanup'):
if hasattr(cls,'apiclient'):
cleanup_resources(cls.apiclient, reversed(cls._cleanup))
elif hasattr(cls,'api_client'):
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def tearDown(self):
try:
if hasattr(self,'apiclient') and hasattr(self,'cleanup'):
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return