You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2023/11/29 12:27:35 UTC

(cloudstack) branch main updated (60b399f8758 -> a31f2116282)

This is an automated email from the ASF dual-hosted git repository.

dahn pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


    from 60b399f8758 Fix create private gateway rollback (#8244)
     add 3c7c75bacfd Clear pool id if volume allocation fails (#8202)
     add 8f390873772 Fix typo in ssvm check script (#8191)
     add 956efb27d93 allow filtering of listDiskOffering and listServiceOffering APIs by account or project (#7082)
     new a31f2116282 Merge remote-tracking branch 'remote/4.18'

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../user/offering/ListDiskOfferingsCmd.java        |   4 +-
 .../user/offering/ListServiceOfferingsCmd.java     |   4 +-
 .../java/com/cloud/api/query/QueryManagerImpl.java |  27 +--
 .../deploy/DeploymentPlanningManagerImpl.java      |  10 +
 .../deploy/DeploymentPlanningManagerImplTest.java  | 211 ++++++++++++++++-----
 .../com/cloud/storage/StorageManagerImplTest.java  |  30 +++
 systemvm/agent/scripts/ssvm-check.sh               |   6 +-
 7 files changed, 222 insertions(+), 70 deletions(-)


(cloudstack) 01/01: Merge remote-tracking branch 'remote/4.18'

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit a31f211628265d76f73cad1c122a854c6dc73944
Merge: 60b399f8758 956efb27d93
Author: Vishesh <vi...@gmail.com>
AuthorDate: Wed Nov 29 16:12:51 2023 +0530

    Merge remote-tracking branch 'remote/4.18'

 .../user/offering/ListDiskOfferingsCmd.java        |   4 +-
 .../user/offering/ListServiceOfferingsCmd.java     |   4 +-
 .../java/com/cloud/api/query/QueryManagerImpl.java |  27 +--
 .../deploy/DeploymentPlanningManagerImpl.java      |  10 +
 .../deploy/DeploymentPlanningManagerImplTest.java  | 211 ++++++++++++++++-----
 .../com/cloud/storage/StorageManagerImplTest.java  |  30 +++
 systemvm/agent/scripts/ssvm-check.sh               |   6 +-
 7 files changed, 222 insertions(+), 70 deletions(-)

diff --cc api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java
index c605b58d7c6,5ab675ae435..e7284d515a2
--- 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
@@@ -23,9 -24,7 +24,8 @@@ import org.apache.log4j.Logger
  
  import org.apache.cloudstack.api.APICommand;
  import org.apache.cloudstack.api.ApiConstants;
- import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
  import org.apache.cloudstack.api.Parameter;
 +import org.apache.cloudstack.api.BaseCmd.CommandType;
  import org.apache.cloudstack.api.response.DiskOfferingResponse;
  import org.apache.cloudstack.api.response.ListResponse;
  
diff --cc api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
index f7c99459baa,cb155d24ad8..a9a699ed3ef
--- 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
@@@ -21,9 -22,7 +22,8 @@@ import org.apache.log4j.Logger
  
  import org.apache.cloudstack.api.APICommand;
  import org.apache.cloudstack.api.ApiConstants;
- import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
  import org.apache.cloudstack.api.Parameter;
 +import org.apache.cloudstack.api.BaseCmd.CommandType;
  import org.apache.cloudstack.api.response.ListResponse;
  import org.apache.cloudstack.api.response.ServiceOfferingResponse;
  import org.apache.cloudstack.api.response.UserVmResponse;
diff --cc server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
index 7a7e88ef449,51aed5af66c..98f162697d2
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@@ -3152,7 -2929,9 +3152,9 @@@ public class QueryManagerImpl extends M
          Object id = cmd.getId();
          Object keyword = cmd.getKeyword();
          Long domainId = cmd.getDomainId();
 +        Boolean isRootAdmin = accountMgr.isRootAdmin(account.getAccountId());
+         Long projectId = cmd.getProjectId();
+         String accountName = cmd.getAccountName();
 -        Boolean isRootAdmin = _accountMgr.isRootAdmin(account.getAccountId());
          Boolean isRecursive = cmd.isRecursive();
          Long zoneId = cmd.getZoneId();
          Long volumeId = cmd.getVolumeId();
@@@ -3246,9 -3021,9 +3248,9 @@@
  
          // Filter offerings that are not associated with caller's domain
          // Fetch the offering ids from the details table since theres no smart way to filter them in the join ... yet!
-         Account caller = CallContext.current().getCallingAccount();
-         if (caller.getType() != Account.Type.ADMIN) {
-             Domain callerDomain = _domainDao.findById(caller.getDomainId());
 -        account = _accountMgr.finalizeOwner(account, accountName, domainId, projectId);
++        account = accountMgr.finalizeOwner(account, accountName, domainId, projectId);
+         if (!Account.Type.ADMIN.equals(account.getType())) {
+             Domain callerDomain = _domainDao.findById(account.getDomainId());
              List<Long> domainIds = findRelatedDomainIds(callerDomain, isRecursive);
  
              List<Long> ids = _diskOfferingDetailsDao.findOfferingIdsByDomainIds(domainIds);
@@@ -3352,21 -3118,21 +3356,22 @@@
          Integer memory = cmd.getMemory();
          Integer cpuSpeed = cmd.getCpuSpeed();
          Boolean encryptRoot = cmd.getEncryptRoot();
 +        String storageType = cmd.getStorageType();
  
 -        final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
++        final Account owner = accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
          SearchCriteria<ServiceOfferingJoinVO> sc = _srvOfferingJoinDao.createSearchCriteria();
 -        if (!_accountMgr.isRootAdmin(caller.getId()) && isSystem) {
 -            throw new InvalidParameterValueException("Only ROOT admins can access system offerings.");
 +        if (!accountMgr.isRootAdmin(caller.getId()) && isSystem) {
 +            throw new InvalidParameterValueException("Only ROOT admins can access system's offering");
          }
  
          // Keeping this logic consistent with domain specific zones
          // if a domainId is provided, we just return the so associated with this
          // domain
 -        if (domainId != null && !_accountMgr.isRootAdmin(caller.getId())) {
 +        if (domainId != null && !accountMgr.isRootAdmin(caller.getId())) {
              // check if the user's domain == so's domain || user's domain is a
              // child of so's domain
-             if (!isPermissible(caller.getDomainId(), domainId)) {
-                 throw new PermissionDeniedException("The account:" + caller.getAccountName() + " does not fall in the same domain hierarchy as the service offering");
+             if (!isPermissible(owner.getDomainId(), domainId)) {
+                 throw new PermissionDeniedException("The account:" + owner.getAccountName() + " does not fall in the same domain hierarchy as the service offering");
              }
          }
  
diff --cc server/src/test/java/com/cloud/deploy/DeploymentPlanningManagerImplTest.java
index 2dfd2829ed9,ea9e2bb2090..6bfc8fb629d
--- a/server/src/test/java/com/cloud/deploy/DeploymentPlanningManagerImplTest.java
+++ b/server/src/test/java/com/cloud/deploy/DeploymentPlanningManagerImplTest.java
@@@ -16,77 -16,54 +16,86 @@@
  // under the License.
  package com.cloud.deploy;
  
 -import static org.junit.Assert.assertFalse;
 -import static org.junit.Assert.assertNull;
 -import static org.junit.Assert.assertTrue;
 -import static org.mockito.Mockito.times;
 -import static org.mockito.Mockito.verify;
 -
 -import java.io.IOException;
 -import java.util.ArrayList;
 -import java.util.Arrays;
 -import java.util.HashMap;
 -import java.util.LinkedHashMap;
 -import java.util.List;
 -import java.util.Map;
 -
 -import javax.inject.Inject;
 -import javax.naming.ConfigurationException;
+ 
 +import com.cloud.agent.AgentManager;
 +import com.cloud.capacity.CapacityManager;
 +import com.cloud.capacity.dao.CapacityDao;
 +import com.cloud.configuration.ConfigurationManagerImpl;
 +import com.cloud.dc.ClusterDetailsDao;
  import com.cloud.dc.ClusterDetailsVO;
 +import com.cloud.dc.ClusterVO;
  import com.cloud.dc.DataCenter;
 +import com.cloud.dc.DataCenterVO;
+ import com.cloud.dc.HostPodVO;
 +import com.cloud.dc.dao.ClusterDao;
 +import com.cloud.dc.dao.DataCenterDao;
 +import com.cloud.dc.dao.DedicatedResourceDao;
 +import com.cloud.dc.dao.HostPodDao;
 +import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 +import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
 +import com.cloud.deploy.dao.PlannerHostReservationDao;
 +import com.cloud.exception.AffinityConflictException;
 +import com.cloud.exception.InsufficientServerCapacityException;
  import com.cloud.gpu.GPU;
 +import com.cloud.gpu.dao.HostGpuGroupsDao;
  import com.cloud.host.Host;
  import com.cloud.host.HostVO;
  import com.cloud.host.Status;
 +import com.cloud.host.dao.HostDao;
 +import com.cloud.host.dao.HostDetailsDao;
 +import com.cloud.host.dao.HostTagsDao;
 +import com.cloud.hypervisor.Hypervisor.HypervisorType;
 +import com.cloud.org.Grouping.AllocationState;
 +import com.cloud.resource.ResourceManager;
 +import com.cloud.service.ServiceOfferingVO;
 +import com.cloud.service.dao.ServiceOfferingDetailsDao;
  import com.cloud.storage.DiskOfferingVO;
 +import com.cloud.storage.ScopeType;
  import com.cloud.storage.Storage;
 +import com.cloud.storage.StorageManager;
  import com.cloud.storage.StoragePool;
+ import com.cloud.storage.StoragePoolStatus;
  import com.cloud.storage.VMTemplateVO;
  import com.cloud.storage.Volume;
  import com.cloud.storage.VolumeVO;
 +import com.cloud.storage.dao.DiskOfferingDao;
 +import com.cloud.storage.dao.GuestOSCategoryDao;
 +import com.cloud.storage.dao.GuestOSDao;
 +import com.cloud.storage.dao.StoragePoolHostDao;
  import com.cloud.storage.dao.VMTemplateDao;
 +import com.cloud.storage.dao.VolumeDao;
+ import com.cloud.template.VirtualMachineTemplate;
+ import com.cloud.user.Account;
 +import com.cloud.user.AccountManager;
  import com.cloud.user.AccountVO;
  import com.cloud.user.dao.AccountDao;
  import com.cloud.utils.Pair;
 +import com.cloud.utils.component.ComponentContext;
+ import com.cloud.vm.DiskProfile;
  import com.cloud.vm.VMInstanceVO;
  import com.cloud.vm.VirtualMachine;
  import com.cloud.vm.VirtualMachine.Type;
  import com.cloud.vm.VirtualMachineProfile;
  import com.cloud.vm.VirtualMachineProfileImpl;
 +import com.cloud.vm.dao.UserVmDao;
 +import com.cloud.vm.dao.UserVmDetailsDao;
 +import com.cloud.vm.dao.VMInstanceDao;
 +import org.apache.cloudstack.affinity.AffinityGroupProcessor;
 +import org.apache.cloudstack.affinity.AffinityGroupService;
 +import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
  import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
 +import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 +import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
+ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
+ import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 +import org.apache.cloudstack.framework.config.ConfigKey;
 +import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 +import org.apache.cloudstack.framework.messagebus.MessageBus;
 +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
  import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 +import org.apache.cloudstack.test.utils.SpringUtils;
  import org.apache.commons.collections.CollectionUtils;
  import org.junit.Assert;
  import org.junit.Before;
@@@ -112,21 -90,52 +121,23 @@@ import org.springframework.test.context
  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  import org.springframework.test.context.support.AnnotationConfigContextLoader;
  
 -import org.apache.cloudstack.affinity.AffinityGroupProcessor;
 -import org.apache.cloudstack.affinity.AffinityGroupService;
 -import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 -import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 -import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
 -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 -import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 -import org.apache.cloudstack.framework.messagebus.MessageBus;
 -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 -import org.apache.cloudstack.test.utils.SpringUtils;
 +import javax.inject.Inject;
 +import javax.naming.ConfigurationException;
 +import java.io.IOException;
 +import java.lang.reflect.Field;
 +import java.util.ArrayList;
 +import java.util.Arrays;
 +import java.util.HashMap;
 +import java.util.LinkedHashMap;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.Set;
  
 -import com.cloud.agent.AgentManager;
 -import com.cloud.capacity.CapacityManager;
 -import com.cloud.capacity.dao.CapacityDao;
 -import com.cloud.dc.ClusterDetailsDao;
 -import com.cloud.dc.ClusterVO;
 -import com.cloud.dc.DataCenterVO;
 -import com.cloud.dc.dao.ClusterDao;
 -import com.cloud.dc.dao.DataCenterDao;
 -import com.cloud.dc.dao.DedicatedResourceDao;
 -import com.cloud.dc.dao.HostPodDao;
 -import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 -import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
 -import com.cloud.deploy.dao.PlannerHostReservationDao;
 -import com.cloud.exception.AffinityConflictException;
 -import com.cloud.exception.InsufficientServerCapacityException;
 -import com.cloud.gpu.dao.HostGpuGroupsDao;
 -import com.cloud.host.dao.HostDao;
 -import com.cloud.host.dao.HostTagsDao;
 -import com.cloud.hypervisor.Hypervisor.HypervisorType;
 -import com.cloud.resource.ResourceManager;
 -import com.cloud.org.Grouping.AllocationState;
 -import com.cloud.service.ServiceOfferingVO;
 -import com.cloud.service.dao.ServiceOfferingDetailsDao;
 -import com.cloud.storage.StorageManager;
 -import com.cloud.storage.dao.DiskOfferingDao;
 -import com.cloud.storage.dao.GuestOSCategoryDao;
 -import com.cloud.storage.dao.GuestOSDao;
 -import com.cloud.storage.dao.StoragePoolHostDao;
 -import com.cloud.storage.dao.VolumeDao;
 -import com.cloud.user.AccountManager;
 -import com.cloud.utils.component.ComponentContext;
 -import com.cloud.vm.dao.UserVmDao;
 -import com.cloud.vm.dao.UserVmDetailsDao;
 -import com.cloud.vm.dao.VMInstanceDao;
 -import com.cloud.host.dao.HostDetailsDao;
 +import static org.junit.Assert.assertFalse;
 +import static org.junit.Assert.assertNull;
 +import static org.junit.Assert.assertTrue;
++import static org.mockito.Mockito.times;
++import static org.mockito.Mockito.verify;
  
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@@@ -255,13 -275,13 +280,13 @@@ public class DeploymentPlanningManagerI
      @Test
      public void dataCenterAvoidTest() throws InsufficientServerCapacityException, AffinityConflictException {
          ServiceOfferingVO svcOffering =
--            new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm",
--                    false, VirtualMachine.Type.User, null, "FirstFitPlanner", true, false);
++                new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm",
++                        false, VirtualMachine.Type.User, null, "FirstFitPlanner", true, false);
          Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
  
          DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
  
--        Mockito.when(avoids.shouldAvoid((DataCenterVO)Matchers.anyObject())).thenReturn(true);
++        Mockito.when(avoids.shouldAvoid((DataCenterVO) Matchers.anyObject())).thenReturn(true);
          DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids, null);
          assertNull("DataCenter is in avoid set, destination should be null! ", dest);
      }
@@@ -269,12 -289,12 +294,12 @@@
      @Test
      public void plannerCannotHandleTest() throws InsufficientServerCapacityException, AffinityConflictException {
          ServiceOfferingVO svcOffering =
--            new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm",
--                    false, VirtualMachine.Type.User, null, "UserDispersingPlanner", true, false);
++                new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm",
++                        false, VirtualMachine.Type.User, null, "UserDispersingPlanner", true, false);
          Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
  
          DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
--        Mockito.when(avoids.shouldAvoid((DataCenterVO)Matchers.anyObject())).thenReturn(false);
++        Mockito.when(avoids.shouldAvoid((DataCenterVO) Matchers.anyObject())).thenReturn(false);
  
          Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(false);
          DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids, null);
@@@ -284,15 -304,15 +309,15 @@@
      @Test
      public void emptyClusterListTest() throws InsufficientServerCapacityException, AffinityConflictException {
          ServiceOfferingVO svcOffering =
--            new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm",
--                    false, VirtualMachine.Type.User, null, "FirstFitPlanner", true, false);
++                new ServiceOfferingVO("testOffering", 1, 512, 500, 1, 1, false, false, false, "test dpm",
++                        false, VirtualMachine.Type.User, null, "FirstFitPlanner", true, false);
          Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
  
          DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
--        Mockito.when(avoids.shouldAvoid((DataCenterVO)Matchers.anyObject())).thenReturn(false);
++        Mockito.when(avoids.shouldAvoid((DataCenterVO) Matchers.anyObject())).thenReturn(false);
          Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(true);
  
--        Mockito.when(((DeploymentClusterPlanner)_planner).orderClusters(vmProfile, plan, avoids)).thenReturn(null);
++        Mockito.when(((DeploymentClusterPlanner) _planner).orderClusters(vmProfile, plan, avoids)).thenReturn(null);
          DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids, null);
          assertNull("Planner cannot handle, destination should be null! ", dest);
      }
@@@ -368,7 -388,7 +393,8 @@@
          }
      }
  
--    private void prepareAndVerifyAvoidDisabledResourcesTest(int timesRouter, int timesAdminVm, int timesDisabledResource, long roleId, Type vmType, boolean isSystemDepolyable,
++    private void prepareAndVerifyAvoidDisabledResourcesTest(int timesRouter, int timesAdminVm,
++            int timesDisabledResource, long roleId, Type vmType, boolean isSystemDepolyable,
              boolean isAdminVmDeployable) {
          Mockito.doReturn(isSystemDepolyable).when(_dpm).isRouterDeployableInDisabledResources();
          Mockito.doReturn(isAdminVmDeployable).when(_dpm).isAdminVmDeployableInDisabledResources();
@@@ -481,9 -501,9 +507,9 @@@
  
      @Test
      public void volumesRequireEncryptionTest() {
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path", Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
--        VolumeVO vol2 = new VolumeVO("vol2", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.DATADISK);
--        VolumeVO vol3 = new VolumeVO("vol3", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.DATADISK);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
++        VolumeVO vol2 = new VolumeVO("vol2", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.DATADISK);
++        VolumeVO vol3 = new VolumeVO("vol3", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.DATADISK);
          vol2.setPassphraseId(1L);
  
          List<VolumeVO> volumes = List.of(vol1, vol2, vol3);
@@@ -492,9 -512,9 +518,9 @@@
  
      @Test
      public void volumesDoNotRequireEncryptionTest() {
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
--        VolumeVO vol2 = new VolumeVO("vol2", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.DATADISK);
--        VolumeVO vol3 = new VolumeVO("vol3", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.DATADISK);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
++        VolumeVO vol2 = new VolumeVO("vol2", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.DATADISK);
++        VolumeVO vol3 = new VolumeVO("vol3", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.DATADISK);
  
          List<VolumeVO> volumes = List.of(vol1, vol2, vol3);
          Assert.assertFalse("Volumes do not require encryption, but reporting they do", _dpm.anyVolumeRequiresEncryption(volumes));
@@@ -511,7 -531,7 +537,7 @@@
          }};
          host.setDetails(hostDetails);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
          vol1.setPassphraseId(1L);
  
          setupMocksForPlanDeploymentHostTests(host, vol1);
@@@ -536,7 -556,7 +562,7 @@@
          }};
          host.setDetails(hostDetails);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
          vol1.setPassphraseId(1L);
  
          setupMocksForPlanDeploymentHostTests(host, vol1);
@@@ -561,7 -581,7 +587,7 @@@
          }};
          host.setDetails(hostDetails);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
  
          setupMocksForPlanDeploymentHostTests(host, vol1);
  
@@@ -585,7 -605,7 +611,7 @@@
          }};
          host.setDetails(hostDetails);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
  
          setupMocksForPlanDeploymentHostTests(host, vol1);
  
@@@ -610,7 -630,7 +636,7 @@@
          host.setDetails(hostDetails);
          Mockito.when(host.getStatus()).thenReturn(Status.Up);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
          vol1.setPassphraseId(1L);
  
          setupMocksForPlanDeploymentHostTests(host, vol1);
@@@ -640,7 -660,7 +666,7 @@@
          host.setDetails(hostDetails);
          Mockito.when(host.getStatus()).thenReturn(Status.Up);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
          vol1.setPassphraseId(1L);
  
          setupMocksForPlanDeploymentHostTests(host, vol1);
@@@ -666,7 -686,7 +692,7 @@@
          host.setDetails(hostDetails);
          Mockito.when(host.getStatus()).thenReturn(Status.Up);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
          vol1.setPassphraseId(1L);
  
          DeploymentClusterPlanner planner = setupMocksForPlanDeploymentHostTests(host, vol1);
@@@ -691,7 -711,7 +717,7 @@@
          host.setDetails(hostDetails);
          Mockito.when(host.getStatus()).thenReturn(Status.Up);
  
--        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId,podId,1L,1L, instanceId,"folder","path",Storage.ProvisioningType.THIN, (long)10<<30, Volume.Type.ROOT);
++        VolumeVO vol1 = new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path", Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT);
          vol1.setPassphraseId(1L);
  
          DeploymentClusterPlanner planner = setupMocksForPlanDeploymentHostTests(host, vol1);
@@@ -707,6 -727,84 +733,84 @@@
          }
      }
  
+     @Test
+     public void findSuitablePoolsForVolumesTest() throws Exception {
+         Long diskOfferingId = 1L;
+         HostVO host = Mockito.spy(new HostVO("host"));
+         Map<String, String> hostDetails = new HashMap<>() {
+             {
+                 put(Host.HOST_VOLUME_ENCRYPTION, "true");
+             }
+         };
+         host.setDetails(hostDetails);
+         Mockito.when(host.getStatus()).thenReturn(Status.Up);
+ 
+         VolumeVO vol1 = Mockito.spy(new VolumeVO("vol1", dataCenterId, podId, 1L, 1L, instanceId, "folder", "path",
+                 Storage.ProvisioningType.THIN, (long) 10 << 30, Volume.Type.ROOT));
+         Mockito.when(vol1.getId()).thenReturn(1L);
+         vol1.setState(Volume.State.Allocated);
+         vol1.setPassphraseId(1L);
+         vol1.setPoolId(1L);
+         vol1.setDiskOfferingId(diskOfferingId);
+ 
+         StoragePoolVO storagePool = new StoragePoolVO();
+         storagePool.setStatus(StoragePoolStatus.Maintenance);
+         storagePool.setId(vol1.getPoolId());
+         storagePool.setDataCenterId(dataCenterId);
+         storagePool.setPodId(podId);
+         storagePool.setClusterId(clusterId);
+ 
+         DiskProfile diskProfile = Mockito.mock(DiskProfile.class);
+ 
+         StoragePoolAllocator allocator = Mockito.mock(StoragePoolAllocator.class);
+ 
+         DataCenterDeployment plan = new DataCenterDeployment(dataCenterId, podId, clusterId, null, null, null);
+ 
+         Account account = Mockito.mock(Account.class);
+         Mockito.when(account.getId()).thenReturn(1L);
+         Mockito.when(vmProfile.getOwner()).thenReturn(account);
+         Mockito.when(_accountMgr.isRootAdmin(account.getId())).thenReturn(Boolean.FALSE);
+ 
+         Mockito.when(_dcDao.findById(dataCenterId)).thenReturn(dc);
+         Mockito.when(dc.getAllocationState()).thenReturn(AllocationState.Enabled);
+ 
+         HostPodVO podVo = Mockito.mock(HostPodVO.class);
+         Mockito.when(podVo.getAllocationState()).thenReturn(AllocationState.Enabled);
+         Mockito.doReturn(podVo).when(_podDao).findById(podId);
+ 
+         ClusterVO cluster = Mockito.mock(ClusterVO.class);
+         Mockito.when(cluster.getAllocationState()).thenReturn(AllocationState.Enabled);
+         Mockito.when(_clusterDao.findById(clusterId)).thenReturn(cluster);
+ 
+         DiskOfferingVO diskOffering = Mockito.mock(DiskOfferingVO.class);
+ 
+         Mockito.when(_diskOfferingDao.findById(vol1.getDiskOfferingId())).thenReturn(diskOffering);
+         VirtualMachineTemplate vmt = Mockito.mock(VirtualMachineTemplate.class);
+ 
+         ServiceOfferingVO serviceOffering = Mockito.mock(ServiceOfferingVO.class);
+         Mockito.when(vmProfile.getServiceOffering()).thenReturn(serviceOffering);
+ 
+         PrimaryDataStore primaryDataStore = Mockito.mock(PrimaryDataStore.class);
+ 
+         Mockito.when(vmt.getFormat()).thenReturn(Storage.ImageFormat.ISO);
+         Mockito.when(vmProfile.getTemplate()).thenReturn(vmt);
+ 
+         Mockito.when(vmProfile.getId()).thenReturn(1L);
+         Mockito.when(vmProfile.getType()).thenReturn(VirtualMachine.Type.User);
+         Mockito.when(volDao.findUsableVolumesForInstance(1L)).thenReturn(Arrays.asList(vol1));
+         Mockito.when(volDao.findByInstanceAndType(1L, Volume.Type.ROOT)).thenReturn(Arrays.asList(vol1));
+         Mockito.when(_dataStoreManager.getPrimaryDataStore(vol1.getPoolId())).thenReturn((DataStore) primaryDataStore);
+         Mockito.when(avoids.shouldAvoid(storagePool)).thenReturn(Boolean.FALSE);
 -        PowerMockito.whenNew(DiskProfile.class).withAnyArguments().thenReturn(diskProfile);
+ 
+         Mockito.doReturn(Arrays.asList(storagePool)).when(allocator).allocateToPool(diskProfile, vmProfile, plan,
+                 avoids, 10);
+         Mockito.when(volDao.update(vol1.getId(), vol1)).thenReturn(true);
+         _dpm.findSuitablePoolsForVolumes(vmProfile, plan, avoids, 10);
+         verify(vol1, times(1)).setPoolId(null);
+         assertTrue(vol1.getPoolId() == null);
+ 
+     }
++
      // This is so ugly but everything is so intertwined...
      private DeploymentClusterPlanner setupMocksForPlanDeploymentHostTests(HostVO host, VolumeVO vol1) {
          long diskOfferingId = 345L;
@@@ -739,10 -837,10 +843,10 @@@
          Mockito.doNothing().when(hostDao).loadDetails(host);
          Mockito.doReturn(volumeVOs).when(volDao).findByInstance(ArgumentMatchers.anyLong());
          Mockito.doReturn(suitable).when(_dpm).findSuitablePoolsForVolumes(
--            ArgumentMatchers.any(VirtualMachineProfile.class),
--            ArgumentMatchers.any(DataCenterDeployment.class),
--            ArgumentMatchers.any(ExcludeList.class),
--            ArgumentMatchers.anyInt()
++                ArgumentMatchers.any(VirtualMachineProfile.class),
++                ArgumentMatchers.any(DataCenterDeployment.class),
++                ArgumentMatchers.any(ExcludeList.class),
++                ArgumentMatchers.anyInt()
          );
  
          ClusterVO clusterVO = new ClusterVO();
@@@ -750,10 -848,10 +854,10 @@@
          Mockito.when(_clusterDao.findById(ArgumentMatchers.anyLong())).thenReturn(clusterVO);
  
          Mockito.doReturn(List.of(host)).when(_dpm).findSuitableHosts(
--            ArgumentMatchers.any(VirtualMachineProfile.class),
--            ArgumentMatchers.any(DeploymentPlan.class),
--            ArgumentMatchers.any(ExcludeList.class),
--            ArgumentMatchers.anyInt()
++                ArgumentMatchers.any(VirtualMachineProfile.class),
++                ArgumentMatchers.any(DeploymentPlan.class),
++                ArgumentMatchers.any(ExcludeList.class),
++                ArgumentMatchers.anyInt()
          );
  
          Map<Volume, StoragePool> suitableVolumeStoragePoolMap = new HashMap<>() {{
@@@ -766,13 -864,13 +870,13 @@@
          Mockito.when(capacityMgr.checkIfHostReachMaxGuestLimit(host)).thenReturn(false);
          Mockito.when(capacityMgr.checkIfHostHasCpuCapability(ArgumentMatchers.anyLong(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(true);
          Mockito.when(capacityMgr.checkIfHostHasCapacity(
--            ArgumentMatchers.anyLong(),
--            ArgumentMatchers.anyInt(),
--            ArgumentMatchers.anyLong(),
--            ArgumentMatchers.anyBoolean(),
--            ArgumentMatchers.anyFloat(),
--            ArgumentMatchers.anyFloat(),
--            ArgumentMatchers.anyBoolean()
++                ArgumentMatchers.anyLong(),
++                ArgumentMatchers.anyInt(),
++                ArgumentMatchers.anyLong(),
++                ArgumentMatchers.anyBoolean(),
++                ArgumentMatchers.anyFloat(),
++                ArgumentMatchers.anyFloat(),
++                ArgumentMatchers.anyBoolean()
          )).thenReturn(true);
          Mockito.when(serviceOfferingDetailsDao.findDetail(vmProfile.getServiceOfferingId(), GPU.Keys.vgpuType.toString())).thenReturn(null);
  
@@@ -783,9 -881,9 +887,9 @@@
          DeploymentClusterPlanner planner = Mockito.spy(new FirstFitPlanner());
          try {
              Mockito.doReturn(List.of(clusterId), List.of()).when(planner).orderClusters(
--                ArgumentMatchers.any(VirtualMachineProfile.class),
--                ArgumentMatchers.any(DeploymentPlan.class),
--                ArgumentMatchers.any(ExcludeList.class)
++                    ArgumentMatchers.any(VirtualMachineProfile.class),
++                    ArgumentMatchers.any(DeploymentPlan.class),
++                    ArgumentMatchers.any(ExcludeList.class)
              );
          } catch (Exception ex) {
              ex.printStackTrace();
@@@ -803,7 -901,7 +907,8 @@@
          return dc;
      }
  
--    private void assertAvoidIsEmpty(ExcludeList avoids, boolean isDcEmpty, boolean isPodsEmpty, boolean isClustersEmpty, boolean isHostsEmpty) {
++    private void assertAvoidIsEmpty(ExcludeList avoids, boolean isDcEmpty, boolean isPodsEmpty, boolean isClustersEmpty,
++            boolean isHostsEmpty) {
          Assert.assertEquals(isDcEmpty, CollectionUtils.isEmpty(avoids.getDataCentersToAvoid()));
          Assert.assertEquals(isPodsEmpty, CollectionUtils.isEmpty(avoids.getPodsToAvoid()));
          Assert.assertEquals(isClustersEmpty, CollectionUtils.isEmpty(avoids.getClustersToAvoid()));
@@@ -811,8 -909,8 +916,9 @@@
      }
  
      @Configuration
--    @ComponentScan(basePackageClasses = {DeploymentPlanningManagerImpl.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class,
--                                                                                                         type = FilterType.CUSTOM)}, useDefaultFilters = false)
++    @ComponentScan(basePackageClasses = {DeploymentPlanningManagerImpl.class},
++                   includeFilters = {@Filter(value = TestConfiguration.Library.class,
++                                             type = FilterType.CUSTOM)}, useDefaultFilters = false)
      public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
  
          @Bean
@@@ -1080,84 -1178,4 +1186,85 @@@
          Assert.assertEquals(6, hosts.get(6).getId());
          Assert.assertEquals(2, hosts.get(7).getId());
      }
 +
-     private List<Long> prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(boolean configValue, boolean mockVolumes, boolean mockClusterStoreVolume) {
++    private List<Long> prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(boolean configValue,
++            boolean mockVolumes, boolean mockClusterStoreVolume) {
 +        try {
 +            Field f = ConfigKey.class.getDeclaredField("_defaultValue");
 +            f.setAccessible(true);
 +            f.set(ConfigurationManagerImpl.MIGRATE_VM_ACROSS_CLUSTERS, String.valueOf(configValue));
 +        } catch (NoSuchFieldException | IllegalAccessException e) {
 +            throw new RuntimeException(e);
 +        }
 +        List<Long> allClusters = List.of(101L, 102L, 103L, 104L);
 +        Mockito.when(_clusterDao.listAllClusters(Mockito.anyLong())).thenReturn(allClusters);
 +        if (mockVolumes) {
 +            VolumeVO vol1 = Mockito.mock(VolumeVO.class);
 +            Mockito.when(vol1.getPoolId()).thenReturn(1L);
 +            VolumeVO vol2 = Mockito.mock(VolumeVO.class);
 +            Mockito.when(vol2.getPoolId()).thenReturn(2L);
 +            StoragePoolVO pool1 = Mockito.mock(StoragePoolVO.class);
 +            Mockito.when(pool1.getScope()).thenReturn(ScopeType.ZONE);
 +            Mockito.when(primaryDataStoreDao.findById(1L)).thenReturn(pool1);
 +            StoragePoolVO pool2 = Mockito.mock(StoragePoolVO.class);
 +            Mockito.when(pool2.getScope()).thenReturn(mockClusterStoreVolume ? ScopeType.CLUSTER : ScopeType.GLOBAL);
 +            Mockito.when(primaryDataStoreDao.findById(2L)).thenReturn(pool2);
 +            Mockito.when(volDao.findUsableVolumesForInstance(1L)).thenReturn(List.of(vol1, vol2));
 +        } else {
 +            Mockito.when(volDao.findUsableVolumesForInstance(1L)).thenReturn(new ArrayList<>());
 +        }
 +        return allClusters;
 +    }
 +
 +    @Test
 +    public void avoidOtherClustersForDeploymentIfMigrationDisabledNonValidHost() {
 +        prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(false, false, false);
 +        VirtualMachine vm = Mockito.mock(VirtualMachine.class);
 +        ExcludeList excludeList = new ExcludeList();
 +        _dpm.avoidOtherClustersForDeploymentIfMigrationDisabled(vm, null, excludeList);
 +        Assert.assertTrue(CollectionUtils.isEmpty(excludeList.getClustersToAvoid()));
 +
 +        Host lastHost = Mockito.mock(Host.class);
 +        Mockito.when(lastHost.getClusterId()).thenReturn(null);
 +        _dpm.avoidOtherClustersForDeploymentIfMigrationDisabled(vm, lastHost, excludeList);
 +        Assert.assertTrue(CollectionUtils.isEmpty(excludeList.getClustersToAvoid()));
 +    }
 +
 +    private Set<Long> runAvoidOtherClustersForDeploymentIfMigrationDisabledTest() {
 +        VirtualMachine vm = Mockito.mock(VirtualMachine.class);
 +        Mockito.when(vm.getId()).thenReturn(1L);
 +        ExcludeList excludeList = new ExcludeList();
 +        Host lastHost = Mockito.mock(Host.class);
 +        Long sourceClusterId = 101L;
 +        Mockito.when(lastHost.getClusterId()).thenReturn(sourceClusterId);
 +        _dpm.avoidOtherClustersForDeploymentIfMigrationDisabled(vm, lastHost, excludeList);
 +        return excludeList.getClustersToAvoid();
 +    }
 +
 +    @Test
 +    public void avoidOtherClustersForDeploymentIfMigrationDisabledConfigAllows() {
-         prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(true,false, false);
++        prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(true, false, false);
 +        Assert.assertTrue(CollectionUtils.isEmpty(runAvoidOtherClustersForDeploymentIfMigrationDisabledTest()));
 +    }
 +
 +    @Test
 +    public void avoidOtherClustersForDeploymentIfMigrationDisabledNoVmVolumes() {
-         prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(false,false, false);
++        prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(false, false, false);
 +        Assert.assertTrue(CollectionUtils.isEmpty(runAvoidOtherClustersForDeploymentIfMigrationDisabledTest()));
 +    }
 +
 +    @Test
 +    public void avoidOtherClustersForDeploymentIfMigrationDisabledVmVolumesNonValidScope() {
-         prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(false,true, false);
++        prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(false, true, false);
 +        Assert.assertTrue(CollectionUtils.isEmpty(runAvoidOtherClustersForDeploymentIfMigrationDisabledTest()));
 +    }
 +
 +    @Test
 +    public void avoidOtherClustersForDeploymentIfMigrationDisabledValid() {
-         List<Long> allClusters = prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(false,true, true);
++        List<Long> allClusters = prepareMockForAvoidOtherClustersForDeploymentIfMigrationDisabled(false, true, true);
 +        Set<Long> avoidedClusters = runAvoidOtherClustersForDeploymentIfMigrationDisabledTest();
 +        Assert.assertTrue(CollectionUtils.isNotEmpty(avoidedClusters));
-         Assert.assertEquals(allClusters.size()-1, avoidedClusters.size());
++        Assert.assertEquals(allClusters.size() - 1, avoidedClusters.size());
 +        Assert.assertFalse(avoidedClusters.contains(allClusters.get(0)));
 +    }
  }
diff --cc server/src/test/java/com/cloud/storage/StorageManagerImplTest.java
index 8df824502cd,20e1be95e52..478547bff1e
--- a/server/src/test/java/com/cloud/storage/StorageManagerImplTest.java
+++ b/server/src/test/java/com/cloud/storage/StorageManagerImplTest.java
@@@ -16,11 -16,11 +16,13 @@@
  // under the License.
  package com.cloud.storage;
  
 -import java.util.ArrayList;
 -import java.util.List;
 -
 +import com.cloud.agent.api.StoragePoolInfo;
 +import com.cloud.host.Host;
 +import com.cloud.storage.dao.VolumeDao;
 +import com.cloud.vm.VMInstanceVO;
 +import com.cloud.vm.dao.VMInstanceDao;
+ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
  import org.junit.Assert;
  import org.junit.Test;
  import org.junit.runner.RunWith;