diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java index 90696cae806..2fc701a1214 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java @@ -22,6 +22,12 @@ import java.util.UUID; import javax.inject.Inject; +import com.cloud.configuration.Config; +import com.cloud.configuration.ConfigurationVO; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.user.Account; +import com.cloud.utils.db.DB; +import com.cloud.vm.VMInstanceVO; import junit.framework.Assert; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; @@ -87,6 +93,8 @@ public class StorageAllocatorTest { StoragePoolDetailsDao poolDetailsDao; @Inject DataStoreProviderManager providerMgr; + @Inject + ConfigurationDao configDao; Long dcId = 1l; Long podId = 1l; Long clusterId = 1l; @@ -98,7 +106,13 @@ public class StorageAllocatorTest { StoragePoolVO storage = null; @Before + @DB public void setup() throws Exception { + ConfigurationVO cfg = configDao.findByName(Config.VmAllocationAlgorithm.key()); + if (cfg == null) { + ConfigurationVO configVO = new ConfigurationVO("test", "DEFAULT", "test", Config.VmAllocationAlgorithm.key(), "userdispersing", null); + configDao.persist(configVO); + } ComponentContext.initComponentsLifeCycle(); } @@ -120,7 +134,7 @@ public class StorageAllocatorTest { cluster = clusterDao.persist(cluster); clusterId = cluster.getId(); - DataStoreProvider provider = providerMgr.getDataStoreProvider("cloudstack primary data store provider"); + DataStoreProvider provider = providerMgr.getDataStoreProvider(DataStoreProvider.DEFAULT_PRIMARY); storage = new StoragePoolVO(); storage.setDataCenterId(dcId); storage.setPodId(podId); @@ -163,7 +177,7 @@ public class StorageAllocatorTest { try { createDb(); - DataStoreProvider provider = providerMgr.getDataStoreProvider("cloudstack primary data store provider"); + DataStoreProvider provider = providerMgr.getDataStoreProvider(DataStoreProvider.DEFAULT_PRIMARY); storage = new StoragePoolVO(); storage.setDataCenterId(dcId); storage.setPodId(podId); @@ -312,7 +326,10 @@ public class StorageAllocatorTest { createDb(); StoragePoolVO pool = storagePoolDao.findById(storagePoolId); + pool.setHypervisor(HypervisorType.KVM); pool.setScope(ScopeType.ZONE); + pool.setClusterId(null); + pool.setPodId(null); storagePoolDao.update(pool.getId(), pool); DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.KVM); @@ -321,6 +338,8 @@ public class StorageAllocatorTest { Mockito.when( storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true); + Mockito.when(storageMgr.storagePoolHasEnoughIops(Matchers.anyListOf(Volume.class), + Matchers.any(StoragePool.class))).thenReturn(true); DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null); int foundAcct = 0; for (StoragePoolAllocator allocator : allocators) { @@ -340,6 +359,49 @@ public class StorageAllocatorTest { } } + @Test + public void testCLOUDSTACK3481() { + try { + createDb(); + + StoragePoolVO pool = storagePoolDao.findById(storagePoolId); + pool.setHypervisor(HypervisorType.KVM); + pool.setScope(ScopeType.ZONE); + pool.setClusterId(null); + pool.setPodId(null); + storagePoolDao.update(pool.getId(), pool); + + + DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.KVM); + VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class); + Account account = Mockito.mock(Account.class); + Mockito.when(account.getAccountId()).thenReturn(1L); + Mockito.when(vmProfile.getHypervisorType()).thenReturn(HypervisorType.KVM); + Mockito.when(vmProfile.getOwner()).thenReturn(account); + Mockito.when( + storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), + Matchers.any(StoragePool.class))).thenReturn(true); + Mockito.when(storageMgr.storagePoolHasEnoughIops(Matchers.anyListOf(Volume.class), + Matchers.any(StoragePool.class))).thenReturn(true); + DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null); + int foundAcct = 0; + for (StoragePoolAllocator allocator : allocators) { + List pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1); + if (!pools.isEmpty()) { + Assert.assertEquals(pools.get(0).getId(), storage.getId()); + foundAcct++; + } + } + + if (foundAcct > 1 || foundAcct == 0) { + Assert.fail(); + } + } catch (Exception e) { + cleanDb(); + Assert.fail(); + } + } + @Test public void testPoolStateIsNotUp() { try { diff --git a/engine/storage/integration-test/test/resource/storageContext.xml b/engine/storage/integration-test/test/resource/storageContext.xml index f9c891a036f..664f1e3a290 100644 --- a/engine/storage/integration-test/test/resource/storageContext.xml +++ b/engine/storage/integration-test/test/resource/storageContext.xml @@ -47,7 +47,6 @@ - @@ -62,7 +61,6 @@ - @@ -82,7 +80,6 @@ - diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorStorageProcessor.java b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorStorageProcessor.java index 12c273368c7..c7768aa5b69 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorStorageProcessor.java +++ b/plugins/hypervisors/simulator/src/com/cloud/resource/SimulatorStorageProcessor.java @@ -72,12 +72,20 @@ public class SimulatorStorageProcessor implements StorageProcessor { @Override public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) { - return null; + VolumeObjectTO volume = new VolumeObjectTO(); + volume.setPath(UUID.randomUUID().toString()); + volume.setSize(100); + volume.setFormat(Storage.ImageFormat.RAW); + return new CopyCmdAnswer(volume); } @Override public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) { - return null; + VolumeObjectTO volume = new VolumeObjectTO(); + volume.setPath(UUID.randomUUID().toString()); + volume.setSize(100); + volume.setFormat(Storage.ImageFormat.RAW); + return new CopyCmdAnswer(volume); } @Override