From 6932fb08666cfed8a96c34cd2268407707d27bcb Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 19 Aug 2024 12:58:36 -0400 Subject: [PATCH 01/14] Add support for disabling serivce / system and disk offerings --- .../user/offering/ListDiskOfferingsCmd.java | 13 +--- .../offering/ListServiceOfferingsCmd.java | 12 +--- .../java/com/cloud/vm/dao/VMInstanceDao.java | 2 + .../com/cloud/vm/dao/VMInstanceDaoImpl.java | 12 ++++ .../com/cloud/api/query/QueryManagerImpl.java | 11 +-- .../ConfigurationManagerImpl.java | 18 +++-- tools/marvin/setup.py | 2 +- ui/public/locales/en.json | 1 + ui/src/config/section/offering.js | 68 ++++++++++++++++--- 9 files changed, 97 insertions(+), 42 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java index f9b9ec59a400..985407601695 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java @@ -16,8 +16,7 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import static com.cloud.offering.DiskOffering.State.Active; - +import com.cloud.offering.DiskOffering; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; @@ -29,7 +28,6 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.EnumUtils; -import org.apache.commons.lang3.StringUtils; import com.cloud.offering.DiskOffering.State; @@ -111,14 +109,7 @@ public String getStorageType() { } public State getState() { - if (StringUtils.isBlank(diskOfferingState)) { - return Active; - } - State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState); - if (!diskOfferingState.equalsIgnoreCase("all") && state == null) { - throw new IllegalArgumentException("Invalid state value: " + diskOfferingState); - } - return state; + return EnumUtils.getEnumIgnoreCase(DiskOffering.State.class, diskOfferingState); } public Long getVirtualMachineId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java index 1b3f531e370d..b7ea5ed06bcd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java @@ -16,8 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import static com.cloud.offering.ServiceOffering.State.Active; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; @@ -28,7 +26,6 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.EnumUtils; -import org.apache.commons.lang3.StringUtils; import com.cloud.offering.ServiceOffering.State; @@ -157,14 +154,7 @@ public String getStorageType() { } public State getState() { - if (StringUtils.isBlank(serviceOfferingState)) { - return Active; - } - State state = EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState); - if (!serviceOfferingState.equalsIgnoreCase("all") && state == null) { - throw new IllegalArgumentException("Invalid state value: " + serviceOfferingState); - } - return state; + return EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState); } public Long getTemplateId() { 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..ba3181a8c518 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,10 @@ 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("serviceOfferingId", ServiceOfferingSearch.entity().getServiceOfferingId(), Op.EQ); + BackupSearch.done(); } @Override @@ -1069,4 +1074,11 @@ 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("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 a39299d5091e..e4e0236edda1 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -3430,7 +3430,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 @@ -3547,6 +3547,8 @@ private Ternary, Integer, String[]> searchForDiskOfferingsIdsAndCount if (state != null) { sc.setParameters("state", state); + } else { + sc.setParameters("state", Arrays.asList(ServiceOffering.State.Active, ServiceOffering.State.Inactive)); } if (keyword != null) { @@ -3756,7 +3758,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) { @@ -3913,8 +3915,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) { @@ -4043,6 +4044,8 @@ private Pair, Integer> searchForServiceOfferingIdsAndCount(ListServic SearchCriteria sc = serviceOfferingSearch.create(); if (state != null) { sc.setParameters("state", state); + } else { + sc.setParameters("state", Arrays.asList(ServiceOffering.State.Active, ServiceOffering.State.Inactive)); } if (vmId != null) { diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index fce4b3496fc8..cee71266405c 100644 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -55,6 +55,7 @@ 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; @@ -4324,8 +4325,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 { @@ -4397,15 +4401,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/tools/marvin/setup.py b/tools/marvin/setup.py index 0618d84370a4..679b1d5920d8 100644 --- a/tools/marvin/setup.py +++ b/tools/marvin/setup.py @@ -27,7 +27,7 @@ raise RuntimeError("python setuptools is required to build Marvin") -VERSION = "4.20.0.0-SNAPSHOT" +VERSION = "4.20.0.0" setup(name="Marvin", version=VERSION, diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index b42899fc6313..b265fd95c0f1 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -93,6 +93,7 @@ "label.action.delete.primary.storage": "Delete primary storage", "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.template": "Delete Template", "label.action.delete.tungsten.router.table": "Remove Tungsten Fabric route table from Network", diff --git a/ui/src/config/section/offering.js b/ui/src/config/section/offering.js index 37973344f65a..309f0b2ee1ba 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 } }) } }] }, @@ -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 } }) } }] }, @@ -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 } }) } }] }, From cfe4c6aa5658da67f75f4d15fdba23a44e1ee4aa Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 20 Aug 2024 11:04:59 -0400 Subject: [PATCH 02/14] clean up virtual machines before cleaning up service offerings --- .../component/test_acl_listvolume.py | 13 +++++++++++- .../component/test_cpu_max_limits.py | 13 ++++++------ .../component/test_network_offering.py | 4 +++- test/integration/component/test_stopped_vm.py | 2 +- test/integration/component/test_vpc.py | 20 +++++++++++++------ .../integration/smoke/test_affinity_groups.py | 19 ++++++++++++++++++ .../smoke/test_backup_recovery_dummy.py | 2 +- .../smoke/test_console_endpoint.py | 2 +- .../integration/smoke/test_primary_storage.py | 5 +++-- .../smoke/test_reset_vm_on_reboot.py | 1 + .../smoke/test_resource_accounting.py | 6 ++---- test/integration/smoke/test_scale_vm.py | 6 +++--- .../smoke/test_service_offerings.py | 1 + test/integration/smoke/test_templates.py | 2 ++ test/integration/smoke/test_usage.py | 10 ++++++++-- test/integration/smoke/test_vm_life_cycle.py | 1 + test/integration/smoke/test_vm_schedule.py | 3 ++- 17 files changed, 81 insertions(+), 29 deletions(-) diff --git a/test/integration/component/test_acl_listvolume.py b/test/integration/component/test_acl_listvolume.py index 826563665bef..2d35f202e4b3 100644 --- a/test/integration/component/test_acl_listvolume.py +++ b/test/integration/component/test_acl_listvolume.py @@ -340,8 +340,19 @@ def setUpClass(cls): cls.vm_a_volume = Volume.list(cls.apiclient, virtualmachineid=cls.vm_a.id) cls.cleanup = [ + cls.vm_d1, + cls.vm_d1a, + cls.vm_d1b, + cls.vm_d11, + cls.vm_d11a, + cls.vm_d11b, + cls.vm_d111a, + cls.vm_d12a, + cls.vm_d12b, + cls.vm_d2, + cls.vm_a cls.account_a, - cls.service_offering, + cls.service_offering ] except Exception as e: cls.domain_2.delete(cls.apiclient, cleanup="true") diff --git a/test/integration/component/test_cpu_max_limits.py b/test/integration/component/test_cpu_max_limits.py index 16341e5d2a73..e1de2b4f952f 100644 --- a/test/integration/component/test_cpu_max_limits.py +++ b/test/integration/component/test_cpu_max_limits.py @@ -230,7 +230,6 @@ def test_02_deploy_vm_account_limit_reached(self): 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") self.setupAccounts(account_limit=6, domain_limit=8) @@ -242,8 +241,10 @@ 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.cleanup.append(self.vm1) + self.cleanup.append(self.service_offering) self.debug("Deploying instance when CPU limit is reached in account") @@ -305,8 +306,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") self.setupAccounts(account_limit=5, domain_limit=5, project_limit=5) @@ -317,9 +316,11 @@ 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.cleanup.append(self.vm2) + self.cleanup.append(self.service_offering) 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..aaa8c8ffed97 100644 --- a/test/integration/component/test_network_offering.py +++ b/test/integration/component/test_network_offering.py @@ -1449,7 +1449,7 @@ def test_create_network_with_snat(self): 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 +1457,8 @@ def test_create_network_with_snat(self): serviceofferingid=self.service_offering.id, networkids=[str(self.network.id)] ) + self.cleanup.append(self.vm1) + self.cleanup.append(self.network) 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..8e866b2d98cc 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): """ @@ -107,6 +111,8 @@ def test_DeployVmAntiAffinityGroup(self): affinitygroupnames=[self.ag.name] ) + self.cleanup.append(vm1) + list_vm1 = list_virtual_machines( self.apiclient, id=vm1.id @@ -139,6 +145,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 @@ -183,6 +191,7 @@ def test_DeployVmAffinityGroup(self): affinitygroupnames=[self.affinity.name] ) + self.cleanup.append(vm1) list_vm1 = list_virtual_machines( self.apiclient, id=vm1.id @@ -215,6 +224,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 +251,14 @@ 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): + 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) + @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..568d8d550bde 100644 --- a/test/integration/smoke/test_backup_recovery_dummy.py +++ b/test/integration/smoke/test_backup_recovery_dummy.py @@ -62,7 +62,7 @@ def setUpClass(cls): 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 = [cls.vm, cls.offering, cls.account] # Import a dummy backup offering to use on tests diff --git a/test/integration/smoke/test_console_endpoint.py b/test/integration/smoke/test_console_endpoint.py index 84b893e57012..17a93699f545 100644 --- a/test/integration/smoke/test_console_endpoint.py +++ b/test/integration/smoke/test_console_endpoint.py @@ -69,8 +69,8 @@ def setUpClass(cls): ) cls._cleanup = [ - cls.service_offering, cls.vm1, + cls.service_offering, cls.account ] return diff --git a/test/integration/smoke/test_primary_storage.py b/test/integration/smoke/test_primary_storage.py index 477d3317ad69..cbf10616e859 100644 --- a/test/integration/smoke/test_primary_storage.py +++ b/test/integration/smoke/test_primary_storage.py @@ -324,7 +324,6 @@ def test_01_add_primary_storage_disabled_host(self): self.apiclient, self.services["service_offerings"]["tiny"] ) - self.cleanup.append(service_offering) self.virtual_machine = VirtualMachine.create( self.apiclient, @@ -336,6 +335,7 @@ def test_01_add_primary_storage_disabled_host(self): serviceofferingid=service_offering.id ) self.cleanup.append(self.virtual_machine) + self.cleanup.append(service_offering) self.cleanup.append(account) finally: # cancel maintenance @@ -438,7 +438,6 @@ def setUpClass(cls): cls.services["service_offerings"]["tiny"], tags=cls.services["storage_tags"]["a"] ) - cls._cleanup.append(cls.service_offering_1) cls.service_offering_2 = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"], @@ -479,6 +478,8 @@ def setUpClass(cls): hypervisor=cls.hypervisor, mode=cls.zone.networktype ) + cls._cleanup.append(cls.virtual_machine_1) + cls._cleanup.append(cls.service_offering_1) # VM-1 not appended to _cleanup, it is expunged on tearDownClass before cleaning up resources return diff --git a/test/integration/smoke/test_reset_vm_on_reboot.py b/test/integration/smoke/test_reset_vm_on_reboot.py index 01faf37d94af..6ea84ad6b2b5 100644 --- a/test/integration/smoke/test_reset_vm_on_reboot.py +++ b/test/integration/smoke/test_reset_vm_on_reboot.py @@ -76,6 +76,7 @@ def setUpClass(cls): mode=cls.services["mode"] ) cls._cleanup = [ + cls.virtual_machine cls.small_offering, cls.account ] diff --git a/test/integration/smoke/test_resource_accounting.py b/test/integration/smoke/test_resource_accounting.py index 043a7af86dfd..e690fcc2ee63 100644 --- a/test/integration/smoke/test_resource_accounting.py +++ b/test/integration/smoke/test_resource_accounting.py @@ -191,16 +191,12 @@ def test_01_so_removal_resource_update(self): domainid=self.domain.id ) - self.cleanup.append(self.service_offering_it_1) - self.service_offering_it_2 = ServiceOffering.create( self.api_client, self.services["service_offering_it_2"], domainid=self.domain.id ) - self.cleanup.append(self.service_offering_it_2) - vm_1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine_1"], @@ -222,6 +218,8 @@ def test_01_so_removal_resource_update(self): self.debug("Deployed VM in account: %s, ID: %s" % (self.account.name, vm_2.id)) self.cleanup.append(vm_2) + self.cleanup.append(self.service_offering_it_1) + self.cleanup.append(self.service_offering_it_2) CPU_RESOURCE_ID = 8 RAM_RESOURCE_ID = 9 diff --git a/test/integration/smoke/test_scale_vm.py b/test/integration/smoke/test_scale_vm.py index c2ae85df3b2d..882a80785e06 100644 --- a/test/integration/smoke/test_scale_vm.py +++ b/test/integration/smoke/test_scale_vm.py @@ -211,7 +211,6 @@ def test_01_scale_vm(self): serviceofferingid=self.small_offering.id, mode=self.services["mode"] ) - self.cleanup.append(self.virtual_machine) # If hypervisor is Vmware, then check if # the vmware tools are installed and the process is running @@ -259,6 +258,7 @@ def test_01_scale_vm(self): offering_data ) self.cleanup.append(self.bigger_offering) + self.cleanup.append(self.virtual_machine) else: self.bigger_offering = self.big_offering @@ -599,7 +599,7 @@ def test_04_scale_vm_with_user_account(self): self.cleanup.append(self.bigger_offering) else: self.bigger_offering = self.big_offering - + self.cleanup.append(self.virtual_machine_in_user_account) 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..7be6e7fc4ae6 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -431,6 +431,7 @@ def setUpClass(cls): mode=cls.services["mode"] ) cls._cleanup = [ + cls.medium_virtual_machine, cls.small_offering, cls.medium_offering, cls.account diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index 2696db8f96b4..3d1016c4b161 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -323,6 +323,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) + cls._cleanup(cls.virtual_machine) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) @@ -560,6 +561,7 @@ def setUpClass(cls): domainid=cls.account.domainid ) cls._cleanup = [ + cls.virtual_machine, cls.service_offering, cls.disk_offering, cls.account, diff --git a/test/integration/smoke/test_usage.py b/test/integration/smoke/test_usage.py index 2100859ba52f..0d8da0e9d87f 100644 --- a/test/integration/smoke/test_usage.py +++ b/test/integration/smoke/test_usage.py @@ -543,7 +543,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"], @@ -552,6 +552,8 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.virtual_machine) + cls._cleanup.append(cls.service_offering) return @classmethod @@ -842,7 +844,6 @@ def setUpClass(cls): cls.api_client, cls.services["service_offering"] ) - cls._cleanup.append(cls.service_offering) # create virtual machine cls.virtual_machine = VirtualMachine.create( cls.api_client, @@ -853,6 +854,8 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) + cls._cleanup.append(cls.virtual_machine) + cls._cleanup.append(cls.service_offering) # Stop virtual machine cls.virtual_machine.stop(cls.api_client) @@ -1190,6 +1193,7 @@ def setUpClass(cls): services=cls.services["server"] ) cls._cleanup = [ + cls.virtual_machine, cls.service_offering, cls.account, ] @@ -1362,6 +1366,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id ) cls._cleanup = [ + cls.virtual_machine, cls.service_offering, cls.account, ] @@ -1555,6 +1560,7 @@ def setUpClass(cls): services=cls.services["server"] ) cls._cleanup = [ + cls.virtual_machine, cls.service_offering, cls.account, ] diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index aaffa63978ae..38de7384af8e 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -116,6 +116,7 @@ def setUpClass(cls): ) cls.cleanup = [ + cls.virtual_machine, cls.service_offering, cls.account ] diff --git a/test/integration/smoke/test_vm_schedule.py b/test/integration/smoke/test_vm_schedule.py index ee1354ff80ee..71828000c193 100644 --- a/test/integration/smoke/test_vm_schedule.py +++ b/test/integration/smoke/test_vm_schedule.py @@ -113,7 +113,6 @@ def setUpClass(cls): 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"], @@ -122,6 +121,8 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, ) + cls._cleanup.append(cls.virtual_machine) + cls._cleanup.append(cls.service_offering) return @classmethod From 6601b381626a9cd062a2d023e6375a668edd81d3 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 20 Aug 2024 16:34:49 -0400 Subject: [PATCH 03/14] update api to list only active states by default, for backward compatibility --- .../command/user/offering/ListDiskOfferingsCmd.java | 13 +++++++++++-- .../user/offering/ListServiceOfferingsCmd.java | 12 +++++++++++- .../java/com/cloud/vm/dao/VMInstanceDaoImpl.java | 2 +- .../java/com/cloud/api/query/QueryManagerImpl.java | 4 ---- ui/public/locales/en.json | 5 +++++ ui/src/config/section/offering.js | 6 +++--- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java index 985407601695..f9b9ec59a400 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java @@ -16,7 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import com.cloud.offering.DiskOffering; +import static com.cloud.offering.DiskOffering.State.Active; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; @@ -28,6 +29,7 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.EnumUtils; +import org.apache.commons.lang3.StringUtils; import com.cloud.offering.DiskOffering.State; @@ -109,7 +111,14 @@ public String getStorageType() { } public State getState() { - return EnumUtils.getEnumIgnoreCase(DiskOffering.State.class, diskOfferingState); + if (StringUtils.isBlank(diskOfferingState)) { + return Active; + } + State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState); + if (!diskOfferingState.equalsIgnoreCase("all") && state == null) { + throw new IllegalArgumentException("Invalid state value: " + diskOfferingState); + } + return state; } public Long getVirtualMachineId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java index b7ea5ed06bcd..1b3f531e370d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; +import static com.cloud.offering.ServiceOffering.State.Active; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; @@ -26,6 +28,7 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.EnumUtils; +import org.apache.commons.lang3.StringUtils; import com.cloud.offering.ServiceOffering.State; @@ -154,7 +157,14 @@ public String getStorageType() { } public State getState() { - return EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState); + if (StringUtils.isBlank(serviceOfferingState)) { + return Active; + } + State state = EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState); + if (!serviceOfferingState.equalsIgnoreCase("all") && state == null) { + throw new IllegalArgumentException("Invalid state value: " + serviceOfferingState); + } + return state; } public Long getTemplateId() { 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 ba3181a8c518..132502da4a19 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 @@ -329,7 +329,7 @@ protected void init() { ServiceOfferingSearch = createSearchBuilder(); ServiceOfferingSearch.and("serviceOfferingId", ServiceOfferingSearch.entity().getServiceOfferingId(), Op.EQ); - BackupSearch.done(); + ServiceOfferingSearch.done(); } @Override 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 e4e0236edda1..b1f05d34413f 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -3547,8 +3547,6 @@ private Ternary, Integer, String[]> searchForDiskOfferingsIdsAndCount if (state != null) { sc.setParameters("state", state); - } else { - sc.setParameters("state", Arrays.asList(ServiceOffering.State.Active, ServiceOffering.State.Inactive)); } if (keyword != null) { @@ -4044,8 +4042,6 @@ private Pair, Integer> searchForServiceOfferingIdsAndCount(ListServic SearchCriteria sc = serviceOfferingSearch.create(); if (state != null) { sc.setParameters("state", state); - } else { - sc.setParameters("state", Arrays.asList(ServiceOffering.State.Active, ServiceOffering.State.Inactive)); } if (vmId != null) { diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index c155974c1020..9dcf8e6dddc4 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -75,6 +75,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", @@ -95,6 +96,7 @@ "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", @@ -2538,6 +2540,7 @@ "message.action.delete.backup.offering": "Please confirm that you want to delete this backup offering?", "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.", @@ -2555,7 +2558,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 309f0b2ee1ba..9b35e9f6d699 100644 --- a/ui/src/config/section/offering.js +++ b/ui/src/config/section/offering.js @@ -158,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'], @@ -253,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 }, From 6ed1b605ad8d0c15321070453f24f6f98df47995 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Thu, 22 Aug 2024 12:03:45 -0400 Subject: [PATCH 04/14] fix tests and increase leniency --- .../com/cloud/vm/dao/VMInstanceDaoImpl.java | 2 ++ .../component/test_acl_listvolume.py | 24 +++++++++---------- .../component/test_cpu_max_limits.py | 5 ++-- .../smoke/test_deploy_virtio_scsi_vm.py | 3 ++- .../integration/smoke/test_direct_download.py | 1 + .../smoke/test_kubernetes_clusters.py | 1 + .../integration/smoke/test_primary_storage.py | 1 - .../smoke/test_reset_vm_on_reboot.py | 2 +- .../smoke/test_resource_accounting.py | 4 ---- test/integration/smoke/test_resource_names.py | 5 ++-- .../smoke/test_service_offerings.py | 5 ++-- test/integration/smoke/test_templates.py | 4 ++-- test/integration/smoke/test_usage.py | 4 +++- test/integration/smoke/test_vm_life_cycle.py | 2 ++ test/integration/smoke/test_volumes.py | 19 +++++++-------- 15 files changed, 43 insertions(+), 39 deletions(-) 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 132502da4a19..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 @@ -328,6 +328,7 @@ protected void init() { VmsNotInClusterUsingPool.done(); ServiceOfferingSearch = createSearchBuilder(); + ServiceOfferingSearch.and("states", ServiceOfferingSearch.entity().getState(), Op.IN); ServiceOfferingSearch.and("serviceOfferingId", ServiceOfferingSearch.entity().getServiceOfferingId(), Op.EQ); ServiceOfferingSearch.done(); } @@ -1078,6 +1079,7 @@ public Pair, Integer> listByVmsNotInClusterUsingPool(long clu @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/test/integration/component/test_acl_listvolume.py b/test/integration/component/test_acl_listvolume.py index 2d35f202e4b3..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,22 +347,12 @@ 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 = [ - cls.vm_d1, - cls.vm_d1a, - cls.vm_d1b, - cls.vm_d11, - cls.vm_d11a, - cls.vm_d11b, - cls.vm_d111a, - cls.vm_d12a, - cls.vm_d12b, - cls.vm_d2, - cls.vm_a cls.account_a, - cls.service_offering + cls.service_offering, ] except Exception as e: cls.domain_2.delete(cls.apiclient, cleanup="true") diff --git a/test/integration/component/test_cpu_max_limits.py b/test/integration/component/test_cpu_max_limits.py index e1de2b4f952f..1c594de5dc5e 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, @@ -243,7 +244,6 @@ def test_02_deploy_vm_account_limit_reached(self): self.vm1 = self.createInstance(account=self.child_do_admin, service_off=self.service_offering, api_client=api_client_admin) - self.cleanup.append(self.vm1) self.cleanup.append(self.service_offering) self.debug("Deploying instance when CPU limit is reached in account") @@ -318,8 +318,7 @@ def test_04_deployVm__account_limit_reached(self): self.child_do_admin.name) 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.cleanup.append(self.vm2) + # Adding to cleanup list after execution self.cleanup.append(self.service_offering) self.debug("Deploying instance in project when CPU limit is reached in account") diff --git a/test/integration/smoke/test_deploy_virtio_scsi_vm.py b/test/integration/smoke/test_deploy_virtio_scsi_vm.py index 4540d16fea58..4ac3ba220e73 100644 --- a/test/integration/smoke/test_deploy_virtio_scsi_vm.py +++ b/test/integration/smoke/test_deploy_virtio_scsi_vm.py @@ -124,7 +124,6 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["small"] ) - cls._cleanup.append(cls.service_offering) cls.sparse_disk_offering = DiskOffering.create( cls.apiclient, @@ -143,6 +142,8 @@ def setUpClass(cls): diskofferingid=cls.sparse_disk_offering.id, mode=cls.zone.networktype ) + cls._cleanup.append()cls.virtual_machine) + cls._cleanup.append(cls.service_offering) hosts = Host.list(cls.apiclient, id=cls.virtual_machine.hostid) if len(hosts) != 1: diff --git a/test/integration/smoke/test_direct_download.py b/test/integration/smoke/test_direct_download.py index 6570bb9f0b3c..9f9f52451316 100644 --- a/test/integration/smoke/test_direct_download.py +++ b/test/integration/smoke/test_direct_download.py @@ -305,6 +305,7 @@ def test_01_deploy_vm_from_direct_download_template_nfs_storage(self): nfs_storage_offering = self.createServiceOffering("TestNFSStorageDirectDownload", "shared", test_tag) vm = self.deployVM(nfs_storage_offering) + self.cleanup.append(vm) self.assertEqual( vm.state, "Running", 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 cbf10616e859..6a66c37cd0d6 100644 --- a/test/integration/smoke/test_primary_storage.py +++ b/test/integration/smoke/test_primary_storage.py @@ -478,7 +478,6 @@ def setUpClass(cls): hypervisor=cls.hypervisor, mode=cls.zone.networktype ) - cls._cleanup.append(cls.virtual_machine_1) cls._cleanup.append(cls.service_offering_1) # VM-1 not appended to _cleanup, it is expunged on tearDownClass before cleaning up resources diff --git a/test/integration/smoke/test_reset_vm_on_reboot.py b/test/integration/smoke/test_reset_vm_on_reboot.py index 6ea84ad6b2b5..5eb1203903f3 100644 --- a/test/integration/smoke/test_reset_vm_on_reboot.py +++ b/test/integration/smoke/test_reset_vm_on_reboot.py @@ -76,7 +76,7 @@ def setUpClass(cls): mode=cls.services["mode"] ) cls._cleanup = [ - cls.virtual_machine + cls.virtual_machine, cls.small_offering, cls.account ] diff --git a/test/integration/smoke/test_resource_accounting.py b/test/integration/smoke/test_resource_accounting.py index e690fcc2ee63..4f3172be4dba 100644 --- a/test/integration/smoke/test_resource_accounting.py +++ b/test/integration/smoke/test_resource_accounting.py @@ -230,10 +230,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..e527a31d7f43 100644 --- a/test/integration/smoke/test_resource_names.py +++ b/test/integration/smoke/test_resource_names.py @@ -83,14 +83,12 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) - cls._cleanup.append(cls.service_offering) cls.services["disk_offering"]["name"] = "test🎉diskoffering🙂" cls.disk_offering = DiskOffering.create( cls.apiclient, cls.services["disk_offering"] ) - cls._cleanup.append(cls.disk_offering) cls.services["small"]["displayname"] = "test🎉vm🙂" cls.virtual_machine = VirtualMachine.create( @@ -101,6 +99,9 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services['mode'] ) + cls._cleanup.append(cls.virtual_machine) + cls._cleanup.append(cls.service_offering) + cls._cleanup.append(cls.disk_offering) @classmethod def tearDownClass(cls): diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 7be6e7fc4ae6..c2f0f116c95d 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -794,7 +794,6 @@ def test_06_disk_offering_strictness_false(self): self.apiclient, offering_data, ) - self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse) self.virtual_machine_with_diskoffering_strictness_false = VirtualMachine.create( self.apiclient, @@ -804,7 +803,8 @@ 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) + self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse) try: self.virtual_machine_with_diskoffering_strictness_false.stop(self.apiclient) @@ -1015,6 +1015,7 @@ def getHost(self, hostId=None): ) cls._cleanup = [ + cls.vm, cls.offering, cls.account ] diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index 3d1016c4b161..b076dc44a821 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -1052,7 +1052,6 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) - cls._cleanup.append(cls.service_offering) #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, @@ -1063,9 +1062,10 @@ 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) - + cls._cleanup.append(cls.service_offering) list_volume = Volume.list( cls.apiclient, virtualmachineid=cls.virtual_machine.id, diff --git a/test/integration/smoke/test_usage.py b/test/integration/smoke/test_usage.py index 0d8da0e9d87f..cddcf5898739 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, ] @@ -1722,7 +1723,6 @@ 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"], @@ -1731,6 +1731,8 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.virtual_machine) + cls._cleanup.append(cls.service_offering) cls.public_ip = PublicIPAddress.create( cls.api_client, accountid=cls.virtual_machine.account, diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index 5dce965ba464..951ea4770174 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -240,6 +240,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"], @@ -247,6 +248,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_volumes.py b/test/integration/smoke/test_volumes.py index 7d64a27eaf2d..965f534d14d9 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -333,7 +333,11 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) - cls._cleanup.append(cls.service_offering) + cls.services["disk_offering"]["disksize"] = 20 + cls.disk_offering_20_GB = DiskOffering.create( + cls.apiclient, + cls.services["disk_offering"] + ) cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services, @@ -343,6 +347,8 @@ def setUpClass(cls): mode=cls.services["mode"] ) cls._cleanup.append(cls.virtual_machine) + cls.cleanup.append(cls.disk_offering_20_GB) + cls._cleanup.append(cls.service_offering) pools = StoragePool.list(cls.apiclient) if cls.hypervisor.lower() == 'lxc' and cls.storage_pools.type.lower() != 'rbd': @@ -636,16 +642,9 @@ def test_08_resize_volume(self): # resize the data disk self.debug("Resize Volume ID: %s" % self.volume.id) - self.services["disk_offering"]["disksize"] = 20 - disk_offering_20_GB = DiskOffering.create( - self.apiclient, - self.services["disk_offering"] - ) - self.cleanup.append(disk_offering_20_GB) - cmd = resizeVolume.resizeVolumeCmd() cmd.id = self.volume.id - cmd.diskofferingid = disk_offering_20_GB.id + cmd.diskofferingid = self.disk_offering_20_GB.id self.apiClient.resizeVolume(cmd) @@ -658,7 +657,7 @@ def test_08_resize_volume(self): type='DATADISK' ) for vol in list_volume_response: - if vol.id == self.volume.id and int(vol.size) == (int(disk_offering_20_GB.disksize) * (1024 ** 3)) and vol.state == 'Ready': + if vol.id == self.volume.id and int(vol.size) == (int(self.disk_offering_20_GB.disksize) * (1024 ** 3)) and vol.state == 'Ready': success = True if success: break From fdb1f45ad9e49ad922a2da35f8156df662f64f31 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Thu, 22 Aug 2024 12:28:54 -0400 Subject: [PATCH 05/14] address comment --- test/integration/smoke/test_affinity_groups.py | 6 +----- tools/marvin/setup.py | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py index 8e866b2d98cc..0649e7c241ad 100644 --- a/test/integration/smoke/test_affinity_groups.py +++ b/test/integration/smoke/test_affinity_groups.py @@ -253,11 +253,7 @@ def test_DeployVmAffinityGroup(self): 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) + super(TestDeployVmWithAffinityGroup, self).tearDown() @classmethod def tearDownClass(cls): diff --git a/tools/marvin/setup.py b/tools/marvin/setup.py index 679b1d5920d8..0618d84370a4 100644 --- a/tools/marvin/setup.py +++ b/tools/marvin/setup.py @@ -27,7 +27,7 @@ raise RuntimeError("python setuptools is required to build Marvin") -VERSION = "4.20.0.0" +VERSION = "4.20.0.0-SNAPSHOT" setup(name="Marvin", version=VERSION, From 3785bab95bc30b4d492f46511cdf75b766247103 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Thu, 22 Aug 2024 22:27:02 -0400 Subject: [PATCH 06/14] revert cleanup changes --- .../component/test_network_offering.py | 13 ++- .../smoke/test_backup_recovery_dummy.py | 8 +- .../smoke/test_console_endpoint.py | 13 +-- .../smoke/test_deploy_virtio_scsi_vm.py | 4 +- .../integration/smoke/test_primary_storage.py | 12 +-- .../smoke/test_reset_vm_on_reboot.py | 12 +-- .../smoke/test_resource_accounting.py | 10 +-- test/integration/smoke/test_resource_names.py | 4 +- .../smoke/test_service_offerings.py | 34 ++------ test/integration/smoke/test_templates.py | 11 +-- test/integration/smoke/test_usage.py | 83 +++++-------------- test/integration/smoke/test_vm_schedule.py | 2 +- test/integration/smoke/test_volumes.py | 20 +++-- 13 files changed, 75 insertions(+), 151 deletions(-) diff --git a/test/integration/component/test_network_offering.py b/test/integration/component/test_network_offering.py index aaa8c8ffed97..30827efedd0b 100644 --- a/test/integration/component/test_network_offering.py +++ b/test/integration/component/test_network_offering.py @@ -1395,12 +1395,10 @@ 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(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,6 +1444,7 @@ 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 @@ -1458,7 +1457,7 @@ def test_create_network_with_snat(self): networkids=[str(self.network.id)] ) self.cleanup.append(self.vm1) - self.cleanup.append(self.network) + self.debug("Deployed VM in network: %s" % self.network.id) src_nat_list = PublicIPAddress.list( diff --git a/test/integration/smoke/test_backup_recovery_dummy.py b/test/integration/smoke/test_backup_recovery_dummy.py index 568d8d550bde..b55e29e1ffdd 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.vm, cls.offering, cls.account] + cls._cleanup.append(cls.vm) # Import a dummy backup offering to use on tests @@ -74,10 +76,8 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + super(TestDummyBackupAndRecovery, cls).tearDownClass() try: - # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) - # 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 17a93699f545..507f7dd298b9 100644 --- a/test/integration/smoke/test_console_endpoint.py +++ b/test/integration/smoke/test_console_endpoint.py @@ -55,10 +55,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 +69,13 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) + cls._cleanup.append(cls.vm1) - cls._cleanup = [ - cls.vm1, - cls.service_offering, - 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 4ac3ba220e73..6f212bb77f87 100644 --- a/test/integration/smoke/test_deploy_virtio_scsi_vm.py +++ b/test/integration/smoke/test_deploy_virtio_scsi_vm.py @@ -124,6 +124,7 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["small"] ) + cls._cleanup.append(cls.service_offering) cls.sparse_disk_offering = DiskOffering.create( cls.apiclient, @@ -142,8 +143,7 @@ def setUpClass(cls): diskofferingid=cls.sparse_disk_offering.id, mode=cls.zone.networktype ) - cls._cleanup.append()cls.virtual_machine) - cls._cleanup.append(cls.service_offering) + cls._cleanup.append(cls.virtual_machine) hosts = Host.list(cls.apiclient, id=cls.virtual_machine.hostid) if len(hosts) != 1: diff --git a/test/integration/smoke/test_primary_storage.py b/test/integration/smoke/test_primary_storage.py index 6a66c37cd0d6..340ccaec7094 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,11 +313,13 @@ 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, self.services["service_offerings"]["tiny"] ) + self.cleanup.append(service_offering) self.virtual_machine = VirtualMachine.create( self.apiclient, @@ -335,8 +331,6 @@ def test_01_add_primary_storage_disabled_host(self): serviceofferingid=service_offering.id ) self.cleanup.append(self.virtual_machine) - self.cleanup.append(service_offering) - 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 5eb1203903f3..e8da02789760 100644 --- a/test/integration/smoke/test_reset_vm_on_reboot.py +++ b/test/integration/smoke/test_reset_vm_on_reboot.py @@ -59,12 +59,14 @@ 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"], isvolatile="true" ) + cls._cleanup.append(cls.small_offering) #create a virtual machine cls.virtual_machine = VirtualMachine.create( @@ -75,17 +77,11 @@ def setUpClass(cls): serviceofferingid=cls.small_offering.id, mode=cls.services["mode"] ) - cls._cleanup = [ - cls.virtual_machine, - 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 4f3172be4dba..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,12 +186,14 @@ 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( self.api_client, self.services["service_offering_it_2"], domainid=self.domain.id ) + self.cleanup.append(self.service_offering_it_2) vm_1 = VirtualMachine.create( self.apiclient, @@ -218,8 +216,6 @@ def test_01_so_removal_resource_update(self): self.debug("Deployed VM in account: %s, ID: %s" % (self.account.name, vm_2.id)) self.cleanup.append(vm_2) - self.cleanup.append(self.service_offering_it_1) - self.cleanup.append(self.service_offering_it_2) CPU_RESOURCE_ID = 8 RAM_RESOURCE_ID = 9 diff --git a/test/integration/smoke/test_resource_names.py b/test/integration/smoke/test_resource_names.py index e527a31d7f43..1f7418fbf2ef 100644 --- a/test/integration/smoke/test_resource_names.py +++ b/test/integration/smoke/test_resource_names.py @@ -83,12 +83,14 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) + cls._cleanup.append(cls.service_offering) cls.services["disk_offering"]["name"] = "test🎉diskoffering🙂" cls.disk_offering = DiskOffering.create( cls.apiclient, cls.services["disk_offering"] ) + cls._cleanup.append(cls.disk_offering) cls.services["small"]["displayname"] = "test🎉vm🙂" cls.virtual_machine = VirtualMachine.create( @@ -100,8 +102,6 @@ def setUpClass(cls): mode=cls.services['mode'] ) cls._cleanup.append(cls.virtual_machine) - cls._cleanup.append(cls.service_offering) - cls._cleanup.append(cls.disk_offering) @classmethod def tearDownClass(cls): diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index c2f0f116c95d..8c0aa9625b9f 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -365,14 +365,7 @@ 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): @@ -412,16 +405,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,26 +427,12 @@ def setUpClass(cls): serviceofferingid=cls.medium_offering.id, mode=cls.services["mode"] ) - cls._cleanup = [ - cls.medium_virtual_machine, - 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=[ @@ -794,6 +777,7 @@ def test_06_disk_offering_strictness_false(self): self.apiclient, offering_data, ) + self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse) self.virtual_machine_with_diskoffering_strictness_false = VirtualMachine.create( self.apiclient, @@ -804,7 +788,7 @@ def test_06_disk_offering_strictness_false(self): mode=self.services["mode"] ) self._cleanup.append(self.virtual_machine_with_diskoffering_strictness_false) - self._cleanup.append(self.serviceOfferingWithDiskOfferingStrictnessFalse) + try: self.virtual_machine_with_diskoffering_strictness_false.stop(self.apiclient) diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index b076dc44a821..1f718131ab90 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -1052,6 +1052,8 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) + cls._cleanup.append(cls.service_offering) + #create virtual machine cls.virtual_machine = VirtualMachine.create( cls.apiclient, @@ -1065,7 +1067,7 @@ def setUpClass(cls): cls._cleanup.append(cls.virtual_machine) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) - cls._cleanup.append(cls.service_offering) + list_volume = Volume.list( cls.apiclient, virtualmachineid=cls.virtual_machine.id, @@ -1099,12 +1101,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 cddcf5898739..e6973c099507 100644 --- a/test/integration/smoke/test_usage.py +++ b/test/integration/smoke/test_usage.py @@ -544,6 +544,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, @@ -554,17 +555,12 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id ) cls._cleanup.append(cls.virtual_machine) - cls._cleanup.append(cls.service_offering) + 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() @@ -845,6 +841,7 @@ def setUpClass(cls): cls.api_client, cls.services["service_offering"] ) + cls._cleanup.append(cls.service_offering) # create virtual machine cls.virtual_machine = VirtualMachine.create( cls.api_client, @@ -856,7 +853,6 @@ def setUpClass(cls): mode=cls.services["mode"] ) cls._cleanup.append(cls.virtual_machine) - cls._cleanup.append(cls.service_offering) # Stop virtual machine cls.virtual_machine.stop(cls.api_client) @@ -877,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() @@ -1171,13 +1162,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"], @@ -1186,6 +1178,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, @@ -1193,21 +1186,11 @@ def setUpClass(cls): domainid=cls.virtual_machine.domainid, services=cls.services["server"] ) - cls._cleanup = [ - cls.virtual_machine, - 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() @@ -1351,6 +1334,7 @@ def setUpClass(cls): cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name @@ -1358,6 +1342,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"], @@ -1366,21 +1351,12 @@ def setUpClass(cls): domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) - cls._cleanup = [ - cls.virtual_machine, - 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() @@ -1538,6 +1514,7 @@ def setUpClass(cls): cls.services["account"], domainid=cls.domain.id ) + cls._cleanup.append(cls.account) cls.services["account"] = cls.account.name @@ -1545,6 +1522,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"], @@ -1553,6 +1531,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, @@ -1560,21 +1539,11 @@ def setUpClass(cls): domainid=cls.virtual_machine.domainid, services=cls.services["server"] ) - cls._cleanup = [ - cls.virtual_machine, - 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() @@ -1723,6 +1692,8 @@ 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"], @@ -1732,7 +1703,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id ) cls._cleanup.append(cls.virtual_machine) - cls._cleanup.append(cls.service_offering) + cls.public_ip = PublicIPAddress.create( cls.api_client, accountid=cls.virtual_machine.account, @@ -1744,12 +1715,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() @@ -1758,12 +1724,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_schedule.py b/test/integration/smoke/test_vm_schedule.py index 71828000c193..3fb88c972089 100644 --- a/test/integration/smoke/test_vm_schedule.py +++ b/test/integration/smoke/test_vm_schedule.py @@ -113,6 +113,7 @@ def setUpClass(cls): 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"], @@ -122,7 +123,6 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, ) cls._cleanup.append(cls.virtual_machine) - cls._cleanup.append(cls.service_offering) return @classmethod diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index 965f534d14d9..dc8cff31e043 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -333,11 +333,7 @@ def setUpClass(cls): cls.apiclient, cls.services["service_offerings"]["tiny"] ) - cls.services["disk_offering"]["disksize"] = 20 - cls.disk_offering_20_GB = DiskOffering.create( - cls.apiclient, - cls.services["disk_offering"] - ) + cls._cleanup.append(cls.service_offering) cls.virtual_machine = VirtualMachine.create( cls.apiclient, cls.services, @@ -347,8 +343,7 @@ def setUpClass(cls): mode=cls.services["mode"] ) cls._cleanup.append(cls.virtual_machine) - cls.cleanup.append(cls.disk_offering_20_GB) - cls._cleanup.append(cls.service_offering) + pools = StoragePool.list(cls.apiclient) if cls.hypervisor.lower() == 'lxc' and cls.storage_pools.type.lower() != 'rbd': @@ -642,9 +637,16 @@ def test_08_resize_volume(self): # resize the data disk self.debug("Resize Volume ID: %s" % self.volume.id) + self.services["disk_offering"]["disksize"] = 20 + disk_offering_20_GB = DiskOffering.create( + self.apiclient, + self.services["disk_offering"] + ) + self.cleanup.append(disk_offering_20_GB) + cmd = resizeVolume.resizeVolumeCmd() cmd.id = self.volume.id - cmd.diskofferingid = self.disk_offering_20_GB.id + cmd.diskofferingid = disk_offering_20_GB.id self.apiClient.resizeVolume(cmd) @@ -657,7 +659,7 @@ def test_08_resize_volume(self): type='DATADISK' ) for vol in list_volume_response: - if vol.id == self.volume.id and int(vol.size) == (int(self.disk_offering_20_GB.disksize) * (1024 ** 3)) and vol.state == 'Ready': + if vol.id == self.volume.id and int(vol.size) == (int(disk_offering_20_GB.disksize) * (1024 ** 3)) and vol.state == 'Ready': success = True if success: break From bd7ff55562be26e2fa09e4c1718eecbaefda050f Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Fri, 23 Aug 2024 07:23:45 -0400 Subject: [PATCH 07/14] fix 1 test --- test/integration/component/test_cpu_max_limits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/component/test_cpu_max_limits.py b/test/integration/component/test_cpu_max_limits.py index 1c594de5dc5e..c6b10d1bd3b3 100644 --- a/test/integration/component/test_cpu_max_limits.py +++ b/test/integration/component/test_cpu_max_limits.py @@ -230,6 +230,7 @@ def test_02_deploy_vm_account_limit_reached(self): self.apiclient, self.testdata["service_offering_multiple_cores"] ) + self.cleanup.append(self.service_offering) # Adding to cleanup list after execution self.debug("Setting up account and domain hierarchy") @@ -244,7 +245,6 @@ def test_02_deploy_vm_account_limit_reached(self): self.vm1 = self.createInstance(account=self.child_do_admin, service_off=self.service_offering, api_client=api_client_admin) - self.cleanup.append(self.service_offering) self.debug("Deploying instance when CPU limit is reached in account") @@ -306,6 +306,7 @@ def test_04_deployVm__account_limit_reached(self): self.apiclient, self.testdata["service_offering_multiple_cores"] ) + self.cleanup.append(self.service_offering) self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=5, domain_limit=5, project_limit=5) @@ -319,7 +320,6 @@ def test_04_deployVm__account_limit_reached(self): 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.cleanup.append(self.service_offering) self.debug("Deploying instance in project when CPU limit is reached in account") with self.assertRaises(Exception): From 90400550adb39d2cc9511afe7d7c6d7392abddea Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 26 Aug 2024 09:47:55 -0400 Subject: [PATCH 08/14] address comments for test fixes --- .../component/test_cpu_max_limits.py | 1 - .../component/test_network_offering.py | 2 +- .../integration/smoke/test_affinity_groups.py | 4 ---- .../smoke/test_backup_recovery_dummy.py | 2 +- .../integration/smoke/test_direct_download.py | 1 - .../integration/smoke/test_primary_storage.py | 2 +- test/integration/smoke/test_scale_vm.py | 4 ++-- .../smoke/test_service_offerings.py | 19 ++++------------ test/integration/smoke/test_templates.py | 22 +++++-------------- test/integration/smoke/test_vm_life_cycle.py | 7 +----- 10 files changed, 16 insertions(+), 48 deletions(-) diff --git a/test/integration/component/test_cpu_max_limits.py b/test/integration/component/test_cpu_max_limits.py index c6b10d1bd3b3..65e76affe5f8 100644 --- a/test/integration/component/test_cpu_max_limits.py +++ b/test/integration/component/test_cpu_max_limits.py @@ -231,7 +231,6 @@ def test_02_deploy_vm_account_limit_reached(self): self.testdata["service_offering_multiple_cores"] ) self.cleanup.append(self.service_offering) - # Adding to cleanup list after execution self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=6, domain_limit=8) diff --git a/test/integration/component/test_network_offering.py b/test/integration/component/test_network_offering.py index 30827efedd0b..defd36f2cfa4 100644 --- a/test/integration/component/test_network_offering.py +++ b/test/integration/component/test_network_offering.py @@ -1388,7 +1388,7 @@ def setUpClass(cls): cls.services["service_offering"] ) - cls.cleanup = [ + cls._cleanup = [ cls.service_offering, ] return diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py index 0649e7c241ad..49c6bca95570 100644 --- a/test/integration/smoke/test_affinity_groups.py +++ b/test/integration/smoke/test_affinity_groups.py @@ -110,7 +110,6 @@ def test_DeployVmAntiAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.ag.name] ) - self.cleanup.append(vm1) list_vm1 = list_virtual_machines( @@ -145,7 +144,6 @@ def test_DeployVmAntiAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.ag.name] ) - self.cleanup.append(vm2) list_vm2 = list_virtual_machines( self.apiclient, @@ -190,7 +188,6 @@ def test_DeployVmAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.affinity.name] ) - self.cleanup.append(vm1) list_vm1 = list_virtual_machines( self.apiclient, @@ -224,7 +221,6 @@ def test_DeployVmAffinityGroup(self): serviceofferingid=self.service_offering.id, affinitygroupnames=[self.affinity.name] ) - self.cleanup.append(vm2) list_vm2 = list_virtual_machines( self.apiclient, diff --git a/test/integration/smoke/test_backup_recovery_dummy.py b/test/integration/smoke/test_backup_recovery_dummy.py index b55e29e1ffdd..1554d078b0ee 100644 --- a/test/integration/smoke/test_backup_recovery_dummy.py +++ b/test/integration/smoke/test_backup_recovery_dummy.py @@ -76,8 +76,8 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - super(TestDummyBackupAndRecovery, cls).tearDownClass() try: + 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_direct_download.py b/test/integration/smoke/test_direct_download.py index 9f9f52451316..6570bb9f0b3c 100644 --- a/test/integration/smoke/test_direct_download.py +++ b/test/integration/smoke/test_direct_download.py @@ -305,7 +305,6 @@ def test_01_deploy_vm_from_direct_download_template_nfs_storage(self): nfs_storage_offering = self.createServiceOffering("TestNFSStorageDirectDownload", "shared", test_tag) vm = self.deployVM(nfs_storage_offering) - self.cleanup.append(vm) self.assertEqual( vm.state, "Running", diff --git a/test/integration/smoke/test_primary_storage.py b/test/integration/smoke/test_primary_storage.py index 340ccaec7094..93c5b1e64a72 100644 --- a/test/integration/smoke/test_primary_storage.py +++ b/test/integration/smoke/test_primary_storage.py @@ -432,6 +432,7 @@ def setUpClass(cls): cls.services["service_offerings"]["tiny"], tags=cls.services["storage_tags"]["a"] ) + cls._cleanup.append(cls.service_offering_1) cls.service_offering_2 = ServiceOffering.create( cls.apiclient, cls.services["service_offerings"]["tiny"], @@ -472,7 +473,6 @@ def setUpClass(cls): hypervisor=cls.hypervisor, mode=cls.zone.networktype ) - cls._cleanup.append(cls.service_offering_1) # VM-1 not appended to _cleanup, it is expunged on tearDownClass before cleaning up resources return diff --git a/test/integration/smoke/test_scale_vm.py b/test/integration/smoke/test_scale_vm.py index 882a80785e06..eed3531cf54b 100644 --- a/test/integration/smoke/test_scale_vm.py +++ b/test/integration/smoke/test_scale_vm.py @@ -211,6 +211,7 @@ def test_01_scale_vm(self): serviceofferingid=self.small_offering.id, mode=self.services["mode"] ) + self.cleanup.append(self.virtual_machine) # If hypervisor is Vmware, then check if # the vmware tools are installed and the process is running @@ -258,7 +259,6 @@ def test_01_scale_vm(self): offering_data ) self.cleanup.append(self.bigger_offering) - self.cleanup.append(self.virtual_machine) else: self.bigger_offering = self.big_offering @@ -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.cleanup.append(self.virtual_machine_in_user_account) self.debug("Scaling VM-ID: %s to service offering: %s and state %s" % ( self.virtual_machine_in_user_account.id, self.bigger_offering.id, diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 8c0aa9625b9f..2426f1dca984 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -958,6 +958,7 @@ def setUpClass(cls): cls.services["account"], domainid=domain.id ) + cls._cleanup.append(cls.account) offering_data = { 'displaytext': 'TestOffering', @@ -972,6 +973,7 @@ def setUpClass(cls): offering_data, limitcpuuse=True ) + cls._cleanup.append(cls.offering) def getHost(self, hostId=None): response = list_hosts( @@ -998,24 +1000,11 @@ def getHost(self, hostId=None): hostid=cls.host.id ) - cls._cleanup = [ - cls.vm, - 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_templates.py b/test/integration/smoke/test_templates.py index 1f718131ab90..1e997d4755e7 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -486,6 +486,7 @@ def setUpClass(cls): cls.apiclient, cls.services["disk_offering"] ) + cls._cleanup.append(cls.disk_offering) template = get_template( cls.apiclient, cls.zone.id, @@ -509,15 +510,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, @@ -528,6 +532,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) @@ -560,25 +565,10 @@ def setUpClass(cls): account=cls.account.name, domainid=cls.account.domainid ) - cls._cleanup = [ - cls.virtual_machine, - 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): diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index 951ea4770174..bbbd86970a04 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -119,12 +119,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services['mode'] ) - - cls.cleanup = [ - cls.virtual_machine, - cls.service_offering, - cls.account - ] + cls._cleanup.append(cls.virtual_machine) @classmethod def tearDownClass(cls): From d34a9164c89e1502ec33f0318fa96c425b0731fa Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 26 Aug 2024 09:51:04 -0400 Subject: [PATCH 09/14] add new line --- test/integration/smoke/test_affinity_groups.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py index 49c6bca95570..98cc5404d760 100644 --- a/test/integration/smoke/test_affinity_groups.py +++ b/test/integration/smoke/test_affinity_groups.py @@ -145,6 +145,7 @@ def test_DeployVmAntiAffinityGroup(self): affinitygroupnames=[self.ag.name] ) self.cleanup.append(vm2) + list_vm2 = list_virtual_machines( self.apiclient, id=vm2.id @@ -189,6 +190,7 @@ def test_DeployVmAffinityGroup(self): affinitygroupnames=[self.affinity.name] ) self.cleanup.append(vm1) + list_vm1 = list_virtual_machines( self.apiclient, id=vm1.id @@ -222,6 +224,7 @@ def test_DeployVmAffinityGroup(self): affinitygroupnames=[self.affinity.name] ) self.cleanup.append(vm2) + list_vm2 = list_virtual_machines( self.apiclient, id=vm2.id From 1f3d2c926bc073f163de712015d0601844b826f0 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Fri, 30 Aug 2024 10:21:46 -0400 Subject: [PATCH 10/14] fix test failures --- test/integration/smoke/test_console_endpoint.py | 1 + test/integration/smoke/test_reset_vm_on_reboot.py | 2 +- test/integration/smoke/test_service_offerings.py | 1 + test/integration/smoke/test_templates.py | 7 +------ test/integration/smoke/test_usage.py | 2 ++ test/integration/smoke/test_vm_snapshots.py | 3 ++- test/integration/smoke/test_volumes.py | 2 -- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/test/integration/smoke/test_console_endpoint.py b/test/integration/smoke/test_console_endpoint.py index 507f7dd298b9..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, diff --git a/test/integration/smoke/test_reset_vm_on_reboot.py b/test/integration/smoke/test_reset_vm_on_reboot.py index e8da02789760..05ba4a9bcb56 100644 --- a/test/integration/smoke/test_reset_vm_on_reboot.py +++ b/test/integration/smoke/test_reset_vm_on_reboot.py @@ -52,7 +52,7 @@ 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, diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 2426f1dca984..608d0107d74b 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -952,6 +952,7 @@ 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, diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index 1e997d4755e7..ecd9607a7eb9 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -1073,12 +1073,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() diff --git a/test/integration/smoke/test_usage.py b/test/integration/smoke/test_usage.py index e6973c099507..71d4b32fb930 100644 --- a/test/integration/smoke/test_usage.py +++ b/test/integration/smoke/test_usage.py @@ -1143,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, @@ -1495,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, 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 dc8cff31e043..1cc543efe66f 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -642,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 @@ -692,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 From 29eea23011386493e4ab3c66de5eece4630f868a Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Fri, 30 Aug 2024 10:26:36 -0400 Subject: [PATCH 11/14] detach volume for its cleanup --- test/integration/smoke/test_resource_names.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/smoke/test_resource_names.py b/test/integration/smoke/test_resource_names.py index 1f7418fbf2ef..438de0551b25 100644 --- a/test/integration/smoke/test_resource_names.py +++ b/test/integration/smoke/test_resource_names.py @@ -179,7 +179,7 @@ def test_02_create_volume(self): domainid=self.account.domainid, diskofferingid=self.disk_offering.id ) - # self.cleanup.append(self.volume) + self.cleanup.append(self.volume) self.virtual_machine.attach_volume(self.apiclient, self.volume) list_volume_response = Volume.list( self.apiclient, @@ -207,6 +207,7 @@ def test_02_create_volume(self): self.volume.name, "Check virtual machine display name in listVirtualMachines" ) + self.virtual_machine.detach_volume(self.apiclient, self.volume) @attr(tags=["advanced", "smoke", "basic"], required_hardware="true") def test_03_register_template(self): From bb8a66027b18edff99cde1463ec3d18a72d2a3ed Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Sat, 31 Aug 2024 10:18:21 -0400 Subject: [PATCH 12/14] fix few tests --- .../smoke/test_deploy_virtio_scsi_vm.py | 1 - test/integration/smoke/test_direct_download.py | 2 +- test/integration/smoke/test_resource_names.py | 2 -- .../integration/smoke/test_service_offerings.py | 1 + test/integration/smoke/test_snapshots.py | 7 +------ test/integration/smoke/test_templates.py | 17 ++--------------- 6 files changed, 5 insertions(+), 25 deletions(-) diff --git a/test/integration/smoke/test_deploy_virtio_scsi_vm.py b/test/integration/smoke/test_deploy_virtio_scsi_vm.py index 6f212bb77f87..8f123e26050f 100644 --- a/test/integration/smoke/test_deploy_virtio_scsi_vm.py +++ b/test/integration/smoke/test_deploy_virtio_scsi_vm.py @@ -160,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_resource_names.py b/test/integration/smoke/test_resource_names.py index 438de0551b25..9391814457ab 100644 --- a/test/integration/smoke/test_resource_names.py +++ b/test/integration/smoke/test_resource_names.py @@ -179,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, @@ -207,7 +206,6 @@ def test_02_create_volume(self): self.volume.name, "Check virtual machine display name in listVirtualMachines" ) - self.virtual_machine.detach_volume(self.apiclient, self.volume) @attr(tags=["advanced", "smoke", "basic"], required_hardware="true") def test_03_register_template(self): diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 608d0107d74b..749e3841879e 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -369,6 +369,7 @@ def tearDown(self): @classmethod def setUpClass(cls): + cls._cleanup = [] testClient = super(TestServiceOfferings, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.services = testClient.getParsedTestDataConfig() diff --git a/test/integration/smoke/test_snapshots.py b/test/integration/smoke/test_snapshots.py index f8346093c641..a10f1c172164 100644 --- a/test/integration/smoke/test_snapshots.py +++ b/test/integration/smoke/test_snapshots.py @@ -339,9 +339,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 +356,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 ecd9607a7eb9..699adb324785 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): @@ -342,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): From a9f1b0a3dba1bcd129851432d1791c1767e0f2d1 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 10 Sep 2024 11:40:42 -0400 Subject: [PATCH 13/14] fix tests --- .../smoke/test_service_offerings.py | 29 +++++--- test/integration/smoke/test_snapshots.py | 73 +++++++++---------- test/integration/smoke/test_templates.py | 12 +-- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 749e3841879e..69ec3ab6e951 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -374,6 +374,7 @@ def setUpClass(cls): 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()) @@ -383,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, @@ -778,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, @@ -788,7 +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) + self.cleanup.append(self.virtual_machine_with_diskoffering_strictness_false) try: self.virtual_machine_with_diskoffering_strictness_false.stop(self.apiclient) @@ -818,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, @@ -833,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 diff --git a/test/integration/smoke/test_snapshots.py b/test/integration/smoke/test_snapshots.py index a10f1c172164..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 diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index 699adb324785..c5b007c4c9b2 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -317,7 +317,7 @@ def setUpClass(cls): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) - cls._cleanup(cls.virtual_machine) + cls._cleanup.append(cls.virtual_machine) #Stop virtual machine cls.virtual_machine.stop(cls.apiclient) @@ -1003,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, @@ -1025,11 +1030,6 @@ 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( From 590dc485a42ce3b7b1d7e70f90f74358feacf0ce Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 10 Sep 2024 14:33:09 -0400 Subject: [PATCH 14/14] unused imports --- .../cloud/configuration/ConfigurationManagerImpl.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index bd5bbf3f69bf..d034ce437942 100644 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -172,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; @@ -186,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; @@ -205,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; @@ -233,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; @@ -267,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; @@ -289,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; @@ -314,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;