mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: Check for null poolid (#6879)
Extract retrieveDatastore method Add unit test for null poolId Fixes #6878 Co-authored-by: Craig Squire <craig.squire@ticketmaster.com> Co-authored-by: Stephan Krug <stekrug@icloud.com>
This commit is contained in:
parent
6c436ec90e
commit
dbc2032077
@ -318,8 +318,10 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
|
||||
private void informStoragePoolForVmTags(long vmId, String key, String value) {
|
||||
List<VolumeVO> volumeVos = volumeDao.findByInstance(vmId);
|
||||
for (VolumeVO volume : volumeVos) {
|
||||
DataStore dataStore = dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary);
|
||||
Long poolId = volume.getPoolId();
|
||||
DataStore dataStore = retrieveDatastore(poolId);
|
||||
if (dataStore == null || !(dataStore.getDriver() instanceof PrimaryDataStoreDriver)) {
|
||||
s_logger.info(String.format("No data store found for VM %d with pool ID %d.", vmId, poolId));
|
||||
continue;
|
||||
}
|
||||
PrimaryDataStoreDriver dataStoreDriver = (PrimaryDataStoreDriver) dataStore.getDriver();
|
||||
@ -328,4 +330,11 @@ public class TaggedResourceManagerImpl extends ManagerBase implements TaggedReso
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected DataStore retrieveDatastore(Long poolId) {
|
||||
if (poolId == null) {
|
||||
return null;
|
||||
}
|
||||
return dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -123,4 +124,10 @@ public class TaggedResourceManagerImplTest extends TestCase {
|
||||
Mockito.doThrow(PermissionDeniedException.class).when(accountManager).checkAccess(caller, null, false, owner);
|
||||
taggedResourceManagerImplSpy.checkTagsDeletePermission(List.of(resourceTag1, resourceTag2), caller);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveDataStoreNullPoolId() {
|
||||
DataStore dataStore = taggedResourceManagerImplSpy.retrieveDatastore(null);
|
||||
Assert.assertNull(dataStore);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user