You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ha...@apache.org on 2023/05/31 11:58:46 UTC
[cloudstack] 15/23: Unit tests for volume livemigration in ScaleIOPrimaryDataStoreDriver
This is an automated email from the ASF dual-hosted git repository.
harikrishna pushed a commit to branch LiveStoragMigrationScaleIOMain
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit b543aeba5a042ea00f97fff23aa40a81f9547011
Author: Harikrishna Patnala <ha...@gmail.com>
AuthorDate: Thu Apr 6 13:54:45 2023 +0530
Unit tests for volume livemigration in ScaleIOPrimaryDataStoreDriver
---
.../driver/ScaleIOPrimaryDataStoreDriver.java | 16 +-
.../client/ScaleIOPrimaryDataStoreDriverTest.java | 351 ++++++++++++++++++++-
2 files changed, 355 insertions(+), 12 deletions(-)
diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java
index c16cdaa5f41..3d846de084d 100644
--- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java
+++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java
@@ -136,7 +136,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
}
- private ScaleIOGatewayClient getScaleIOClient(final Long storagePoolId) throws Exception {
+ public ScaleIOGatewayClient getScaleIOClient(final Long storagePoolId) throws Exception {
return ScaleIOGatewayClientConnectionPool.getInstance().getClient(storagePoolId, storagePoolDetailsDao);
}
@@ -448,7 +448,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
}
}
- private CreateObjectAnswer createVolume(VolumeInfo volumeInfo, long storagePoolId) {
+ public CreateObjectAnswer createVolume(VolumeInfo volumeInfo, long storagePoolId) {
LOGGER.debug("Creating PowerFlex volume");
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
@@ -687,7 +687,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
if (isSameScaleIOStorageInstance(srcStore, destStore)) {
answer = migrateVolume(srcData, destData);
} else {
- answer = copyVolume(srcData, destData, destHost);
+ answer = copyVolume(srcData, destData);
}
} else {
errMsg = "Unsupported copy operation from src object: (" + srcData.getType() + ", " + srcData.getDataStore() + "), dest object: ("
@@ -761,7 +761,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
return answer;
}
- private Answer copyVolume(DataObject srcData, DataObject destData, Host destHost) {
+ public Answer copyVolume(DataObject srcData, DataObject destData) {
// Volume migration across different PowerFlex/ScaleIO clusters
final long srcVolumeId = srcData.getId();
DataStore srcStore = srcData.getDataStore();
@@ -813,7 +813,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
return answer;
}
- private void updateVolumeAfterCopyVolume(DataObject srcData, DataObject destData) {
+ public void updateVolumeAfterCopyVolume(DataObject srcData, DataObject destData) {
// destination volume is already created and volume path is set in database by this time at "CreateObjectAnswer createAnswer = createVolume((VolumeInfo) destData, destStore.getId());"
final long srcVolumeId = srcData.getId();
final long destVolumeId = destData.getId();
@@ -850,7 +850,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
return host;
}
- private void updateSnapshotsAfterCopyVolume(DataObject srcData, DataObject destData) throws Exception {
+ public void updateSnapshotsAfterCopyVolume(DataObject srcData, DataObject destData) throws Exception {
final long srcVolumeId = srcData.getId();
DataStore srcStore = srcData.getDataStore();
final long srcPoolId = srcStore.getId();
@@ -884,7 +884,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
}
}
- private void deleteSourceVolumeAfterSuccessfulBlockCopy(DataObject srcData, Host host) {
+ public void deleteSourceVolumeAfterSuccessfulBlockCopy(DataObject srcData, Host host) {
DataStore srcStore = srcData.getDataStore();
String srcVolumePath = srcData.getTO().getPath();
revokeAccess(srcData, host, srcData.getDataStore());
@@ -903,7 +903,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
}
}
- private void revertBlockCopyVolumeOperations(DataObject srcData, DataObject destData, Host host, String destVolumePath) {
+ public void revertBlockCopyVolumeOperations(DataObject srcData, DataObject destData, Host host, String destVolumePath) {
final String srcVolumePath = ((VolumeInfo) srcData).getPath();
final String srcVolumeFolder = ((VolumeInfo) srcData).getFolder();
DataStore destStore = destData.getDataStore();
diff --git a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/client/ScaleIOPrimaryDataStoreDriverTest.java b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/client/ScaleIOPrimaryDataStoreDriverTest.java
index 4ed31e6d8c1..643bf9165b7 100644
--- a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/client/ScaleIOPrimaryDataStoreDriverTest.java
+++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/client/ScaleIOPrimaryDataStoreDriverTest.java
@@ -19,33 +19,84 @@
package org.apache.cloudstack.storage.datastore.driver.client;
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.storage.MigrateVolumeAnswer;
+import com.cloud.agent.api.to.DataTO;
+import com.cloud.agent.api.to.DiskTO;
+import com.cloud.configuration.Config;
+import com.cloud.host.Host;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.storage.Storage;
+import com.cloud.storage.Volume;
+import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.storage.dao.VolumeDetailsDao;
import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.dao.VMInstanceDao;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.storage.RemoteHostEndPoint;
+import org.apache.cloudstack.storage.command.CreateObjectAnswer;
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.datastore.driver.ScaleIOPrimaryDataStoreDriver;
+import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import java.util.Optional;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(RemoteHostEndPoint.class)
public class ScaleIOPrimaryDataStoreDriverTest {
@Spy
@InjectMocks
- ScaleIOPrimaryDataStoreDriver scaleIOPrimaryDataStoreDriver;
-
+ ScaleIOPrimaryDataStoreDriver scaleIOPrimaryDataStoreDriver = new ScaleIOPrimaryDataStoreDriver();
@Mock
StoragePoolDetailsDao storagePoolDetailsDao;
+ @Mock
+ PrimaryDataStoreDao storagePoolDao;
+ @Mock
+ VolumeDao volumeDao;
+ @Mock
+ VolumeDetailsDao volumeDetailsDao;
+ @Mock
+ VolumeService volumeService;
+ @Mock
+ VMInstanceDao vmInstanceDao;
+ @Mock
+ HostDao hostDao;
+ @Mock
+ ConfigurationDao configDao;
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
@Test
public void testSameScaleIOStorageInstance() {
DataStore srcStore = Mockito.mock(DataStore.class);
@@ -111,4 +162,296 @@ public class ScaleIOPrimaryDataStoreDriverTest {
scaleIOPrimaryDataStoreDriver.isSameScaleIOStorageInstance(srcStore, destStore);
}
+
+ @Test
+ public void testMigrateVolumeWithinSameScaleIOClusterSuccess() throws Exception {
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ VolumeInfo destData = Mockito.mock(VolumeInfo.class);
+
+ DataStore srcStore = Mockito.mock(DataStore.class);
+ DataStore destStore = Mockito.mock(DataStore.class);
+
+ when(srcData.getDataStore()).thenReturn(srcStore);
+ when(destData.getDataStore()).thenReturn(destStore);
+
+ fillSrcVolumeDetails(srcData, srcStore);
+ fillDestVolumeDetails(destData, destStore);
+
+ VolumeObjectTO destVolTO = Mockito.mock(VolumeObjectTO.class);
+ when(destData.getTO()).thenReturn(destVolTO);
+ Host host = prepareEndpointForVolumeOperation(srcData);
+ PowerMockito.mockStatic(RemoteHostEndPoint.class);
+ RemoteHostEndPoint ep = Mockito.mock(RemoteHostEndPoint.class);
+ when(RemoteHostEndPoint.getHypervisorHostEndPoint(host)).thenReturn(ep);
+
+ DataTO dataTO = Mockito.mock(DataTO.class);
+ CreateObjectAnswer createAnswer = new CreateObjectAnswer(dataTO);
+ doReturn(createAnswer).when(scaleIOPrimaryDataStoreDriver).createVolume(destData, 2L);
+ when(dataTO.getPath()).thenReturn("bec0ba7700000007:vol-11-6aef-10ee");
+ doReturn(true).when(scaleIOPrimaryDataStoreDriver)
+ .grantAccess(any(), any(), any());
+
+ when(configDao.getValue(Config.MigrateWait.key())).thenReturn("3600");
+ MigrateVolumeAnswer migrateVolumeAnswer = Mockito.mock(MigrateVolumeAnswer.class);
+ when(ep.sendMessage(any())).thenReturn(migrateVolumeAnswer);
+ when(migrateVolumeAnswer.getResult()).thenReturn(true);
+
+ Mockito.doNothing().when(scaleIOPrimaryDataStoreDriver)
+ .updateVolumeAfterCopyVolume(any(), any());
+ Mockito.doNothing().when(scaleIOPrimaryDataStoreDriver)
+ .updateSnapshotsAfterCopyVolume(any(), any());
+ Mockito.doNothing().when(scaleIOPrimaryDataStoreDriver)
+ .deleteSourceVolumeAfterSuccessfulBlockCopy(any(), any());
+
+ Answer answer = scaleIOPrimaryDataStoreDriver.copyVolume(srcData, destData);
+
+ Assert.assertTrue(answer.getResult());
+ }
+
+ @Test
+ public void testMigrateVolumeWithinSameScaleIOClusterFailure() throws Exception {
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ VolumeInfo destData = Mockito.mock(VolumeInfo.class);
+
+ DataStore srcStore = Mockito.mock(DataStore.class);
+ DataStore destStore = Mockito.mock(DataStore.class);
+
+ when(srcData.getDataStore()).thenReturn(srcStore);
+ when(destData.getDataStore()).thenReturn(destStore);
+
+ fillSrcVolumeDetails(srcData, srcStore);
+ fillDestVolumeDetails(destData, destStore);
+
+ VolumeObjectTO destVolTO = Mockito.mock(VolumeObjectTO.class);
+ when(destData.getTO()).thenReturn(destVolTO);
+ Host host = prepareEndpointForVolumeOperation(srcData);
+ PowerMockito.mockStatic(RemoteHostEndPoint.class);
+ RemoteHostEndPoint ep = Mockito.mock(RemoteHostEndPoint.class);
+ when(RemoteHostEndPoint.getHypervisorHostEndPoint(host)).thenReturn(ep);
+
+ DataTO dataTO = Mockito.mock(DataTO.class);
+ CreateObjectAnswer createAnswer = new CreateObjectAnswer(dataTO);
+ doReturn(createAnswer).when(scaleIOPrimaryDataStoreDriver).createVolume(destData, 2L);
+ when(dataTO.getPath()).thenReturn("bec0ba7700000007:vol-11-6aef-10ee");
+ doReturn(true).when(scaleIOPrimaryDataStoreDriver)
+ .grantAccess(any(), any(), any());
+
+ when(configDao.getValue(Config.MigrateWait.key())).thenReturn("3600");
+ MigrateVolumeAnswer migrateVolumeAnswer = Mockito.mock(MigrateVolumeAnswer.class);
+ when(ep.sendMessage(any())).thenReturn(migrateVolumeAnswer);
+ when(migrateVolumeAnswer.getResult()).thenReturn(false);
+ Mockito.doNothing().when(scaleIOPrimaryDataStoreDriver)
+ .revertBlockCopyVolumeOperations(any(), any(), any(), any());
+
+ Answer answer = scaleIOPrimaryDataStoreDriver.copyVolume(srcData, destData);
+
+ Assert.assertFalse(answer.getResult());
+ }
+
+ private void fillSrcVolumeDetails(VolumeInfo srcData, DataStore srcStore) {
+ when(srcStore.getId()).thenReturn(1L);
+ when(srcData.getId()).thenReturn(1L);
+
+ StoragePoolVO storagePoolVO = Mockito.mock(StoragePoolVO.class);
+ when(storagePoolDao.findById(1L)).thenReturn(storagePoolVO);
+ when(storagePoolVO.isManaged()).thenReturn(true);
+
+ VolumeVO volumeVO = Mockito.mock(VolumeVO.class);
+ when(volumeDao.findById(1L)).thenReturn(volumeVO);
+
+ when(volumeDetailsDao.findDetail(1L, DiskTO.SCSI_NAA_DEVICE_ID)).thenReturn(null);
+ when(volumeService.getChapInfo(srcData, srcStore)).thenReturn(null);
+
+ StoragePoolDetailVO srcStoragePoolDetail = Mockito.mock(StoragePoolDetailVO.class);
+ when(srcStoragePoolDetail.getValue()).thenReturn("610204d03e3ad60f");
+ when(storagePoolDetailsDao.findDetail(1L, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(srcStoragePoolDetail);
+ }
+
+ private void fillDestVolumeDetails(VolumeInfo srcData, DataStore srcStore) {
+ when(srcStore.getId()).thenReturn(2L);
+ when(srcData.getId()).thenReturn(2L);
+
+ StoragePoolVO storagePoolVO = Mockito.mock(StoragePoolVO.class);
+ when(storagePoolDao.findById(2L)).thenReturn(storagePoolVO);
+ when(storagePoolVO.isManaged()).thenReturn(true);
+
+ VolumeVO volumeVO = Mockito.mock(VolumeVO.class);
+ when(volumeDao.findById(2L)).thenReturn(volumeVO);
+
+ when(volumeDetailsDao.findDetail(2L, DiskTO.SCSI_NAA_DEVICE_ID)).thenReturn(null);
+ when(volumeService.getChapInfo(srcData, srcStore)).thenReturn(null);
+
+ StoragePoolDetailVO srcStoragePoolDetail = Mockito.mock(StoragePoolDetailVO.class);
+ when(srcStoragePoolDetail.getValue()).thenReturn("7332760565f6340f");
+ when(storagePoolDetailsDao.findDetail(2L, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(srcStoragePoolDetail);
+ }
+
+ private Host prepareEndpointForVolumeOperation(VolumeInfo srcData) {
+ VMInstanceVO instance = Mockito.mock(VMInstanceVO.class);
+ when(srcData.getAttachedVmName()).thenReturn("i-2-VM");
+ when(vmInstanceDao.findVMByInstanceName("i-2-VM")).thenReturn(instance);
+ when(instance.getHostId()).thenReturn(4L);
+ when(instance.getState()).thenReturn(VirtualMachine.State.Running);
+ HostVO host = Mockito.mock(HostVO.class);
+ when(hostDao.findById(4L)).thenReturn(host);
+
+ return host;
+ }
+
+ @Test
+ public void updateVolumeAfterCopyVolumeLiveMigrate() {
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ VolumeInfo destData = Mockito.mock(VolumeInfo.class);
+
+ when(srcData.getId()).thenReturn(1L);
+ when(destData.getId()).thenReturn(1L);
+
+ VolumeVO volume = new VolumeVO("root", 1L, 1L, 1L, 1L, 1L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
+ volume.setPoolId(2L);
+ when(volumeDao.findById(1L)).thenReturn(volume);
+ when(volumeDao.update(1L, volume)).thenReturn(true);
+
+ scaleIOPrimaryDataStoreDriver.updateVolumeAfterCopyVolume(srcData, destData);
+
+ Assert.assertEquals(Optional.of(2L), Optional.of(volume.getLastPoolId()));
+ }
+
+ @Test
+ public void updateVolumeAfterCopyVolumeOffline() {
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ VolumeInfo destData = Mockito.mock(VolumeInfo.class);
+
+ when(srcData.getId()).thenReturn(1L);
+ when(destData.getId()).thenReturn(2L);
+
+ VolumeVO volume = new VolumeVO("root", 1L, 1L, 1L, 1L, 1L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
+ when(volumeDao.findById(1L)).thenReturn(volume);
+ when(volumeDao.update(1L, volume)).thenReturn(true);
+
+ scaleIOPrimaryDataStoreDriver.updateVolumeAfterCopyVolume(srcData, destData);
+
+ Assert.assertNull(volume.get_iScsiName());
+ Assert.assertNull(volume.getPath());
+ Assert.assertNull(volume.getFolder());
+ }
+
+ @Test
+ public void revertBlockCopyVolumeOperationsOnDeleteSuccess() throws Exception{
+ //Either destination volume delete success or failure, DB operations should get revert
+
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ VolumeInfo destData = Mockito.mock(VolumeInfo.class);
+ Host host = Mockito.mock(Host.class);
+ String destVolumePath = "01b332b300000007:vol-11-b9e2-10ee";
+
+ when(srcData.getId()).thenReturn(1L);
+ when(srcData.getPoolId()).thenReturn(1L);
+ when(destData.getId()).thenReturn(1L);
+
+ when(srcData.getPath()).thenReturn("bec0ba7700000007:vol-11-6aef-10ee");
+ when(srcData.getFolder()).thenReturn("921c364500000007");
+ DataStore destStore = Mockito.mock(DataStore.class);
+ when(destStore.getId()).thenReturn(2L);
+ when(destData.getDataStore()).thenReturn(destStore);
+ doNothing().when(scaleIOPrimaryDataStoreDriver)
+ .revokeAccess(any(), any(), any());
+
+ ScaleIOGatewayClient client = Mockito.mock(ScaleIOGatewayClient.class);
+ doReturn(client).when(scaleIOPrimaryDataStoreDriver)
+ .getScaleIOClient(any());
+ when(client.deleteVolume(any())).thenReturn(true);
+
+ VolumeVO volume = new VolumeVO("root", 1L, 1L, 1L, 1L, 1L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
+ when(volumeDao.findById(1L)).thenReturn(volume);
+ when(volumeDao.update(1L, volume)).thenReturn(true);
+
+ scaleIOPrimaryDataStoreDriver.revertBlockCopyVolumeOperations(srcData, destData, host, destVolumePath);
+
+ Assert.assertEquals("bec0ba7700000007:vol-11-6aef-10ee", volume.get_iScsiName());
+ Assert.assertEquals("bec0ba7700000007:vol-11-6aef-10ee", volume.getPath());
+ Assert.assertEquals("921c364500000007", volume.getFolder());
+ }
+
+ @Test
+ public void revertBlockCopyVolumeOperationsOnDeleteFailure() throws Exception{
+ //Either destination volume delete success or failure, DB operations should get revert
+
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ VolumeInfo destData = Mockito.mock(VolumeInfo.class);
+ Host host = Mockito.mock(Host.class);
+ String srcVolumePath = "bec0ba7700000007:vol-11-6aef-10ee";
+ String destVolumePath = "01b332b300000007:vol-11-b9e2-10ee";
+
+ when(srcData.getId()).thenReturn(1L);
+ when(srcData.getPoolId()).thenReturn(1L);
+ when(destData.getId()).thenReturn(1L);
+
+ when(srcData.getPath()).thenReturn(srcVolumePath);
+ when(srcData.getFolder()).thenReturn("921c364500000007");
+ DataStore destStore = Mockito.mock(DataStore.class);
+ when(destStore.getId()).thenReturn(2L);
+ when(destData.getDataStore()).thenReturn(destStore);
+ doNothing().when(scaleIOPrimaryDataStoreDriver).revokeAccess(any(), any(), any());
+
+ ScaleIOGatewayClient client = Mockito.mock(ScaleIOGatewayClient.class);
+ doReturn(client).when(scaleIOPrimaryDataStoreDriver)
+ .getScaleIOClient(any());
+ when(client.deleteVolume(any())).thenReturn(false);
+
+ VolumeVO volume = new VolumeVO("root", 1L, 1L, 1L, 1L, 1L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
+ when(volumeDao.findById(1L)).thenReturn(volume);
+ when(volumeDao.update(1L, volume)).thenReturn(true);
+
+ scaleIOPrimaryDataStoreDriver.revertBlockCopyVolumeOperations(srcData, destData, host, destVolumePath);
+
+ Assert.assertEquals(srcVolumePath, volume.get_iScsiName());
+ Assert.assertEquals(srcVolumePath, volume.getPath());
+ Assert.assertEquals("921c364500000007", volume.getFolder());
+ }
+
+ @Test
+ public void deleteSourceVolumeSuccessScenarioAfterSuccessfulBlockCopy() throws Exception {
+ // Either Volume deletion success or failure method should complete
+
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ Host host = Mockito.mock(Host.class);
+ String srcVolumePath = "bec0ba7700000007:vol-11-6aef-10ee";
+
+ DataStore srcStore = Mockito.mock(DataStore.class);
+ DataTO volumeTO = Mockito.mock(DataTO.class);
+ when(srcData.getDataStore()).thenReturn(srcStore);
+ when(srcData.getTO()).thenReturn(volumeTO);
+ when(volumeTO.getPath()).thenReturn(srcVolumePath);
+ doNothing().when(scaleIOPrimaryDataStoreDriver).revokeAccess(any(), any(), any());
+
+ ScaleIOGatewayClient client = Mockito.mock(ScaleIOGatewayClient.class);
+ doReturn(client).when(scaleIOPrimaryDataStoreDriver)
+ .getScaleIOClient(any());
+ when(client.deleteVolume(any())).thenReturn(true);
+
+ scaleIOPrimaryDataStoreDriver.deleteSourceVolumeAfterSuccessfulBlockCopy(srcData, host);
+ }
+
+ @Test
+ public void deleteSourceVolumeFailureScenarioAfterSuccessfulBlockCopy() throws Exception {
+ // Either Volume deletion success or failure method should complete
+
+ VolumeInfo srcData = Mockito.mock(VolumeInfo.class);
+ Host host = Mockito.mock(Host.class);
+ String srcVolumePath = "bec0ba7700000007:vol-11-6aef-10ee";
+
+ DataStore srcStore = Mockito.mock(DataStore.class);
+ DataTO volumeTO = Mockito.mock(DataTO.class);
+ when(srcData.getDataStore()).thenReturn(srcStore);
+ when(srcData.getTO()).thenReturn(volumeTO);
+ when(volumeTO.getPath()).thenReturn(srcVolumePath);
+ doNothing().when(scaleIOPrimaryDataStoreDriver).revokeAccess(any(), any(), any());
+
+ ScaleIOGatewayClient client = Mockito.mock(ScaleIOGatewayClient.class);
+ doReturn(client).when(scaleIOPrimaryDataStoreDriver)
+ .getScaleIOClient(any());
+ when(client.deleteVolume(any())).thenReturn(false);
+
+ scaleIOPrimaryDataStoreDriver.deleteSourceVolumeAfterSuccessfulBlockCopy(srcData, host);
+ }
}
\ No newline at end of file