diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java index 52bc5aac7e25..e1a2efd74066 100755 --- a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java @@ -170,4 +170,6 @@ List searchRemovedByRemoveDate(final Date startDate, final Date en List skippedVmIds); Pair, Integer> listByVmsNotInClusterUsingPool(long clusterId, long poolId); + + List listByOfferingId(long offeringId); } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java index 744518ba7433..a529fb4e0ec2 100755 --- a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -99,6 +99,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem protected SearchBuilder StartingWithNoHostSearch; protected SearchBuilder NotMigratingSearch; protected SearchBuilder BackupSearch; + protected SearchBuilder ServiceOfferingSearch; protected SearchBuilder LastHostAndStatesSearch; protected SearchBuilder VmsNotInClusterUsingPool; @@ -325,6 +326,11 @@ protected void init() { VmsNotInClusterUsingPool.join("hostSearch2", hostSearch2, hostSearch2.entity().getId(), VmsNotInClusterUsingPool.entity().getHostId(), JoinType.INNER); VmsNotInClusterUsingPool.and("vmStates", VmsNotInClusterUsingPool.entity().getState(), Op.IN); VmsNotInClusterUsingPool.done(); + + ServiceOfferingSearch = createSearchBuilder(); + ServiceOfferingSearch.and("states", ServiceOfferingSearch.entity().getState(), Op.IN); + ServiceOfferingSearch.and("serviceOfferingId", ServiceOfferingSearch.entity().getServiceOfferingId(), Op.EQ); + ServiceOfferingSearch.done(); } @Override @@ -1069,4 +1075,12 @@ public Pair, Integer> listByVmsNotInClusterUsingPool(long clu List uniqueVms = vms.stream().distinct().collect(Collectors.toList()); return new Pair<>(uniqueVms, uniqueVms.size()); } + + @Override + public List listByOfferingId(long offeringId) { + SearchCriteria sc = ServiceOfferingSearch.create(); + sc.setParameters("states", State.Starting, State.Running, State.Stopping, State.Stopped, State.Migrating, State.Restoring); + sc.setParameters("serviceOfferingId", offeringId); + return search(sc, null); + } } diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index f4c9b19c1926..1c3e627788ad 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -3431,7 +3431,7 @@ private Ternary, Integer, String[]> searchForDiskOfferingsIdsAndCount diskOfferingSearch.and("computeOnly", diskOfferingSearch.entity().isComputeOnly(), Op.EQ); if (state != null) { - diskOfferingSearch.and("state", diskOfferingSearch.entity().getState(), Op.EQ); + diskOfferingSearch.and("state", diskOfferingSearch.entity().getState(), Op.IN); } // Keeping this logic consistent with domain specific zones @@ -3757,7 +3757,7 @@ private Pair, Integer> searchForServiceOfferingIdsAndCount(ListServic serviceOfferingSearch.select(null, Func.DISTINCT, serviceOfferingSearch.entity().getId()); // select distinct if (state != null) { - serviceOfferingSearch.and("state", serviceOfferingSearch.entity().getState(), Op.EQ); + serviceOfferingSearch.and("state", serviceOfferingSearch.entity().getState(), Op.IN); } if (vmId != null) { @@ -3914,8 +3914,7 @@ private Pair, Integer> searchForServiceOfferingIdsAndCount(ListServic } serviceOfferingSearch.join("diskOfferingSearch", diskOfferingSearch, JoinBuilder.JoinType.INNER, JoinBuilder.JoinCondition.AND, - serviceOfferingSearch.entity().getDiskOfferingId(), diskOfferingSearch.entity().getId(), - serviceOfferingSearch.entity().setString("Active"), diskOfferingSearch.entity().getState()); + serviceOfferingSearch.entity().getDiskOfferingId(), diskOfferingSearch.entity().getId()); } if (cpuNumber != null) { diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index 25cbd10de0a4..d034ce437942 100644 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -45,6 +45,17 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.dc.VlanDetailsVO; +import com.cloud.dc.dao.VlanDetailsDao; +import com.cloud.hypervisor.HypervisorGuru; +import com.cloud.network.dao.NsxProviderDao; +import com.cloud.network.element.NsxProviderVO; +import com.cloud.utils.crypt.DBEncryptionUtil; +import com.cloud.host.HostTagVO; +import com.cloud.storage.StoragePoolTagVO; +import com.cloud.storage.VolumeApiServiceImpl; +import com.cloud.vm.VMInstanceVO; +import com.googlecode.ipv6.IPv6Address; import org.apache.cloudstack.acl.SecurityChecker; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupService; @@ -161,7 +172,6 @@ import com.cloud.dc.PodVlanMapVO; import com.cloud.dc.Vlan; import com.cloud.dc.Vlan.VlanType; -import com.cloud.dc.VlanDetailsVO; import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.ClusterDao; @@ -175,7 +185,6 @@ import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; -import com.cloud.dc.dao.VlanDetailsDao; import com.cloud.dc.dao.VsphereStoragePolicyDao; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeploymentClusterPlanner; @@ -194,12 +203,10 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.gpu.GPU; -import com.cloud.host.HostTagVO; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostTagsDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.hypervisor.HypervisorGuru; import com.cloud.hypervisor.kvm.dpdk.DpdkHelper; import com.cloud.network.IpAddress; import com.cloud.network.IpAddressManager; @@ -222,13 +229,11 @@ import com.cloud.network.dao.Ipv6GuestPrefixSubnetNetworkMapDao; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.NetworkVO; -import com.cloud.network.dao.NsxProviderDao; import com.cloud.network.dao.PhysicalNetworkDao; import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO; import com.cloud.network.dao.PhysicalNetworkVO; import com.cloud.network.dao.UserIpv6AddressDao; -import com.cloud.network.element.NsxProviderVO; import com.cloud.network.rules.LoadBalancerContainer.Scheme; import com.cloud.network.vpc.VpcManager; import com.cloud.offering.DiskOffering; @@ -256,9 +261,7 @@ import com.cloud.storage.Storage; import com.cloud.storage.Storage.ProvisioningType; import com.cloud.storage.StorageManager; -import com.cloud.storage.StoragePoolTagVO; import com.cloud.storage.Volume; -import com.cloud.storage.VolumeApiServiceImpl; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.StoragePoolTagsDao; @@ -278,7 +281,6 @@ import com.cloud.utils.Pair; import com.cloud.utils.UriUtils; import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.db.DB; import com.cloud.utils.db.EntityManager; import com.cloud.utils.db.Filter; @@ -303,7 +305,6 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; -import com.googlecode.ipv6.IPv6Address; import com.googlecode.ipv6.IPv6Network; import static com.cloud.configuration.Config.SecStorageAllowedInternalDownloadSites; @@ -4367,8 +4368,11 @@ public boolean deleteDiskOffering(final DeleteDiskOfferingCmd cmd) { } annotationDao.removeByEntityType(AnnotationService.EntityType.DISK_OFFERING.name(), offering.getUuid()); - offering.setState(DiskOffering.State.Inactive); - if (_diskOfferingDao.update(offering.getId(), offering)) { + List volumesUsingOffering = _volumeDao.findByDiskOfferingId(diskOfferingId); + if (!volumesUsingOffering.isEmpty()) { + throw new InvalidParameterValueException(String.format("Unable to delete disk offering: %s [%s] because there are volumes using it", offering.getUuid(), offering.getName())); + } + if (_diskOfferingDao.remove(offering.getId())) { CallContext.current().setEventDetails("Disk offering id=" + diskOfferingId); return true; } else { @@ -4440,15 +4444,17 @@ public boolean deleteServiceOffering(final DeleteServiceOfferingCmd cmd) { throw new InvalidParameterValueException(String.format("Unable to delete service offering: %s by user: %s because it is not root-admin or domain-admin", offering.getUuid(), user.getUuid())); } + List vmsUsingOffering = _vmInstanceDao.listByOfferingId(offeringId); + if (!vmsUsingOffering.isEmpty()) { + throw new CloudRuntimeException(String.format("Unable to delete service offering %s as it is in use", offering.getUuid())); + } annotationDao.removeByEntityType(AnnotationService.EntityType.SERVICE_OFFERING.name(), offering.getUuid()); if (diskOffering.isComputeOnly()) { - diskOffering.setState(DiskOffering.State.Inactive); - if (!_diskOfferingDao.update(diskOffering.getId(), diskOffering)) { + if (!_diskOfferingDao.remove(diskOffering.getId())) { throw new CloudRuntimeException(String.format("Unable to delete disk offering %s mapped to the service offering %s", diskOffering.getUuid(), offering.getUuid())); } } - offering.setState(ServiceOffering.State.Inactive); - if (_serviceOfferingDao.update(offeringId, offering)) { + if (_serviceOfferingDao.remove(offeringId)) { CallContext.current().setEventDetails("Service offering id=" + offeringId); return true; } else { diff --git a/test/integration/component/test_acl_listvolume.py b/test/integration/component/test_acl_listvolume.py index 826563665bef..04fa5131f876 100644 --- a/test/integration/component/test_acl_listvolume.py +++ b/test/integration/component/test_acl_listvolume.py @@ -227,6 +227,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d1) cls.vm_d1_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d1.id) cls.apiclient.connection.apiKey = cls.user_d1a_apikey @@ -238,6 +239,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d1a) cls.vm_d1a_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d1a.id) cls.apiclient.connection.apiKey = cls.user_d1b_apikey @@ -249,6 +251,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d1b) cls.vm_d1b_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d1b.id) cls.apiclient.connection.apiKey = cls.user_d11_apikey @@ -260,6 +263,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d11) cls.vm_d11_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d11.id) cls.apiclient.connection.apiKey = cls.user_d11a_apikey @@ -271,6 +275,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d11a) cls.vm_d11a_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d11a.id) cls.apiclient.connection.apiKey = cls.user_d11b_apikey @@ -282,6 +287,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d11b) cls.vm_d11b_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d11b.id) cls.apiclient.connection.apiKey = cls.user_d111a_apikey @@ -293,6 +299,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d111a) cls.vm_d111a_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d111a.id) cls.apiclient.connection.apiKey = cls.user_d12a_apikey @@ -304,6 +311,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d12a) cls.vm_d12a_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d12a.id) cls.apiclient.connection.apiKey = cls.user_d12b_apikey @@ -315,6 +323,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d12b) cls.vm_d12b_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d12b.id) cls.apiclient.connection.apiKey = cls.user_d2a_apikey @@ -326,6 +335,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_d2) cls.vm_d2_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_d2.id) cls.apiclient.connection.apiKey = cls.user_a_apikey @@ -337,6 +347,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, templateid=cls.template.id ) + cls.cleanup.append(cls.vm_a) cls.vm_a_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_a.id) cls.cleanup = [ diff --git a/test/integration/component/test_cpu_max_limits.py b/test/integration/component/test_cpu_max_limits.py index 16341e5d2a73..65e76affe5f8 100644 --- a/test/integration/component/test_cpu_max_limits.py +++ b/test/integration/component/test_cpu_max_limits.py @@ -106,6 +106,7 @@ def createInstance(self, service_off, account=None, projectid=project.id, networkids=networks, serviceofferingid=service_off.id) + self.cleanup.append(vm) vms = VirtualMachine.list(api_client, id=vm.id, listall=True) self.assertIsInstance(vms, list, @@ -229,7 +230,6 @@ def test_02_deploy_vm_account_limit_reached(self): self.apiclient, self.testdata["service_offering_multiple_cores"] ) - # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") @@ -242,7 +242,7 @@ def test_02_deploy_vm_account_limit_reached(self): self.debug("Deploying instance with account: %s" % self.child_do_admin.name) - self.createInstance(account=self.child_do_admin, + self.vm1 = self.createInstance(account=self.child_do_admin, service_off=self.service_offering, api_client=api_client_admin) self.debug("Deploying instance when CPU limit is reached in account") @@ -305,7 +305,6 @@ def test_04_deployVm__account_limit_reached(self): self.apiclient, self.testdata["service_offering_multiple_cores"] ) - # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") @@ -317,9 +316,9 @@ def test_04_deployVm__account_limit_reached(self): self.debug("Deploying instance with account: %s" % self.child_do_admin.name) - self.createInstance(account=self.child_do_admin, + self.vm2 = self.createInstance(account=self.child_do_admin, service_off=self.service_offering, api_client=api_client_admin) - + # Adding to cleanup list after execution self.debug("Deploying instance in project when CPU limit is reached in account") with self.assertRaises(Exception): diff --git a/test/integration/component/test_network_offering.py b/test/integration/component/test_network_offering.py index 1fb24ca68bd1..defd36f2cfa4 100644 --- a/test/integration/component/test_network_offering.py +++ b/test/integration/component/test_network_offering.py @@ -1388,19 +1388,17 @@ def setUpClass(cls): cls.services["service_offering"] ) - cls.cleanup = [ + cls._cleanup = [ cls.service_offering, ] return @classmethod def tearDownClass(cls): - try: - #Cleanup resources used - cleanup_resources(cls.apiclient, cls.cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestNOWithOnlySourceNAT, cls).tearDownClass() + + def tearDown(self): + super(TestNOWithOnlySourceNAT, self).tearDown() @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_create_network_with_snat(self): @@ -1446,10 +1444,11 @@ def test_create_network_with_snat(self): zoneid=self.zone.id ) self.debug("Created guest network with ID: %s within account %s" % (self.network.id, self.account.name)) + self.cleanup.append(self.network) self.debug("Deploying VM in account: %s on the network %s" % (self.account.name, self.network.id)) # Spawn an instance in that network - VirtualMachine.create( + self.vm1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], accountid=self.account.name, @@ -1457,6 +1456,8 @@ def test_create_network_with_snat(self): serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) + self.cleanup.append(self.vm1) + self.debug("Deployed VM in network: %s" % self.network.id) src_nat_list = PublicIPAddress.list( diff --git a/test/integration/component/test_stopped_vm.py b/test/integration/component/test_stopped_vm.py index b7fe4b04b043..9422bb7bf09d 100644 --- a/test/integration/component/test_stopped_vm.py +++ b/test/integration/component/test_stopped_vm.py @@ -1444,7 +1444,7 @@ def test_vm_per_account(self): serviceofferingid=self.service_offering.id, startvm=False ) - + self.cleanup.append(virtual_machine) # Verify VM state self.assertEqual( virtual_machine.state, diff --git a/test/integration/component/test_vpc.py b/test/integration/component/test_vpc.py index 5870769be0c7..6d552f3761d2 100644 --- a/test/integration/component/test_vpc.py +++ b/test/integration/component/test_vpc.py @@ -947,7 +947,7 @@ def test_07_restart_network_vm_running(self): networkids=[str(network_1.id)] ) self.debug("Deployed VM in network: %s" % network_1.id) - + self.cleanup.append(vm_1) vm_2 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], @@ -956,6 +956,7 @@ def test_07_restart_network_vm_running(self): serviceofferingid=self.service_offering.id, networkids=[str(network_1.id)] ) + self.cleanup.append(vm_2) self.debug("Deployed VM in network: %s" % network_1.id) self.debug("deploying VMs in network: %s" % network_2.name) @@ -968,6 +969,7 @@ def test_07_restart_network_vm_running(self): serviceofferingid=self.service_offering.id, networkids=[str(network_2.id)] ) + self.cleanup.append(vm_3) self.debug("Deployed VM in network: %s" % network_2.id) vm_4 = VirtualMachine.create( @@ -978,6 +980,7 @@ def test_07_restart_network_vm_running(self): serviceofferingid=self.service_offering.id, networkids=[str(network_2.id)] ) + self.cleanup.append(vm_4) self.debug("Deployed VM in network: %s" % network_2.id) self.debug("Associating public IP for network: %s" % network_1.name) @@ -1293,6 +1296,7 @@ def test_08_delete_vpc(self): networkids=[str(network_1.id)] ) self.debug("Deployed VM in network: %s" % network_1.id) + self.cleanup.append(vm_1) vm_2 = VirtualMachine.create( self.apiclient, @@ -1303,6 +1307,7 @@ def test_08_delete_vpc(self): networkids=[str(network_1.id)] ) self.debug("Deployed VM in network: %s" % network_1.id) + self.cleanup.append(vm_2) self.debug("deploying VMs in network: %s" % network_2.name) # Spawn an instance in that network @@ -1315,6 +1320,7 @@ def test_08_delete_vpc(self): networkids=[str(network_2.id)] ) self.debug("Deployed VM in network: %s" % network_2.id) + self.cleanup.append(vm_3) vm_4 = VirtualMachine.create( self.apiclient, @@ -1325,6 +1331,7 @@ def test_08_delete_vpc(self): networkids=[str(network_2.id)] ) self.debug("Deployed VM in network: %s" % network_2.id) + self.cleanup.append(vm_4) self.debug("Associating public IP for network: %s" % network_1.name) public_ip_1 = PublicIPAddress.create( @@ -1738,7 +1745,7 @@ def test_11_deploy_vm_wo_network_netdomain(self): networkids=[str(network.id)] ) self.debug("Deployed VM in network: %s" % network.id) - + self.cleanup.append(virtual_machine) self.validate_vm_netdomain( virtual_machine, vpc, @@ -1945,7 +1952,7 @@ def test_13_deploy_vm_with_vpc_netdomain(self): networkids=[str(network.id)] ) self.debug("Deployed VM in network: %s" % network.id) - + self.cleanup.append(virtual_machine) self.validate_vm_netdomain(virtual_machine, vpc, network, netdomain) @attr(tags=["advanced", "intervlan"], required_hardware="false") @@ -2017,7 +2024,7 @@ def test_14_deploy_vm_1(self): networkids=[str(network.id)] ) self.debug("Deployed VM in network: %s" % network.id) - + self.cleanup.append(virtual_machine) self.assertNotEqual(virtual_machine, None, "VM creation in the network failed") @@ -2094,7 +2101,7 @@ def test_15_deploy_vm_2(self): networkids=[str(network.id)] ) self.debug("Deployed VM in network: %s" % network.id) - + self.cleanup.append(virtual_machine) self.assertNotEqual(virtual_machine, None, "VM creation in the network failed") @@ -2173,7 +2180,7 @@ def test_16_deploy_vm_for_user_by_admin(self): networkids=[str(network.id)] ) self.debug("Deployed VM in network: %s" % network.id) - + self.cleanup.append(virtual_machine) self.assertNotEqual(virtual_machine, None, "VM creation in the network failed") @@ -2494,6 +2501,7 @@ def test_21_deploy_vm_with_gateway_ip(self): networkids=[str(network.id)] ) self.debug("Deployed VM in network: %s" % network.id) + self.cleanup.append(vm) self.assertIsNotNone( vm, "Failed to create VM with first ip address in the CIDR as the vm ip" diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py index 26271f69e3fd..98cc5404d760 100644 --- a/test/integration/smoke/test_affinity_groups.py +++ b/test/integration/smoke/test_affinity_groups.py @@ -88,6 +88,10 @@ def setUpClass(cls): ] return + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.cleanup = [] + @attr(tags=["basic", "advanced", "multihost"], required_hardware="false") def test_DeployVmAntiAffinityGroup(self): """ @@ -106,6 +110,7 @@ def test_DeployVmAntiAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.ag.name] ) + self.cleanup.append(vm1) list_vm1 = list_virtual_machines( self.apiclient, @@ -139,6 +144,8 @@ def test_DeployVmAntiAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.ag.name] ) + self.cleanup.append(vm2) + list_vm2 = list_virtual_machines( self.apiclient, id=vm2.id @@ -182,6 +189,7 @@ def test_DeployVmAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.affinity.name] ) + self.cleanup.append(vm1) list_vm1 = list_virtual_machines( self.apiclient, @@ -215,6 +223,8 @@ def test_DeployVmAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.affinity.name] ) + self.cleanup.append(vm2) + list_vm2 = list_virtual_machines( self.apiclient, id=vm2.id @@ -240,6 +250,10 @@ def test_DeployVmAffinityGroup(self): self.assertEqual(host_of_vm1, host_of_vm2, msg="Both VMs of affinity group %s are on different hosts" % self.affinity.name) + + def tearDown(self): + super(TestDeployVmWithAffinityGroup, self).tearDown() + @classmethod def tearDownClass(cls): try: diff --git a/test/integration/smoke/test_backup_recovery_dummy.py b/test/integration/smoke/test_backup_recovery_dummy.py index b4789bd0f249..1554d078b0ee 100644 --- a/test/integration/smoke/test_backup_recovery_dummy.py +++ b/test/integration/smoke/test_backup_recovery_dummy.py @@ -58,11 +58,13 @@ def setUpClass(cls): return cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id) + cls._cleanup.append(cls.account) cls.offering = ServiceOffering.create(cls.api_client,cls.services["service_offerings"]["small"]) + cls._cleanup.append(cls.offering) cls.vm = VirtualMachine.create(cls.api_client, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.offering.id, mode=cls.services["mode"]) - cls._cleanup = [cls.offering, cls.account] + cls._cleanup.append(cls.vm) # Import a dummy backup offering to use on tests @@ -75,9 +77,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): try: - # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) - + super(TestDummyBackupAndRecovery, cls).tearDownClass() # Restore original backup framework values values if cls.backup_enabled == "false": Configurations.update(cls.api_client, 'backup.framework.enabled', value=cls.backup_enabled, zoneid=cls.zone.id) diff --git a/test/integration/smoke/test_console_endpoint.py b/test/integration/smoke/test_console_endpoint.py index 84b893e57012..c482e2093512 100644 --- a/test/integration/smoke/test_console_endpoint.py +++ b/test/integration/smoke/test_console_endpoint.py @@ -35,6 +35,7 @@ def setUpClass(cls): # Get Zone, Domain and templates cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.hypervisor = cls.testClient.getHypervisorInfo() + cls._cleanup = [] cls.template = get_template( cls.apiclient, @@ -55,10 +56,12 @@ def setUpClass(cls): 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.vm1 = VirtualMachine.create( cls.apiclient, cls.services["virtual_machine"], @@ -67,20 +70,13 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.vm1) - cls._cleanup = [ - cls.service_offering, - cls.vm1, - cls.account - ] return @classmethod def tearDownClass(cls): - try: - cleanup_resources(cls.apiclient, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) + super(TestConsoleEndpoint, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() diff --git a/test/integration/smoke/test_deploy_virtio_scsi_vm.py b/test/integration/smoke/test_deploy_virtio_scsi_vm.py index 4540d16fea58..8f123e26050f 100644 --- a/test/integration/smoke/test_deploy_virtio_scsi_vm.py +++ b/test/integration/smoke/test_deploy_virtio_scsi_vm.py @@ -143,6 +143,7 @@ def setUpClass(cls): diskofferingid=cls.sparse_disk_offering.id, mode=cls.zone.networktype ) + cls._cleanup.append(cls.virtual_machine) hosts = Host.list(cls.apiclient, id=cls.virtual_machine.hostid) if len(hosts) != 1: @@ -159,7 +160,6 @@ def setUpClass(cls): # Start VM after password reset cls.virtual_machine.start(cls.apiclient) - cls._cleanup.append(cls.virtual_machine) @classmethod diff --git a/test/integration/smoke/test_direct_download.py b/test/integration/smoke/test_direct_download.py index 6570bb9f0b3c..100ce177f170 100644 --- a/test/integration/smoke/test_direct_download.py +++ b/test/integration/smoke/test_direct_download.py @@ -303,6 +303,7 @@ def test_01_deploy_vm_from_direct_download_template_nfs_storage(self): test_tag = "marvin_test_nfs_storage_direct_download" self.updateStoragePoolTags(self.nfsPoolId, test_tag) nfs_storage_offering = self.createServiceOffering("TestNFSStorageDirectDownload", "shared", test_tag) + self.cleanup.append(nfs_storage_offering) vm = self.deployVM(nfs_storage_offering) self.assertEqual( @@ -313,7 +314,6 @@ def test_01_deploy_vm_from_direct_download_template_nfs_storage(self): # Revert storage tags for the storage pool used in this test self.updateStoragePoolTags(self.nfsPoolId, tags) - self.cleanup.append(nfs_storage_offering) return @skipTestIf("localStorageKvmNotAvailable") diff --git a/test/integration/smoke/test_kubernetes_clusters.py b/test/integration/smoke/test_kubernetes_clusters.py index 20f1cb3224ae..2eab13646b4d 100644 --- a/test/integration/smoke/test_kubernetes_clusters.py +++ b/test/integration/smoke/test_kubernetes_clusters.py @@ -629,6 +629,7 @@ def test_11_test_unmanaged_cluster_lifecycle(self): virtualMachine = VirtualMachine.create(self.apiclient, self.services["virtual_machine"], zoneid=self.zone.id, accountid=self.account.name, domainid=self.account.domainid, serviceofferingid=self.cks_service_offering.id) + self.cleanup.append(virtualMachine) self.debug("Adding VM %s to unmanaged Kubernetes cluster with ID: %s" % (virtualMachine.id, cluster.id)) self.addVirtualMachinesToKubernetesCluster(cluster.id, [virtualMachine.id]) cluster = self.listKubernetesCluster(cluster.id) diff --git a/test/integration/smoke/test_primary_storage.py b/test/integration/smoke/test_primary_storage.py index 477d3317ad69..93c5b1e64a72 100644 --- a/test/integration/smoke/test_primary_storage.py +++ b/test/integration/smoke/test_primary_storage.py @@ -60,13 +60,7 @@ def setUp(self): 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 + super(TestPrimaryStorageServices, self).tearDown() @attr(tags=["advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false") def test_01_primary_storage_nfs(self): @@ -319,6 +313,7 @@ def test_01_add_primary_storage_disabled_host(self): self.services["account"], domainid=self.domain.id ) + self.cleanup.append(account) service_offering = ServiceOffering.create( self.apiclient, @@ -336,7 +331,6 @@ def test_01_add_primary_storage_disabled_host(self): serviceofferingid=service_offering.id ) self.cleanup.append(self.virtual_machine) - self.cleanup.append(account) finally: # cancel maintenance for pool in storage_pool_list: diff --git a/test/integration/smoke/test_reset_vm_on_reboot.py b/test/integration/smoke/test_reset_vm_on_reboot.py index 01faf37d94af..05ba4a9bcb56 100644 --- a/test/integration/smoke/test_reset_vm_on_reboot.py +++ b/test/integration/smoke/test_reset_vm_on_reboot.py @@ -52,19 +52,21 @@ def setUpClass(cls): # Set Zones and disk offerings ?? cls.services["small"]["zoneid"] = zone.id cls.services["small"]["template"] = template.id - + cls._cleanup = [] # Create account, service offerings, vm. cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=domain.id ) + cls._cleanup.append(cls.account) cls.small_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"], isvolatile="true" ) + cls._cleanup.append(cls.small_offering) #create a virtual machine cls.virtual_machine = VirtualMachine.create( @@ -75,16 +77,11 @@ def setUpClass(cls): serviceofferingid=cls.small_offering.id, mode=cls.services["mode"] ) - cls._cleanup = [ - cls.small_offering, - cls.account - ] + cls._cleanup.append(cls.virtual_machine) @classmethod def tearDownClass(cls): - cls.apiclient = super(TestResetVmOnReboot, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.apiclient, cls._cleanup) - return + super(TestResetVmOnReboot, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() diff --git a/test/integration/smoke/test_resource_accounting.py b/test/integration/smoke/test_resource_accounting.py index 043a7af86dfd..4f2012acd571 100644 --- a/test/integration/smoke/test_resource_accounting.py +++ b/test/integration/smoke/test_resource_accounting.py @@ -167,11 +167,7 @@ def setUp(self): self.cleanup = [] def tearDown(self): - try: - # Clean up, terminate the created accounts - cleanup_resources(self.apiclient, self.cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) + super(TestRAMCPUResourceAccounting, self).tearDown() def get_resource_amount(self, resource_type): cmd = updateResourceCount.updateResourceCountCmd() @@ -190,7 +186,6 @@ def test_01_so_removal_resource_update(self): self.services["service_offering_it_1"], domainid=self.domain.id ) - self.cleanup.append(self.service_offering_it_1) self.service_offering_it_2 = ServiceOffering.create( @@ -198,7 +193,6 @@ def test_01_so_removal_resource_update(self): self.services["service_offering_it_2"], domainid=self.domain.id ) - self.cleanup.append(self.service_offering_it_2) vm_1 = VirtualMachine.create( @@ -232,10 +226,6 @@ def test_01_so_removal_resource_update(self): self.assertEqual(cores, self.services['service_offering_it_1']['cpunumber'] + self.services['service_offering_it_2']['cpunumber']) self.assertEqual(ram, self.services['service_offering_it_1']['memory'] + self.services['service_offering_it_2']['memory']) - self.service_offering_it_2.delete(self.apiclient) - - self.cleanup = self.cleanup[0:-1] - cores = int(self.get_resource_amount(CPU_RESOURCE_ID)) ram = int(self.get_resource_amount(RAM_RESOURCE_ID)) diff --git a/test/integration/smoke/test_resource_names.py b/test/integration/smoke/test_resource_names.py index 46fa445f1b1f..9391814457ab 100644 --- a/test/integration/smoke/test_resource_names.py +++ b/test/integration/smoke/test_resource_names.py @@ -101,6 +101,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services['mode'] ) + cls._cleanup.append(cls.virtual_machine) @classmethod def tearDownClass(cls): @@ -178,7 +179,6 @@ def test_02_create_volume(self): domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) - # self.cleanup.append(self.volume) self.virtual_machine.attach_volume(self.apiclient, self.volume) list_volume_response = Volume.list( self.apiclient, diff --git a/test/integration/smoke/test_scale_vm.py b/test/integration/smoke/test_scale_vm.py index c2ae85df3b2d..eed3531cf54b 100644 --- a/test/integration/smoke/test_scale_vm.py +++ b/test/integration/smoke/test_scale_vm.py @@ -549,6 +549,7 @@ def test_04_scale_vm_with_user_account(self): serviceofferingid=self.small_offering.id, mode=self.services["mode"] ) + self.cleanup.append(self.virtual_machine_in_user_account) if self.hypervisor.lower() == "vmware": sshClient = self.virtual_machine_in_user_account.get_ssh_client() @@ -599,7 +600,6 @@ def test_04_scale_vm_with_user_account(self): self.cleanup.append(self.bigger_offering) else: self.bigger_offering = self.big_offering - self.debug("Scaling VM-ID: %s to service offering: %s and state %s" % ( self.virtual_machine_in_user_account.id, self.bigger_offering.id, @@ -694,7 +694,7 @@ def test_05_scale_vm_dont_allow_disk_offering_change(self): serviceofferingid=self.ServiceOffering1WithDiskOffering1.id, mode=self.services["mode"] ) - + self._cleanup.append(self.virtual_machine_test) if self.hypervisor.lower() == "vmware": sshClient = self.virtual_machine_test.get_ssh_client() result = str( diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index c6a14a64471d..69ec3ab6e951 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -365,21 +365,16 @@ def setUp(self): self.cleanup = [] 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 + super(TestServiceOfferings, self).tearDown() @classmethod def setUpClass(cls): + cls._cleanup = [] testClient = super(TestServiceOfferings, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = testClient.getParsedTestDataConfig() cls.hypervisor = testClient.getHypervisorInfo() + cls._cleanup = [] domain = get_domain(cls.apiclient) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) @@ -389,10 +384,12 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) + cls._cleanup.append(cls.service_offering_1) cls.service_offering_2 = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"] ) + cls._cleanup.append(cls.service_offering_2) cls.template = get_test_template( cls.apiclient, cls.zone.id, @@ -412,16 +409,20 @@ def setUpClass(cls): cls.services["account"], domainid=domain.id ) + cls._cleanup.append(cls.account) cls.small_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["small"] ) + cls._cleanup.append(cls.small_offering) cls.medium_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["medium"] ) + cls._cleanup.append(cls.medium_offering) + cls.medium_virtual_machine = VirtualMachine.create( cls.apiclient, cls.services["small"], @@ -430,25 +431,12 @@ def setUpClass(cls): serviceofferingid=cls.medium_offering.id, mode=cls.services["mode"] ) - cls._cleanup = [ - cls.small_offering, - cls.medium_offering, - cls.account - ] + cls._cleanup.append(cls.medium_virtual_machine) return @classmethod def tearDownClass(cls): - try: - cls.apiclient = super( - TestServiceOfferings, - 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(TestServiceOfferings, cls).tearDownClass() @attr( tags=[ @@ -793,7 +781,19 @@ def test_06_disk_offering_strictness_false(self): self.apiclient, offering_data, ) - self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse) + self.cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse) + + self.disk_offering2 = DiskOffering.create( + self.apiclient, + self.services["disk_offering"], + ) + self.cleanup.append(self.disk_offering2) + + self.serviceOfferingWithDiskOfferingStrictnessFalse2 = ServiceOffering.create( + self.apiclient, + offering_data, + ) + self.cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse2) self.virtual_machine_with_diskoffering_strictness_false = VirtualMachine.create( self.apiclient, @@ -803,6 +803,7 @@ def test_06_disk_offering_strictness_false(self): serviceofferingid=self.serviceOfferingWithDiskOfferingStrictnessFalse.id, mode=self.services["mode"] ) + self.cleanup.append(self.virtual_machine_with_diskoffering_strictness_false) try: self.virtual_machine_with_diskoffering_strictness_false.stop(self.apiclient) @@ -832,11 +833,6 @@ def test_06_disk_offering_strictness_false(self): except Exception as e: self.fail("Failed to stop VM: %s" % e) - self.disk_offering2 = DiskOffering.create( - self.apiclient, - self.services["disk_offering"], - ) - self._cleanup.append(self.disk_offering2) offering_data = { 'displaytext': 'TestDiskOfferingStrictnessFalse2', 'cpuspeed': 1000, @@ -847,11 +843,6 @@ def test_06_disk_offering_strictness_false(self): 'diskofferingid': self.disk_offering2.id } - self.serviceOfferingWithDiskOfferingStrictnessFalse2 = ServiceOffering.create( - self.apiclient, - offering_data, - ) - self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse2) cmd = scaleVirtualMachine.scaleVirtualMachineCmd() cmd.id = self.virtual_machine_with_diskoffering_strictness_false.id cmd.serviceofferingid = self.serviceOfferingWithDiskOfferingStrictnessFalse2.id @@ -967,12 +958,14 @@ def setUpClass(cls): cls.services["small"]["template"] = template.id cls.services["small"]["hypervisor"] = cls.hypervisor cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ + cls._cleanup = [] cls.account = Account.create( cls.apiclient, cls.services["account"], domainid=domain.id ) + cls._cleanup.append(cls.account) offering_data = { 'displaytext': 'TestOffering', @@ -987,6 +980,7 @@ def setUpClass(cls): offering_data, limitcpuuse=True ) + cls._cleanup.append(cls.offering) def getHost(self, hostId=None): response = list_hosts( @@ -1013,23 +1007,11 @@ def getHost(self, hostId=None): hostid=cls.host.id ) - cls._cleanup = [ - cls.offering, - cls.account - ] + cls._cleanup.append(cls.vm) @classmethod def tearDownClass(cls): - try: - cls.apiclient = super( - TestCpuCapServiceOfferings, - 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(TestCpuCapServiceOfferings, cls).tearDownClass() @skipTestIf("hypervisorNotSupported") @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") diff --git a/test/integration/smoke/test_snapshots.py b/test/integration/smoke/test_snapshots.py index f8346093c641..db9a6fe03460 100644 --- a/test/integration/smoke/test_snapshots.py +++ b/test/integration/smoke/test_snapshots.py @@ -119,12 +119,7 @@ def setUp(self): 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(TestSnapshotRootDisk, self).tearDown() @skipTestIf("hypervisorNotSupported") @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") @@ -226,39 +221,6 @@ def test_02_list_snapshots_with_removed_data_store(self): # 5 - Take volume V snapshot -> S # 6 - List snapshot and verify it gets properly listed although Primary Storage was removed - # Create new volume - vol = Volume.create( - self.apiclient, - self.services["volume"], - diskofferingid=self.disk_offering.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - ) - self.cleanup.append(vol) - self.assertIsNotNone(vol, "Failed to create volume") - vol_res = Volume.list( - self.apiclient, - id=vol.id - ) - self.assertEqual( - validateList(vol_res)[0], - PASS, - "Invalid response returned for list volumes") - vol_uuid = vol_res[0].id - clusters = list_clusters( - self.apiclient, - zoneid=self.zone.id - ) - assert isinstance(clusters,list) and len(clusters)>0 - - # Attach created volume to vm, then detach it to be able to migrate it - self.virtual_machine_with_disk.stop(self.apiclient) - self.virtual_machine_with_disk.attach_volume( - self.apiclient, - vol - ) - # Create new Primary Storage storage = StoragePool.create(self.apiclient, self.services["nfs2"], @@ -302,6 +264,39 @@ def test_02_list_snapshots_with_removed_data_store(self): "Check storage pool type " ) + # Create new volume + vol = Volume.create( + self.apiclient, + self.services["volume"], + diskofferingid=self.disk_offering.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + ) + self.cleanup.append(vol) + self.assertIsNotNone(vol, "Failed to create volume") + vol_res = Volume.list( + self.apiclient, + id=vol.id + ) + self.assertEqual( + validateList(vol_res)[0], + PASS, + "Invalid response returned for list volumes") + vol_uuid = vol_res[0].id + clusters = list_clusters( + self.apiclient, + zoneid=self.zone.id + ) + assert isinstance(clusters,list) and len(clusters)>0 + + # Attach created volume to vm, then detach it to be able to migrate it + self.virtual_machine_with_disk.stop(self.apiclient) + self.virtual_machine_with_disk.attach_volume( + self.apiclient, + vol + ) + self.virtual_machine_with_disk.detach_volume( self.apiclient, vol @@ -339,9 +334,6 @@ def test_02_list_snapshots_with_removed_data_store(self): self.debug("Snapshot created: ID - %s" % snapshot.id) - # Delete volume, VM and created Primary Storage - cleanup_resources(self.apiclient, self.cleanup) - # List snapshot and verify it gets properly listed although Primary Storage was removed snapshot_response = Snapshot.list( self.apiclient, @@ -359,10 +351,8 @@ def test_02_list_snapshots_with_removed_data_store(self): ) # Delete snapshot and verify it gets properly deleted (should not be listed) - self.cleanup = [snapshot] - cleanup_resources(self.apiclient, self.cleanup) + self.cleanup.append(snapshot) - self.cleanup = [] snapshot_response_2 = Snapshot.list( self.apiclient, id=snapshot.id diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index 2696db8f96b4..c5b007c4c9b2 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -255,13 +255,7 @@ def setUp(self): return def tearDown(self): - try: - #Clean up, terminate the created templates - cleanup_resources(self.apiclient, reversed(self.cleanup)) - - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestCreateTemplate, self).tearDown() @classmethod def setUpClass(cls): @@ -323,6 +317,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) + cls._cleanup.append(cls.virtual_machine) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) @@ -341,14 +336,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - try: - #Cleanup resources used - cleanup_resources(cls.apiclient, reversed(cls._cleanup)) - - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - - return + super(TestCreateTemplate, cls).tearDownClass() @attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="false") def test_CreateTemplateWithDuplicateName(self): @@ -485,6 +473,7 @@ def setUpClass(cls): cls.apiclient, cls.services["disk_offering"] ) + cls._cleanup.append(cls.disk_offering) template = get_template( cls.apiclient, cls.zone.id, @@ -508,15 +497,18 @@ def setUpClass(cls): admin=True, domainid=cls.domain.id ) + cls._cleanup.append(cls.account) cls.user = Account.create( cls.apiclient, cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.user) cls.service_offering = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"] ) + cls._cleanup.append(cls.service_offering) #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, @@ -527,6 +519,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) + cls._cleanup.append(cls.virtual_machine) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) @@ -559,24 +552,10 @@ def setUpClass(cls): account=cls.account.name, domainid=cls.account.domainid ) - cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - cls.account, - cls.user - ] @classmethod def tearDownClass(cls): - try: - cls.apiclient = super(TestTemplates, cls).getClsTestClient().getApiClient() - #Cleanup created resources such as templates and VMs - cleanup_resources(cls.apiclient, cls._cleanup) - - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - - return + super(TestTemplates, cls).tearDownClass() def setUp(self): @@ -1024,6 +1003,11 @@ def setUpClass(cls): cls.services["disk_offering"] ) cls._cleanup.append(cls.disk_offering) + cls.service_offering = ServiceOffering.create( + cls.apiclient, + cls.services["service_offerings"]["tiny"] + ) + cls._cleanup.append(cls.service_offering) cls.template = get_template( cls.apiclient, cls.zone.id, @@ -1046,11 +1030,7 @@ def setUpClass(cls): 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) + #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, @@ -1061,6 +1041,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) + cls._cleanup.append(cls.virtual_machine) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) @@ -1079,12 +1060,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - try: - #Cleanup resources used - cleanup_resources(cls.apiclient, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestCopyAndDeleteTemplatesAcrossZones, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -1097,12 +1073,7 @@ def setUp(self): 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 + super(TestCopyAndDeleteTemplatesAcrossZones, self).tearDown() @attr(tags=["advanced", "advancedns"], required_hardware="true") def test_09_copy_delete_template(self): diff --git a/test/integration/smoke/test_usage.py b/test/integration/smoke/test_usage.py index 2100859ba52f..71d4b32fb930 100644 --- a/test/integration/smoke/test_usage.py +++ b/test/integration/smoke/test_usage.py @@ -383,6 +383,7 @@ def setUpClass(cls): services=cls.services["server"] ) cls._cleanup = [ + cls.virtual_machine, cls.service_offering, cls.account, ] @@ -544,6 +545,7 @@ def setUpClass(cls): cls.services["service_offering"] ) cls._cleanup.append(cls.service_offering) + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["server"], @@ -552,16 +554,13 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.virtual_machine) + 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(TestVolumeUsage, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -853,6 +852,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) + cls._cleanup.append(cls.virtual_machine) # Stop virtual machine cls.virtual_machine.stop(cls.api_client) @@ -873,12 +873,7 @@ def setUpClass(cls): @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(TestTemplateUsage, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -1148,6 +1143,7 @@ def setUpClass(cls): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.hypervisor = cls.testClient.getHypervisorInfo() + cls._cleanup = [] template = get_suitable_test_template( cls.api_client, @@ -1167,13 +1163,14 @@ def setUpClass(cls): cls.services["account"], domainid=cls.domain.id ) - + cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( cls.api_client, cls.services["service_offering"] ) + cls._cleanup.append(cls.service_offering) cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["server"], @@ -1182,6 +1179,7 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.virtual_machine) cls.public_ip_1 = PublicIPAddress.create( cls.api_client, accountid=cls.virtual_machine.account, @@ -1189,20 +1187,11 @@ def setUpClass(cls): domainid=cls.virtual_machine.domainid, services=cls.services["server"] ) - cls._cleanup = [ - cls.service_offering, - cls.account, - ] 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(TestLBRuleUsage, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -1346,6 +1335,7 @@ def setUpClass(cls): cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name @@ -1353,6 +1343,7 @@ def setUpClass(cls): cls.api_client, cls.services["service_offering"] ) + cls._cleanup.append(cls.service_offering) cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["server"], @@ -1361,20 +1352,12 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) - cls._cleanup = [ - cls.service_offering, - cls.account, - ] + cls._cleanup.append(cls.virtual_machine) 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(TestSnapshotUsage, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -1513,6 +1496,7 @@ def setUpClass(cls): cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.hypervisor = cls.testClient.getHypervisorInfo() + cls._cleanup = [] template = get_suitable_test_template( cls.api_client, @@ -1532,6 +1516,7 @@ def setUpClass(cls): cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name @@ -1539,6 +1524,7 @@ def setUpClass(cls): cls.api_client, cls.services["service_offering"] ) + cls._cleanup.append(cls.service_offering) cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["server"], @@ -1547,6 +1533,7 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.virtual_machine) cls.public_ip_1 = PublicIPAddress.create( cls.api_client, accountid=cls.virtual_machine.account, @@ -1554,20 +1541,11 @@ def setUpClass(cls): domainid=cls.virtual_machine.domainid, services=cls.services["server"] ) - cls._cleanup = [ - cls.service_offering, - cls.account, - ] 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(TestNatRuleUsage, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -1717,6 +1695,7 @@ def setUpClass(cls): cls.services["service_offering"] ) cls._cleanup.append(cls.service_offering) + cls.virtual_machine = VirtualMachine.create( cls.api_client, cls.services["server"], @@ -1725,6 +1704,8 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.virtual_machine) + cls.public_ip = PublicIPAddress.create( cls.api_client, accountid=cls.virtual_machine.account, @@ -1736,12 +1717,7 @@ def setUpClass(cls): @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(TestVpnUsage, cls).tearDownClass() def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -1750,12 +1726,7 @@ def setUp(self): return def tearDown(self): - try: - # Clean up, terminate the created instance, VPN users - cleanup_resources(self.apiclient, self.cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestVpnUsage, self).tearDown() @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_01_vpn_usage(self): diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index c7c9a01bd32c..b521e428671d 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -119,6 +119,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services['mode'] ) + cls._cleanup.append(cls.virtual_machine) @classmethod def tearDownClass(cls): @@ -234,6 +235,7 @@ def test_deploy_vm_multiple(self): domainid=account.domainid, serviceofferingid=self.service_offering.id ) + self.cleanup.append(virtual_machine1) virtual_machine2 = VirtualMachine.create( self.apiclient, self.services["small"], @@ -241,6 +243,7 @@ def test_deploy_vm_multiple(self): domainid=account.domainid, serviceofferingid=self.service_offering.id ) + self.cleanup.append(virtual_machine2) list_vms = VirtualMachine.list(self.apiclient, ids=[virtual_machine1.id, virtual_machine2.id], listAll=True) self.debug( diff --git a/test/integration/smoke/test_vm_schedule.py b/test/integration/smoke/test_vm_schedule.py index ee1354ff80ee..3fb88c972089 100644 --- a/test/integration/smoke/test_vm_schedule.py +++ b/test/integration/smoke/test_vm_schedule.py @@ -122,6 +122,7 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, ) + cls._cleanup.append(cls.virtual_machine) return @classmethod diff --git a/test/integration/smoke/test_vm_snapshots.py b/test/integration/smoke/test_vm_snapshots.py index 07779e78c58c..5d54d4c5898c 100644 --- a/test/integration/smoke/test_vm_snapshots.py +++ b/test/integration/smoke/test_vm_snapshots.py @@ -285,7 +285,7 @@ def test_03_delete_vm_snapshots(self): self.assertEqual( list_snapshot_response, None, - "Check list vm snapshot has be deleted" + "Check list vm snapshot has to be deleted" ) class Utils: @@ -438,6 +438,7 @@ def test_change_service_offering_for_vm_with_snapshots(self): mode=self.zone.networktype, serviceofferingid=self.service_offering_1.id ) + self.cleanup.append(virtual_machine) # Verify Service OFfering 1 CPU cores and memory try: diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index 28a029adf70f..a159ec3afcc9 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -343,6 +343,7 @@ def setUpClass(cls): mode=cls.services["mode"] ) cls._cleanup.append(cls.virtual_machine) + pools = StoragePool.list(cls.apiclient) if cls.hypervisor.lower() == 'lxc' and cls.storage_pools.type.lower() != 'rbd': @@ -641,7 +642,6 @@ def test_08_resize_volume(self): self.apiclient, self.services["disk_offering"] ) - self.cleanup.append(disk_offering_20_GB) cmd = resizeVolume.resizeVolumeCmd() cmd.id = self.volume.id @@ -691,7 +691,6 @@ def test_08_resize_volume(self): self.apiclient, self.services["disk_offering"] ) - self.cleanup.append(disk_offering_10_GB) cmd = resizeVolume.resizeVolumeCmd() cmd.id = self.volume.id diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index 7336c038c897..b65e6219bcb6 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -80,6 +80,7 @@ "label.action.delete.backup.offering": "Delete backup offering", "label.action.delete.cluster": "Delete cluster", "label.action.delete.domain": "Delete domain", +"label.action.delete.disk.offering": "Delete disk offering", "label.action.delete.egress.firewall": "Delete egress firewall rule", "label.action.delete.firewall": "Delete firewall rule", "label.action.delete.interface.static.route": "Remove Tungsten Fabric interface static route", @@ -99,7 +100,9 @@ "label.action.delete.routing.firewall.rule": "Delete IPv4 Routing firewall rule", "label.action.delete.secondary.storage": "Delete secondary storage", "label.action.delete.security.group": "Delete security group", +"label.action.delete.service.offering": "Delete compute offering", "label.action.delete.snapshot": "Delete Snapshot", +"label.action.delete.system.service.offering": "Delete system offering", "label.action.delete.template": "Delete Template", "label.action.delete.tungsten.router.table": "Remove Tungsten Fabric route table from Network", "label.action.delete.user": "Delete User", @@ -2612,6 +2615,7 @@ "message.action.delete.backup.repository": "Please confirm that you want to delete this backup repository?", "message.action.delete.cluster": "Please confirm that you want to delete this cluster.", "message.action.delete.domain": "Please confirm that you want to delete this domain.", +"message.action.delete.disk.offering": "Please confirm that you want to delete this disk offering", "message.action.delete.external.firewall": "Please confirm that you would like to remove this external firewall. Warning: If you are planning to add back the same external firewall, you must reset usage data on the device.", "message.action.delete.external.load.balancer": "Please confirm that you would like to remove this external load balancer. Warning: If you are planning to add back the same external load balancer, you must reset usage data on the device.", "message.action.delete.ingress.rule": "Please confirm that you want to delete this ingress rule.", @@ -2630,7 +2634,9 @@ "message.action.delete.pod": "Please confirm that you want to delete this pod.", "message.action.delete.secondary.storage": "Please confirm that you want to delete this secondary storage.", "message.action.delete.security.group": "Please confirm that you want to delete this security group.", +"message.action.delete.service.offering": "Please confirm that you want to delete this compute offering", "message.action.delete.snapshot": "Please confirm that you want to delete this Snapshot.", +"message.action.delete.system.service.offering": "Please confirm that you want to delete this system service offering", "message.action.delete.template": "Please confirm that you want to delete this Template.", "message.action.delete.tungsten.router.table": "Please confirm that you want to remove Route Table from this Network?", "message.action.delete.volume": "Please confirm that you want to delete this volume. Note: this will not delete any Snapshots of this volume.", diff --git a/ui/src/config/section/offering.js b/ui/src/config/section/offering.js index e542f3d8df3c..70b0c2771ffe 100644 --- a/ui/src/config/section/offering.js +++ b/ui/src/config/section/offering.js @@ -31,9 +31,9 @@ export default { permission: ['listServiceOfferings'], searchFilters: ['name', 'zoneid', 'domainid', 'cpunumber', 'cpuspeed', 'memory'], params: () => { - var params = {} + var params = { state: 'all' } if (['Admin', 'DomainAdmin'].includes(store.getters.userInfo.roletype)) { - params = { isrecursive: 'true' } + params.isrecursive = true } return params }, @@ -121,16 +121,33 @@ export default { popup: true, show: (record) => { return record.state !== 'Active' }, groupMap: (selection) => { return selection.map(x => { return { id: x, state: 'Active' } }) } - }, { - api: 'deleteServiceOffering', + }, + { + api: 'updateServiceOffering', icon: 'pause-circle-outlined', label: 'label.action.disable.service.offering', message: 'message.action.disable.service.offering', - docHelp: 'adminguide/service_offerings.html#modifying-or-deleting-a-service-offering', dataView: true, + args: ['state'], + mapping: { + state: { + value: (record) => { return 'Inactive' } + } + }, groupAction: true, popup: true, show: (record) => { return record.state === 'Active' }, + groupMap: (selection) => { return selection.map(x => { return { id: x, state: 'Active' } }) } + }, + { + api: 'deleteServiceOffering', + icon: 'delete-outlined', + label: 'label.action.delete.service.offering', + message: 'message.action.delete.service.offering', + docHelp: 'adminguide/service_offerings.html#modifying-or-deleting-a-service-offering', + dataView: true, + groupAction: true, + popup: true, groupMap: (selection) => { return selection.map(x => { return { id: x } }) } }] }, @@ -141,7 +158,7 @@ export default { docHelp: 'adminguide/service_offerings.html#system-service-offerings', permission: ['listServiceOfferings', 'listInfrastructure'], searchFilters: ['name', 'zoneid', 'domainid', 'cpunumber', 'cpuspeed', 'memory'], - params: { issystem: 'true', isrecursive: 'true' }, + params: { issystem: 'true', isrecursive: 'true', state: 'all' }, columns: ['name', 'state', 'systemvmtype', 'cpunumber', 'cpuspeed', 'memory', 'storagetype', 'order'], filters: ['active', 'inactive'], details: ['name', 'id', 'displaytext', 'systemvmtype', 'provisioningtype', 'storagetype', 'iscustomized', 'limitcpuuse', 'cpunumber', 'cpuspeed', 'memory', 'storagetags', 'hosttags', 'tags', 'domain', 'zone', 'created', 'dynamicscalingenabled', 'diskofferingstrictness'], @@ -198,16 +215,33 @@ export default { show: (record) => { return record.state !== 'Active' }, groupMap: (selection) => { return selection.map(x => { return { id: x, state: 'Active' } }) } }, { - api: 'deleteServiceOffering', + api: 'updateServiceOffering', icon: 'pause-circle-outlined', label: 'label.action.disable.system.service.offering', message: 'message.action.disable.system.service.offering', - docHelp: 'adminguide/service_offerings.html#modifying-or-deleting-a-service-offering', dataView: true, params: { issystem: 'true' }, + args: ['state'], + mapping: { + state: { + value: (record) => { return 'Inactive' } + } + }, groupAction: true, popup: true, show: (record) => { return record.state === 'Active' }, + groupMap: (selection) => { return selection.map(x => { return { id: x, state: 'Active' } }) } + }, + { + api: 'deleteServiceOffering', + icon: 'delete-outlined', + label: 'label.action.delete.system.service.offering', + message: 'message.action.delete.system.service.offering', + docHelp: 'adminguide/service_offerings.html#modifying-or-deleting-a-service-offering', + dataView: true, + params: { issystem: 'true' }, + groupAction: true, + popup: true, groupMap: (selection) => { return selection.map(x => { return { id: x } }) } }] }, @@ -219,9 +253,9 @@ export default { permission: ['listDiskOfferings'], searchFilters: ['name', 'zoneid', 'domainid', 'storageid'], params: () => { - var params = {} + var params = { state: 'all' } if (['Admin', 'DomainAdmin'].includes(store.getters.userInfo.roletype)) { - params = { isrecursive: 'true' } + params.isrecursive = 'true' } return params }, @@ -301,15 +335,31 @@ export default { show: (record) => { return record.state !== 'Active' }, groupMap: (selection) => { return selection.map(x => { return { id: x, state: 'Active' } }) } }, { - api: 'deleteDiskOffering', + api: 'updateDiskOffering', icon: 'pause-circle-outlined', label: 'label.action.disable.disk.offering', message: 'message.action.disable.disk.offering', - docHelp: 'adminguide/service_offerings.html#modifying-or-deleting-a-service-offering', dataView: true, + params: { issystem: 'true' }, + args: ['state'], + mapping: { + state: { + value: (record) => { return 'Inactive' } + } + }, groupAction: true, popup: true, show: (record) => { return record.state === 'Active' }, + groupMap: (selection) => { return selection.map(x => { return { id: x, state: 'Active' } }) } + }, { + api: 'deleteDiskOffering', + icon: 'delete-outlined', + label: 'label.action.delete.disk.offering', + message: 'message.action.delete.disk.offering', + docHelp: 'adminguide/service_offerings.html#modifying-or-deleting-a-service-offering', + dataView: true, + groupAction: true, + popup: true, groupMap: (selection) => { return selection.map(x => { return { id: x } }) } }] },