mirror of https://github.com/apache/cloudstack.git
Merge ea1712bb6b into b7d4df0a11
This commit is contained in:
commit
7536ff3a59
|
|
@ -44,6 +44,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
|
|||
|
||||
List<VolumeVO> findByInstance(long id);
|
||||
|
||||
List<VolumeVO> findByInstanceAndNotDestroyed(long id);
|
||||
|
||||
List<VolumeVO> findByInstanceAndType(long id, Volume.Type vType);
|
||||
|
||||
List<VolumeVO> findByInstanceAndNotStates(long id, Volume.State...states);
|
||||
|
|
|
|||
|
|
@ -132,6 +132,14 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> findByInstanceAndNotDestroyed(long id) {
|
||||
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("instanceId", id);
|
||||
sc.setParameters("notDestroyed", Volume.State.Destroy, Volume.State.Expunged);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VolumeVO> findByInstanceAndDeviceId(long instanceId, long deviceId) {
|
||||
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
|
||||
|
|
|
|||
|
|
@ -7347,7 +7347,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
|
||||
public boolean isVMUsingLocalStorage(VMInstanceVO vm) {
|
||||
List<VolumeVO> volumes = _volsDao.findByInstance(vm.getId());
|
||||
List<VolumeVO> volumes = _volsDao.findByInstanceAndNotDestroyed(vm.getId());
|
||||
return isAnyVmVolumeUsingLocalStorage(volumes);
|
||||
}
|
||||
|
||||
|
|
@ -7783,10 +7783,20 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
protected boolean isAnyVmVolumeUsingLocalStorage(final List<VolumeVO> volumes) {
|
||||
for (VolumeVO vol : volumes) {
|
||||
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId());
|
||||
if (diskOffering.isUseLocalStorage()) {
|
||||
if (diskOffering != null && diskOffering.isUseLocalStorage()) {
|
||||
return true;
|
||||
}
|
||||
StoragePoolVO storagePool = _storagePoolDao.findById(vol.getPoolId());
|
||||
Long poolId = vol.getPoolId();
|
||||
if (poolId == null) {
|
||||
logger.debug("Skipping volume without storage pool while checking local storage usage: {}", vol);
|
||||
continue;
|
||||
}
|
||||
StoragePoolVO storagePool = _storagePoolDao.findById(poolId);
|
||||
if (storagePool == null || storagePool.getRemoved() != null) {
|
||||
throw new CloudRuntimeException(String.format(
|
||||
"Cannot determine local storage usage for active volume %s because storage pool ID %s is missing or removed",
|
||||
vol, poolId));
|
||||
}
|
||||
if (storagePool.isLocal()) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1252,6 +1252,38 @@ public class UserVmManagerImplTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAnyVmVolumeUsingLocalStorageFailsForActiveVolumeWithMissingPool() {
|
||||
VolumeVO volume = Mockito.mock(VolumeVO.class);
|
||||
Mockito.when(volume.getDiskOfferingId()).thenReturn(1L);
|
||||
Mockito.when(volume.getPoolId()).thenReturn(2L);
|
||||
DiskOfferingVO diskOffering = Mockito.mock(DiskOfferingVO.class);
|
||||
Mockito.when(diskOfferingDao.findById(1L)).thenReturn(diskOffering);
|
||||
Mockito.when(diskOffering.isUseLocalStorage()).thenReturn(false);
|
||||
Mockito.when(primaryDataStoreDao.findById(2L)).thenReturn(null);
|
||||
|
||||
CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, () ->
|
||||
userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(Collections.singletonList(volume)));
|
||||
Assert.assertTrue(exception.getMessage().contains("storage pool ID 2 is missing or removed"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAnyVmVolumeUsingLocalStorageFailsForActiveVolumeWithRemovedPool() {
|
||||
VolumeVO volume = Mockito.mock(VolumeVO.class);
|
||||
Mockito.when(volume.getDiskOfferingId()).thenReturn(1L);
|
||||
Mockito.when(volume.getPoolId()).thenReturn(2L);
|
||||
DiskOfferingVO diskOffering = Mockito.mock(DiskOfferingVO.class);
|
||||
Mockito.when(diskOfferingDao.findById(1L)).thenReturn(diskOffering);
|
||||
Mockito.when(diskOffering.isUseLocalStorage()).thenReturn(false);
|
||||
StoragePoolVO storagePool = Mockito.mock(StoragePoolVO.class);
|
||||
Mockito.when(storagePool.getRemoved()).thenReturn(new Date());
|
||||
Mockito.when(primaryDataStoreDao.findById(2L)).thenReturn(storagePool);
|
||||
|
||||
CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, () ->
|
||||
userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(Collections.singletonList(volume)));
|
||||
Assert.assertTrue(exception.getMessage().contains("storage pool ID 2 is missing or removed"));
|
||||
}
|
||||
|
||||
private List<VolumeVO> mockVolumesForIsAllVmVolumesOnZoneWideStore(int nullPoolIdVolumes, int nullPoolVolumes, int zoneVolumes, int nonZoneVolumes) {
|
||||
List<VolumeVO> volumes = new ArrayList<>();
|
||||
for (int i=0; i< nullPoolIdVolumes + nullPoolVolumes + zoneVolumes + nonZoneVolumes; ++i) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue