Maor Lipchuk has uploaded a new change for review. Change subject: core: Validate the return value of an internal query. ......................................................................
core: Validate the return value of an internal query. Use the internal query return value to check if it has been succeeded or failed when calling getExistingStorageDomainList, so we can be sure that the return object value is a list and not null in case of a failure. Change-Id: I7a4ddd8f0e290981f1d583dfdb1722f7864b1f6d Signed-off-by: Maor Lipchuk <mlipc...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQuery.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQueryTest.java 2 files changed, 49 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/37272/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQuery.java index 270d9c4..8f19786 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQuery.java @@ -31,23 +31,26 @@ protected List<StorageDomainStatic> getStorageDomainsByStorageServerConnections(StorageServerConnections storageServerConnection) { List<StorageDomainStatic> storageDomainsWithAttachedStoragePoolId = new ArrayList<>(); - List<StorageDomain> existingStorageDomains = getExistingStorageDomainList(storageServerConnection); - if (!existingStorageDomains.isEmpty()) { - StorageDomain storageDomain = existingStorageDomains.get(0); - if (storageDomain.getStoragePoolId() != null) { - storageDomainsWithAttachedStoragePoolId.add(storageDomain.getStorageStaticData()); + VdcQueryReturnValue returnValue = getExistingStorageDomainList(storageServerConnection); + if (returnValue.getSucceeded()) { + List<StorageDomain> existingStorageDomains = returnValue.getReturnValue(); + if (!existingStorageDomains.isEmpty()) { + StorageDomain storageDomain = existingStorageDomains.get(0); + if (storageDomain.getStoragePoolId() != null) { + storageDomainsWithAttachedStoragePoolId.add(storageDomain.getStorageStaticData()); + } } } return storageDomainsWithAttachedStoragePoolId; } - protected List<StorageDomain> getExistingStorageDomainList(StorageServerConnections storageServerConnection) { + protected VdcQueryReturnValue getExistingStorageDomainList(StorageServerConnections storageServerConnection) { VdcQueryReturnValue returnValue = getBackend().runInternalQuery(VdcQueryType.GetExistingStorageDomainList, new GetExistingStorageDomainListParameters( getVdsId(), storageServerConnection.getstorage_type(), StorageDomainType.Data, storageServerConnection.getconnection())); - return returnValue.getReturnValue(); + return returnValue; } } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQueryTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQueryTest.java index cfe688d..b083b59 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQueryTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/GetFileStorageDomainsWithAttachedStoragePoolGuidQueryTest.java @@ -24,6 +24,7 @@ import org.ovirt.engine.core.common.businessentities.VDSStatus; import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend; import org.ovirt.engine.core.common.queries.StorageDomainsAndStoragePoolIdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; @@ -190,7 +191,36 @@ when(paramsMock.getStorageServerConnection()).thenReturn(storageServerConnections); List<StorageDomain> storageDomains = new ArrayList<>(); - doReturn(storageDomains).when(getQuery()).getExistingStorageDomainList(eq(storageServerConnections)); + VdcQueryReturnValue vdcReturnValue = new VdcQueryReturnValue(); + vdcReturnValue.setSucceeded(true); + vdcReturnValue.setReturnValue(storageDomains); + doReturn(vdcReturnValue).when(getQuery()).getExistingStorageDomainList(eq(storageServerConnections)); + + // Execute command + getQuery().executeQueryCommand(); + + // Assert the query's results + List<StorageDomainStatic> returnedStorageDomainList = new ArrayList<>(); + assertEquals(returnedStorageDomainList, getQuery().getQueryReturnValue().getReturnValue()); + } + + @Test + public void testFetchUsingStorageServerConnectionWithFailedInternalQuery() { + mockVdsCommand(); + StoragePool storagePool = new StoragePool(); + storagePool.setStatus(StoragePoolStatus.Up); + mockStoragePoolDao(storagePool); + + // Create parameters + StorageDomainsAndStoragePoolIdQueryParameters paramsMock = getQueryParameters(); + when(paramsMock.getStorageDomainList()).thenReturn(null); + StorageServerConnections storageServerConnections = new StorageServerConnections(); + when(paramsMock.getStorageServerConnection()).thenReturn(storageServerConnections); + + VdcQueryReturnValue vdcReturnValue = new VdcQueryReturnValue(); + vdcReturnValue.setSucceeded(false); + vdcReturnValue.setReturnValue(null); + doReturn(vdcReturnValue).when(getQuery()).getExistingStorageDomainList(eq(storageServerConnections)); // Execute command getQuery().executeQueryCommand(); @@ -219,7 +249,10 @@ List<StorageDomain> storageDomains = new ArrayList<>(); storageDomains.add(mockedStorageDomain); - doReturn(storageDomains).when(getQuery()).getExistingStorageDomainList(eq(storageServerConnection)); + VdcQueryReturnValue vdcReturnValue = new VdcQueryReturnValue(); + vdcReturnValue.setSucceeded(true); + vdcReturnValue.setReturnValue(storageDomains); + doReturn(vdcReturnValue).when(getQuery()).getExistingStorageDomainList(eq(storageServerConnection)); // Execute command getQuery().executeQueryCommand(); @@ -248,7 +281,10 @@ List<StorageDomain> storageDomains = new ArrayList<>(); storageDomains.add(mockedStorageDomain); - doReturn(storageDomains).when(getQuery()).getExistingStorageDomainList(eq(storageServerConnections)); + VdcQueryReturnValue vdcReturnValue = new VdcQueryReturnValue(); + vdcReturnValue.setSucceeded(true); + vdcReturnValue.setReturnValue(storageDomains); + doReturn(vdcReturnValue).when(getQuery()).getExistingStorageDomainList(eq(storageServerConnections)); // Execute command getQuery().executeQueryCommand(); -- To view, visit http://gerrit.ovirt.org/37272 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7a4ddd8f0e290981f1d583dfdb1722f7864b1f6d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Maor Lipchuk <mlipc...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches