mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-4325: add more test cases for zone wide storage pool allocator
This commit is contained in:
parent
a03c5f5b1b
commit
b359152679
|
|
@ -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<StoragePool> 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 {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@
|
|||
<bean id="LocalStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.LocalStoragePoolAllocator"/>
|
||||
<bean id="clusterScopeStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.ClusterScopeStoragePoolAllocator" />
|
||||
<bean id="zoneWideStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.ZoneWideStoragePoolAllocator" />
|
||||
<bean id="garbageCollectingStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.GarbageCollectingStoragePoolAllocator"/>
|
||||
<bean id="dataStoreProviderManagerImpl" class="org.apache.cloudstack.storage.datastore.provider.DataStoreProviderManagerImpl" />
|
||||
<bean id="ancientDataMotionStrategy" class="org.apache.cloudstack.storage.motion.AncientDataMotionStrategy" />
|
||||
<bean id="storageCacheManagerImpl" class="org.apache.cloudstack.storage.cache.manager.StorageCacheManagerImpl" />
|
||||
|
|
@ -62,7 +61,6 @@
|
|||
<bean id="iSCSI" class="org.apache.cloudstack.storage.datastore.type.ISCSI" />
|
||||
<bean id="ISO" class="org.apache.cloudstack.storage.image.format.ISO" />
|
||||
<bean id="templateDataFactoryImpl" class="org.apache.cloudstack.storage.image.TemplateDataFactoryImpl" />
|
||||
<bean id="imageDataManagerImpl" class="org.apache.cloudstack.storage.image.manager.ImageDataManagerImpl" />
|
||||
<bean id="imageStoreHelper" class="org.apache.cloudstack.storage.image.datastore.ImageStoreHelper" />
|
||||
<bean id="imageFormatHelper" class="org.apache.cloudstack.storage.image.format.ImageFormatHelper" />
|
||||
<bean id="templateServiceImpl" class="org.apache.cloudstack.storage.image.TemplateServiceImpl" />
|
||||
|
|
@ -82,7 +80,6 @@
|
|||
<bean id="cloudStackImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.CloudStackImageStoreProviderImpl" />
|
||||
<bean id="s3ImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.S3ImageStoreProviderImpl" />
|
||||
<bean id="swiftImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.SwiftImageStoreProviderImpl" />
|
||||
<bean id="simulatorImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.SimulatorImageStoreProviderImpl" />
|
||||
<bean id="BAREMETAL" class="org.apache.cloudstack.storage.image.format.BAREMETAL" />
|
||||
<bean id="storagePoolAutomationImpl" class="com.cloud.storage.StoragePoolAutomationImpl" />
|
||||
<bean id="AccountGuestVlanMapDaoImpl" class="com.cloud.network.dao.AccountGuestVlanMapDaoImpl" />
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue