cleanup for resources left by test_accounts and test_project(#3657)

This commit is contained in:
dahn 2020-03-09 12:19:37 +01:00 committed by GitHub
parent 6f9890694d
commit 1942f5734e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 567 additions and 235 deletions

View File

@ -128,7 +128,7 @@
},
{
"url": "nfs://10.147.28.6:/export/home/sandbox/primary3",
"name": "PS2"
"name": "PS3"
}
]
}

377
setup/dev/dualsim.cfg Normal file
View File

@ -0,0 +1,377 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
{
"zones": [
{
"name": "zim1",
"guestcidraddress": "10.100.1.0/24",
"dns1": "10.147.100.6",
"physical_networks": [
{
"broadcastdomainrange": "Zone",
"vlan": "1100-1200",
"name": "z1-pnet",
"traffictypes": [
{
"typ": "Guest"
},
{
"typ": "Management"
},
{
"typ": "Public"
}
],
"providers": [
{
"broadcastdomainrange": "ZONE",
"name": "VirtualRouter"
},
{
"broadcastdomainrange": "ZONE",
"name": "VpcVirtualRouter"
},
{
"broadcastdomainrange": "ZONE",
"name": "InternalLbVm"
}
],
"isolationmethods": [
"VLAN"
]
}
],
"vmwaredc": {
"username": "",
"vcenter": "",
"password": "",
"name": ""
},
"ipranges": [
{
"startip": "192.168.100.2",
"endip": "192.168.100.200",
"netmask": "255.255.255.0",
"vlan": "50",
"gateway": "192.168.100.1"
}
],
"networktype": "Advanced",
"pods": [
{
"endip": "172.16.100.200",
"name": "Z1P1",
"startip": "172.16.100.2",
"netmask": "255.255.255.0",
"clusters": [
{
"clustername": "Z1P1C1",
"hypervisor": "simulator",
"hosts": [
{
"username": "root",
"url": "http://sim1/c1/h1",
"password": "password"
},
{
"username": "root",
"url": "http://sim1/c1/h2",
"password": "password"
}
],
"clustertype": "CloudManaged",
"primaryStorages": [
{
"url": "nfs://10.147.100.6:/export/home/sandbox/z1p1",
"name": "Z1PS1"
},
{
"url": "nfs://10.147.100.6:/export/home/sandbox/z1p2",
"name": "Z1PS2"
}
]
},
{
"clustername": "Z1P1C2",
"hypervisor": "simulator",
"hosts": [
{
"username": "root",
"url": "http://sim1/c2/h1",
"password": "password"
},
{
"username": "root",
"url": "http://sim1/c2/h2",
"password": "password"
}
],
"clustertype": "CloudManaged",
"primaryStorages": [
{
"url": "nfs://10.147.100.6:/export/home/sandbox/z1p3",
"name": "Z1PS3"
},
{
"url": "nfs://10.147.100.6:/export/home/sandbox/z1p4",
"name": "Z1PS4"
}
]
}
],
"gateway": "172.16.100.1"
}
],
"internaldns1": "10.147.100.6",
"secondaryStorages": [
{
"url": "nfs://10.147.100.6:/export/home/sandbox/z1secondary",
"provider" : "NFS"
}
]
},
{
"name": "zim2",
"guestcidraddress": "10.200.1.0/24",
"dns1": "10.147.200.6",
"physical_networks": [
{
"broadcastdomainrange": "Zone",
"vlan": "2100-2200",
"name": "z2-pnet",
"traffictypes": [
{
"typ": "Guest"
},
{
"typ": "Management"
},
{
"typ": "Public"
}
],
"providers": [
{
"broadcastdomainrange": "ZONE",
"name": "VirtualRouter"
},
{
"broadcastdomainrange": "ZONE",
"name": "VpcVirtualRouter"
},
{
"broadcastdomainrange": "ZONE",
"name": "InternalLbVm"
}
],
"isolationmethods": [
"VLAN"
]
}
],
"vmwaredc": {
"username": "",
"vcenter": "",
"password": "",
"name": ""
},
"ipranges": [
{
"startip": "192.168.200.2",
"endip": "192.168.200.200",
"netmask": "255.255.255.0",
"vlan": "50",
"gateway": "192.168.200.1"
}
],
"networktype": "Advanced",
"pods": [
{
"endip": "172.16.200.200",
"name": "Z2P1",
"startip": "172.16.200.2",
"netmask": "255.255.255.0",
"clusters": [
{
"clustername": "Z2P1C1",
"hypervisor": "simulator",
"hosts": [
{
"username": "root",
"url": "http://sim2/c1/h1",
"password": "password"
},
{
"username": "root",
"url": "http://sim2/c1/h2",
"password": "password"
}
],
"clustertype": "CloudManaged",
"primaryStorages": [
{
"url": "nfs://10.147.200.6:/export/home/sandbox/z2p1",
"name": "Z2PS1"
},
{
"url": "nfs://10.147.200.6:/export/home/sandbox/z2p2",
"name": "Z2PS2"
}
]
},
{
"clustername": "Z2P2C1",
"hypervisor": "simulator",
"hosts": [
{
"username": "root",
"url": "http://sim2/c1/h1",
"password": "password"
},
{
"username": "root",
"url": "http://sim2/c1/h2",
"password": "password"
}
],
"clustertype": "CloudManaged",
"primaryStorages": [
{
"url": "nfs://10.147.200.6:/export/home/sandbox/z2p3",
"name": "Z2PS3"
},
{
"url": "nfs://10.147.200.6:/export/home/sandbox/z2p4",
"name": "Z2PS4"
}
]
}
],
"gateway": "172.16.200.1"
}
],
"internaldns1": "10.147.200.6",
"secondaryStorages": [
{
"url": "nfs://10.147.200.6:/export/home/sandbox/z2secondary",
"provider" : "NFS"
}
]
}
],
"dbSvr": {
"dbSvr": "localhost",
"passwd": "cloud",
"db": "cloud",
"port": 3306,
"user": "cloud"
},
"logger":
{
"LogFolderPath": "/tmp"
},
"globalConfig": [
{
"name": "network.gc.wait",
"value": "20"
},
{
"name": "storage.cleanup.interval",
"value": "40"
},
{
"name": "vm.op.wait.interval",
"value": "5"
},
{
"name": "default.page.size",
"value": "500"
},
{
"name": "network.gc.interval",
"value": "20"
},
{
"name": "instance.name",
"value": "QA"
},
{
"name": "workers",
"value": "10"
},
{
"name": "account.cleanup.interval",
"value": "20"
},
{
"name": "guest.domain.suffix",
"value": "sandbox.simulator"
},
{
"name": "expunge.delay",
"value": "20"
},
{
"name": "vm.allocation.algorithm",
"value": "random"
},
{
"name": "expunge.interval",
"value": "20"
},
{
"name": "expunge.workers",
"value": "3"
},
{
"name": "check.pod.cidrs",
"value": "true"
},
{
"name": "secstorage.allowed.internal.sites",
"value": "10.147.0.0/16"
},
{
"name": "direct.agent.load.size",
"value": "1000"
},
{
"name": "enable.dynamic.scale.vm",
"value": "true"
},
{
"name": "ping.interval",
"value": "10"
},
{
"name": "ping.timeout",
"value": "2.0"
}
],
"mgtSvr": [
{
"mgtSvrIp": "localhost",
"passwd": "password",
"user": "root",
"port": 8096,
"hypervisor": "simulator",
"useHttps": "False",
"certCAPath": "NA",
"certPath": "NA"
}
]
}

View File

@ -155,7 +155,7 @@ class TestAccounts(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -169,7 +169,7 @@ class TestAccounts(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -280,12 +280,13 @@ class TestAccounts(cloudstackTestCase):
ts = str(time.time())
network_domain = 'mycloud.com'
account = Account.create(self.apiclient, self.services['account'])
self.cleanup.append(account)
# role will be in cleanup list first so it won't be deleted before the account it is on.
role = Role.create(self.apiclient, self.services['role'])
self.cleanup.append(role)
account = Account.create(self.apiclient, self.services['account'])
self.cleanup.append(account)
account.update(self.apiclient, newname=account.name + ts)
account.update(self.apiclient, roleid=role.id)
account.update(self.apiclient, networkdomain=network_domain)
@ -353,7 +354,7 @@ class TestRemoveUserFromAccount(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -367,7 +368,7 @@ class TestRemoveUserFromAccount(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created instance, users etc
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -494,28 +495,27 @@ class TestNonRootAdminsPrivileges(cloudstackTestCase):
cls.services = Services().services
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.services['mode'] = cls.zone.networktype
cls._cleanup = []
# Create an account, domain etc
cls.domain = Domain.create(
cls.api_client,
cls.services["domain"],
)
cls._cleanup.append(cls.domain)
cls.account = Account.create(
cls.api_client,
cls.services["account"],
admin=True,
domainid=cls.domain.id
)
cls._cleanup = [
cls.account,
cls.domain
]
cls._cleanup.append(cls.account)
return
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -529,7 +529,7 @@ class TestNonRootAdminsPrivileges(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created accounts
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -601,20 +601,25 @@ class TestServiceOfferingSiblings(cloudstackTestCase):
).getClsTestClient().getApiClient()
cls.services = Services().services
cls._cleanup = []
# Create Domains, accounts etc
cls.domain_1 = Domain.create(
cls.api_client,
cls.services["domain"]
)
cls._cleanup.append(cls.domain_1)
cls.domain_2 = Domain.create(
cls.api_client,
cls.services["domain"]
)
cls._cleanup.append(cls.domain_2)
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"],
domainid=cls.domain_1.id
)
cls._cleanup.append(cls.service_offering)
# Create account for doamin_1
cls.account_1 = Account.create(
cls.api_client,
@ -622,6 +627,7 @@ class TestServiceOfferingSiblings(cloudstackTestCase):
admin=True,
domainid=cls.domain_1.id
)
cls._cleanup.append(cls.account_1)
# Create an account for domain_2
cls.account_2 = Account.create(
@ -630,21 +636,15 @@ class TestServiceOfferingSiblings(cloudstackTestCase):
admin=True,
domainid=cls.domain_2.id
)
cls._cleanup.append(cls.account_2)
cls._cleanup = [
cls.account_1,
cls.account_2,
cls.service_offering,
cls.domain_1,
cls.domain_2,
]
return
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -658,7 +658,7 @@ class TestServiceOfferingSiblings(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created domains, accounts
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -725,21 +725,26 @@ class TestServiceOfferingHierarchy(cloudstackTestCase):
).getClsTestClient().getApiClient()
cls.services = Services().services
cls._cleanup = []
# Create domain, service offerings etc
cls.domain_1 = Domain.create(
cls.api_client,
cls.services["domain"]
)
cls._cleanup.append(cls.domain_1)
cls.domain_2 = Domain.create(
cls.api_client,
cls.services["domain"],
parentdomainid=cls.domain_1.id
)
cls._cleanup.append(cls.domain_2)
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"],
domainid=cls.domain_1.id
)
cls._cleanup.append(cls.service_offering)
# Create account for doamin_1
cls.account_1 = Account.create(
cls.api_client,
@ -747,7 +752,7 @@ class TestServiceOfferingHierarchy(cloudstackTestCase):
admin=True,
domainid=cls.domain_1.id
)
cls._cleanup.append(cls.account_1)
# Create an account for domain_2
cls.account_2 = Account.create(
cls.api_client,
@ -755,14 +760,7 @@ class TestServiceOfferingHierarchy(cloudstackTestCase):
admin=True,
domainid=cls.domain_2.id
)
cls._cleanup = [
cls.account_2,
cls.domain_2,
cls.service_offering,
cls.account_1,
cls.domain_1,
]
cls._cleanup.append(cls.account_2)
return
@ -770,7 +768,7 @@ class TestServiceOfferingHierarchy(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -784,7 +782,7 @@ class TestServiceOfferingHierarchy(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -852,16 +850,20 @@ class TestTemplateHierarchy(cloudstackTestCase):
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.services['mode'] = cls.zone.networktype
cls._cleanup = []
# Create domains, accounts and template
cls.domain_1 = Domain.create(
cls.api_client,
cls.services["domain"]
)
cls._cleanup.append(cls.domain_1)
cls.domain_2 = Domain.create(
cls.api_client,
cls.services["domain"],
parentdomainid=cls.domain_1.id
)
cls._cleanup.append(cls.domain_2)
# Create account for doamin_1
cls.account_1 = Account.create(
@ -870,6 +872,7 @@ class TestTemplateHierarchy(cloudstackTestCase):
admin=True,
domainid=cls.domain_1.id
)
cls._cleanup.append(cls.account_1)
# Create an account for domain_2
cls.account_2 = Account.create(
@ -878,13 +881,7 @@ class TestTemplateHierarchy(cloudstackTestCase):
admin=True,
domainid=cls.domain_2.id
)
cls._cleanup = [
cls.account_2,
cls.domain_2,
cls.account_1,
cls.domain_1,
]
cls._cleanup.append(cls.account_2)
builtin_info = get_builtin_template_info(cls.api_client, cls.zone.id)
cls.services["template"]["url"] = builtin_info[0]
@ -900,6 +897,7 @@ class TestTemplateHierarchy(cloudstackTestCase):
domainid=cls.domain_1.id,
hypervisor=cls.hypervisor
)
cls._cleanup.append(cls.template)
# Wait for template to download
cls.template.download(cls.api_client)
@ -912,7 +910,7 @@ class TestTemplateHierarchy(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -926,7 +924,7 @@ class TestTemplateHierarchy(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created instance, volumes and snapshots
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1005,11 +1003,14 @@ class TestAddVmToSubDomain(cloudstackTestCase):
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.hypervisor = cls.testClient.getHypervisorInfo()
cls.services['mode'] = cls.zone.networktype
cls._cleanup = []
cls.sub_domain = Domain.create(
cls.api_client,
cls.services["domain"],
parentdomainid=cls.domain.id
)
cls._cleanup.append(cls.sub_domain)
# Create account for doamin_1
cls.account_1 = Account.create(
@ -1018,6 +1019,7 @@ class TestAddVmToSubDomain(cloudstackTestCase):
admin=True,
domainid=cls.domain.id
)
cls._cleanup.append(cls.account_1)
# Create an account for domain_2
cls.account_2 = Account.create(
@ -1026,19 +1028,15 @@ class TestAddVmToSubDomain(cloudstackTestCase):
admin=True,
domainid=cls.sub_domain.id
)
cls._cleanup.append(cls.account_2)
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"],
domainid=cls.domain.id
)
cls._cleanup.append(cls.service_offering)
cls._cleanup = [
cls.account_2,
cls.account_1,
cls.sub_domain,
cls.service_offering
]
cls.template = get_test_template(
cls.api_client,
cls.zone.id,
@ -1068,7 +1066,7 @@ class TestAddVmToSubDomain(cloudstackTestCase):
def tearDownClass(cls):
try:
# Clean up, terminate the created resources
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1082,7 +1080,7 @@ class TestAddVmToSubDomain(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created resources
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1164,7 +1162,7 @@ class TestUserDetails(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1178,7 +1176,7 @@ class TestUserDetails(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1463,7 +1461,7 @@ class TestUserLogin(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1477,7 +1475,7 @@ class TestUserLogin(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1558,7 +1556,7 @@ class TestUserLogin(cloudstackTestCase):
self.services["domain"],
parentdomainid=self.domain.id
)
self.cleanup.append(domain)
self.debug("Domain: %s is created successfully." % domain.name)
self.debug("Validating the created domain")
@ -1574,11 +1572,8 @@ class TestUserLogin(cloudstackTestCase):
self.services["domain"],
parentdomainid=domain.id
)
self.debug("Sub-Domain: %s is created successfully." % subDomain.name)
self.cleanup.append(subDomain)
self.cleanup.append(domain)
self.debug("Sub-Domain: %s is created successfully." % subDomain.name)
self.debug("Validating the created sub-domain")
list_sub_domain = Domain.list(self.api_client, id=subDomain.id)
@ -1631,6 +1626,7 @@ class TestUserLogin(cloudstackTestCase):
self.services["domain"],
parentdomainid=self.domain.id
)
self.cleanup.append(domain)
self.debug("Domain: %s is created succesfully." % domain.name)
self.debug(
"Checking if the created domain is listed in list domains API")
@ -1690,40 +1686,39 @@ class TestUserAPIKeys(cloudstackTestCase):
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.services['mode'] = cls.zone.networktype
cls._cleanup = []
# Create an account, domain etc
cls.domain = Domain.create(
cls.api_client,
cls.services["domain"],
)
cls._cleanup.append(cls.domain)
cls.account = Account.create(
cls.api_client,
cls.services["account"],
admin=False,
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.domain_2 = Domain.create(
cls.api_client,
cls.services["domain"],
)
cls._cleanup.append(cls.domain_2)
cls.account_2 = Account.create(
cls.api_client,
cls.services["account"],
admin=False,
domainid=cls.domain_2.id
)
cls._cleanup = [
cls.account,
cls.domain,
cls.account_2,
cls.domain_2
]
cls._cleanup.append(cls.account_2)
return
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1737,7 +1732,7 @@ class TestUserAPIKeys(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1875,7 +1870,7 @@ class TestDomainForceRemove(cloudstackTestCase):
def tearDownClass(cls):
try:
# Clean up, terminate the created resources
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@ -1890,7 +1885,7 @@ class TestDomainForceRemove(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created resources
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -2043,8 +2038,10 @@ class TestDomainForceRemove(cloudstackTestCase):
"Length of response from listLbRules should not be 0"
)
except Exception as e:
self.clenaup.append(self.account_1)
self.cleanup.append(self.domain)
self.cleanup.append(self.account_1)
self.cleanup.append(self.account_2)
self.cleanup.append(self.service_offering)
self.fail(e)
self.debug("Deleting domain with force option")
@ -2102,6 +2099,8 @@ class TestDomainForceRemove(cloudstackTestCase):
self.services["domain"],
parentdomainid=self.domain.id
)
# in this test delete domain *should* fail so we need to housekeep:
self.cleanup.append(domain)
self.debug("Domain: %s is created successfully." % domain.name)
self.debug(
"Checking if the created domain is listed in list domains API")
@ -2250,7 +2249,7 @@ class TestMoveUser(cloudstackTestCase):
def tearDownClass(cls):
try:
# Clean up, terminate the created resources
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@ -2287,7 +2286,7 @@ class TestMoveUser(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created resources
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -2337,7 +2336,6 @@ class TestMoveUser(cloudstackTestCase):
else:
self.fail("It should not be allowed to move users across accounts in different domains, failing")
account_different_domain.delete(self.api_client)
return
@attr(tags=["domains", "advanced", "advancedns", "simulator","dvs"], required_hardware="false")

View File

@ -153,7 +153,7 @@ class TestMultipleProjectCreation(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -170,7 +170,7 @@ class TestMultipleProjectCreation(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -365,6 +365,7 @@ class TestCrossDomainAccountAdd(cloudstackTestCase):
cls.api_client,
cls.services["domain"]
)
cls._cleanup.append(cls.new_domain)
cls.account = Account.create(
cls.api_client,
@ -387,7 +388,7 @@ class TestCrossDomainAccountAdd(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -404,7 +405,7 @@ class TestCrossDomainAccountAdd(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -518,7 +519,7 @@ class TestDeleteAccountWithProject(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -535,7 +536,7 @@ class TestDeleteAccountWithProject(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1249,7 +1250,7 @@ class TestProjectResources(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1266,7 +1267,7 @@ class TestProjectResources(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1569,12 +1570,14 @@ class TestProjectSuspendActivate(cloudstackTestCase):
admin=True,
domainid=cls.domain.id
)
cls._cleanup.append(cls.account)
cls.user = Account.create(
cls.api_client,
cls.services["account"],
admin=True,
domainid=cls.domain.id
)
cls._cleanup.append(cls.user)
# Create project as a domain admin
cls.project = Project.create(
@ -1584,8 +1587,6 @@ class TestProjectSuspendActivate(cloudstackTestCase):
domainid=cls.account.domainid
)
cls._cleanup.append(cls.project)
cls._cleanup.append(cls.account)
cls._cleanup.append(cls.user)
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
return
@ -1593,7 +1594,7 @@ class TestProjectSuspendActivate(cloudstackTestCase):
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
cleanup_resources(cls.api_client, reversed(cls._cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@ -1610,7 +1611,7 @@ class TestProjectSuspendActivate(cloudstackTestCase):
def tearDown(self):
try:
# Clean up, terminate the created accounts, domains etc
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return

View File

@ -41,49 +41,6 @@ from marvin.cloudstackAPI import (createTemplate, listOsTypes)
_multiprocess_shared_ = True
# Function to create template with name existing in test_data without any extensions
def create(apiclient, services, volumeid=None, account=None, domainid=None, projectid=None):
cmd = createTemplate.createTemplateCmd()
cmd.displaytext = services["displaytext"]
cmd.name = services["name"]
if "ostypeid" in services:
cmd.ostypeid = services["ostypeid"]
elif "ostype" in services:
sub_cmd = listOsTypes.listOsTypesCmd()
sub_cmd.description = services["ostype"]
ostypes = apiclient.listOsTypes(sub_cmd)
if not isinstance(ostypes, list):
raise Exception(
"Unable to find Ostype id with desc: %s" % services["ostype"]
)
cmd.ostypeid = ostypes[0].id
else:
raise Exception(
"Unable to find Ostype is required for creating template")
cmd.isfeatured = services[
"isfeatured"] if "isfeatured" in services else False
cmd.ispublic = services[
"ispublic"] if "ispublic" in services else False
cmd.isextractable = services[
"isextractable"] if "isextractable" in services else False
cmd.passwordenabled = services[
"passwordenabled"] if "passwordenabled" in services else False
if volumeid:
cmd.volumeid = volumeid
if account:
cmd.account = account
if domainid:
cmd.domainid = domainid
if projectid:
cmd.projectid = projectid
return apiclient.createTemplate(cmd)
class TestCreateTemplateWithChecksum(cloudstackTestCase):
def setUp(self):
self.testClient = super(TestCreateTemplateWithChecksum, self).getClsTestClient()
@ -298,7 +255,7 @@ class TestCreateTemplate(cloudstackTestCase):
def tearDown(self):
try:
#Clean up, terminate the created templates
cleanup_resources(self.apiclient, self.cleanup)
cleanup_resources(self.apiclient, reversed(self.cleanup))
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@ -383,9 +340,8 @@ class TestCreateTemplate(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cls.apiclient = super(TestCreateTemplate, cls).getClsTestClient().getApiClient()
#Cleanup resources used
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)
@ -401,14 +357,18 @@ class TestCreateTemplate(cloudstackTestCase):
#2. check the db that the templates with same name have different unique_name
#Create templates from Virtual machine and Volume ID
template1 = create(self.apiclient,
self.services["template"],
self.volume.id,
account=self.account.name)
template2 = create(self.apiclient,
self.services["template"],
self.volume.id,
account=self.account.name)
template1 = Template.create(self.apiclient,
self.services["template"],
self.volume.id,
account=self.account.name,
randomise=False)
self.cleanup.append(template1)
template2 = Template.create(self.apiclient,
self.services["template"],
self.volume.id,
account=self.account.name,
randomise=False)
self.cleanup.append(template2)
self.debug("Created template with ID: %s" % template1.id)
self.debug("Created template with ID: %s" % template2.id)
@ -1000,32 +960,12 @@ class TestTemplates(cloudstackTestCase):
"ListTemplates should not list any system templates"
)
return
class TestCopyDeleteTemplate(cloudstackTestCase):
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
if self.unsupportedHypervisor:
self.skipTest("Skipping test because unsupported hypervisor\
%s" % self.hypervisor)
return
def tearDown(self):
try:
#Clean up, terminate the created templates
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
class TestCopyAndDeleteTemplatesAcrossZones(cloudstackTestCase):
@classmethod
def setUpClass(cls):
testClient = super(TestCopyDeleteTemplate, cls).getClsTestClient()
testClient = super(TestCopyAndDeleteTemplatesAcrossZones, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient()
cls._cleanup = []
cls.services = testClient.getParsedTestDataConfig()
@ -1042,15 +982,15 @@ class TestCopyDeleteTemplate(cloudstackTestCase):
cls.services['mode'] = cls.zone.networktype
try:
cls.disk_offering = DiskOffering.create(
cls.apiclient,
cls.services["disk_offering"]
)
cls.apiclient,
cls.services["disk_offering"]
)
cls._cleanup.append(cls.disk_offering)
template = get_template(
cls.apiclient,
cls.zone.id,
cls.services["ostype"]
)
cls.apiclient,
cls.zone.id,
cls.services["ostype"]
)
if template == FAILED:
assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
@ -1063,35 +1003,35 @@ class TestCopyDeleteTemplate(cloudstackTestCase):
cls.services["volume"]["zoneid"] = cls.zone.id
cls.services["sourcezoneid"] = cls.zone.id
cls.account = Account.create(
cls.apiclient,
cls.services["account"],
domainid=cls.domain.id
)
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.apiclient,
cls.services["service_offerings"]["tiny"]
)
cls._cleanup.append(cls.service_offering)
#create virtual machine
cls.virtual_machine = VirtualMachine.create(
cls.apiclient,
cls.services["virtual_machine"],
templateid=template.id,
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
mode=cls.services["mode"]
)
cls.apiclient,
cls.services["virtual_machine"],
templateid=template.id,
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id,
mode=cls.services["mode"]
)
#Stop virtual machine
cls.virtual_machine.stop(cls.apiclient)
list_volume = Volume.list(
cls.apiclient,
virtualmachineid=cls.virtual_machine.id,
type='ROOT',
listall=True
)
cls.apiclient,
virtualmachineid=cls.virtual_machine.id,
type='ROOT',
listall=True
)
cls.volume = list_volume[0]
except Exception as e:
@ -1102,71 +1042,83 @@ class TestCopyDeleteTemplate(cloudstackTestCase):
@classmethod
def tearDownClass(cls):
try:
cls.apiclient = super(TestCopyDeleteTemplate, cls).getClsTestClient().getApiClient()
#Cleanup resources used
cleanup_resources(cls.apiclient, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
if self.unsupportedHypervisor:
self.skipTest("Skipping test because unsupported hypervisor\
%s" % self.hypervisor)
return
def tearDown(self):
try:
#Clean up, terminate the created templates
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["advanced", "advancedns"], required_hardware="false")
def test_09_copy_delete_template(self):
cmd = listZones.listZonesCmd()
cmd = listZones.listZonesCmd()
zones = self.apiclient.listZones(cmd)
if not isinstance(zones, list):
raise Exception("Failed to find zones.")
if len(zones) < 2:
self.skipTest(
"Skipping test due to there are less than two zones.")
return
self.sourceZone = zones[0]
self.destZone = zones[1]
self.skipTest("Skipping test due to there are less than two zones.")
return
self.sourceZone = zones[0]
self.destZone = zones[1]
template = Template.create(
self.apiclient,
self.services["template"],
self.volume.id,
account=self.account.name,
domainid=self.account.domainid
)
self.apiclient,
self.services["template"],
self.volume.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(template)
self.debug("Created template with ID: %s" % template.id)
list_template_response = Template.list(
self.apiclient,
templatefilter=\
self.services["templatefilter"],
id=template.id
)
self.apiclient,
templatefilter= self.services["templatefilter"],
id=template.id
)
self.assertEqual(
isinstance(list_template_response, list),
True,
"Check list response returns a valid list"
)
#Verify template response to check whether template added successfully
self.assertNotEqual(
len(list_template_response),
0,
"Check template available in List Templates"
)
#Copy template from zone1 to zone2
copytemplate = Template.copy(
cls.apiclient,
zoneid=cls.sourceZone.id,
destzoneid = cls.destZone.id
isinstance(list_template_response, list),
True,
"Check list response returns a valid list"
)
cls._cleanup.append(cls.copytemplate)
# Verify template response to check whether template added successfully
self.assertNotEqual(
len(list_template_response),
0,
"Check template available in List Templates"
)
# todo: check for template ready
# Copy template from zone1 to zone2
self.copytemplate = template.copy(
self.apiclient,
sourcezoneid=self.sourceZone.id,
destzoneid=self.destZone.id
)
self.cleanup.append(self.copytemplate)
list_template_response = Template.list(
self.apiclient,
templatefilter=self.services["template"]["templatefilter"],
templatefilter=self.services["template"]["templatefilter"],
id=self.template.id,
zoneid=self.destZone.id
)
@ -1183,17 +1135,18 @@ class TestCopyDeleteTemplate(cloudstackTestCase):
self.deltemplate.delete(self.apiclient)
self.debug("Delete template: %s successful" % self.deltemplate)
copytemplate = Template.copy(
copytemplate = template.copy(
self.apiclient,
zoneid=self.sourceZone.id,
sourcezoneid=self.sourceZone.id,
destzoneid = self.destZone.id
)
self.cleanup.append(copytemplate)
removed = cls.dbclient.execute("select removed from template_zone_ref where zone_id='%s' and template_id='%s';" % self.destZone.id, self.template.id)
removed = self.dbclient.execute("select removed from template_zone_ref where zone_id='%s' and template_id='%s';" % self.destZone.id, self.template.id)
self.assertEqual(
removed,
NULL,
None,
"Removed state is not correct."
)
return

View File

@ -1265,12 +1265,15 @@ class Template:
@classmethod
def create(cls, apiclient, services, volumeid=None,
account=None, domainid=None, projectid=None):
account=None, domainid=None, projectid=None, randomise=True):
"""Create template from Volume"""
# Create template from Virtual machine and Volume ID
cmd = createTemplate.createTemplateCmd()
cmd.displaytext = services["displaytext"]
cmd.name = "-".join([services["name"], random_gen()])
if randomise:
cmd.name = "-".join([services["name"], random_gen()])
else:
cmd.name = services["name"]
if "ostypeid" in services:
cmd.ostypeid = services["ostypeid"]
elif "ostype" in services: