From 2c4d1f095ffe0c86e29f120c9a2f0e90cbbf0512 Mon Sep 17 00:00:00 2001 From: sandeeplocharla <85344604+sandeeplocharla@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:47:39 +0530 Subject: [PATCH] CSTACKEX-262: Support for Compute + Volume migration and Volume migration (#112) This PR... - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [X] New feature (non-breaking change which adds functionality) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Enhancement (improves an existing feature and functionality) - [ ] Cleanup (Code refactoring and cleanup, that may add test cases) - [ ] Build/CI - [X] Test (unit or integration test code) - [X] Major - [ ] Minor - [ ] BLOCKER - [ ] Critical - [ ] Major - [ ] Minor - [ ] Trivial | Use case | Suite | Tests | Result | | --- | --- | --- | --- | | Live VM migration with volumes | migration_live | 22 | Pass | | Stopped VM storage migration | migration_stopped | 15 | Pass | | Volume migration (detached or stopped-attached) | migration_volume | 23 | Pass | | iSCSI pool lifecycle | iscsi_pool_lifecycle | 8 | Pass | | iSCSI pool with volumes | iscsi_pool_volumes | 7 | Pass | | iSCSI zone-scoped pool | iscsi_zone_pool | 4 | Pass | | iSCSI volume lifecycle | iscsi_volume | 5 | Pass | | iSCSI VM volume attach | iscsi_instance | 8 | Pass | | NFS3 pool lifecycle | nfs3_pool_lifecycle | 8 | Pass | | NFS3 pool with volumes | nfs3_pool_volumes | 7 | Pass | | NFS3 zone-scoped pool | nfs3_zone_pool | 4 | Pass | | NFS3 volume lifecycle | nfs3_volume | 5 | Pass | | NFS3 VM volume attach | nfs3_instance | 8 | Pass | | Test | What it covers | Status | | --- | --- | --- | | test_01_nfs3_default_primary_to_cluster | DefaultPrimary root and data volumes to NFS3 C1a | Pass | | test_02_nfs3_cluster_to_cluster | NFS3 C1a to C1b | Pass | | test_03_nfs3_cluster_to_zone | NFS3 C1b to zone-wide Z1 | Pass | | test_04_nfs3_zone_to_zone | NFS3 Z1 to Z2 | Pass | | test_05_nfs3_zone_to_cluster | NFS3 Z2 back to C1a | Pass | | test_06_iscsi_default_primary_to_cluster | DefaultPrimary root and data volumes to iSCSI C1a | Pass | | test_07_iscsi_cluster_to_cluster | iSCSI C1a to C1b | Pass | | test_08_iscsi_cluster_to_zone | iSCSI C1b to Z1 | Pass | | test_09_iscsi_zone_to_zone | iSCSI Z1 to Z2 | Pass | | test_10_iscsi_zone_to_cluster | iSCSI Z2 back to C1a | Pass | | test_11_reject_nfs3_to_iscsi | Live NFS3-to-iSCSI mapping is rejected | Pass | | test_12_reject_iscsi_to_nfs3 | Live iSCSI-to-NFS3 mapping is rejected | Pass | | test_13_reject_live_volume_only | `migrateVolume` with livemigrate on a running volume is rejected | Pass | | test_14_nfs3_cluster_to_cluster | After host split, NFS3 C1a to C2 | Pass | | test_15_nfs3_cluster_to_zone | NFS3 C1a to Z1 onto a C2 host | Pass | | test_16_nfs3_zone_to_cluster | NFS3 Z1 to C2 | Pass | | test_17_nfs3_zone_to_zone | NFS3 Z1 to Z2 onto a C2 host | Pass | | test_18_iscsi_cluster_to_cluster | iSCSI C1a to C2 onto a C2 host | Pass | | test_19_iscsi_cluster_to_zone | iSCSI C1a to Z1 onto a C2 host | Pass | | test_20_iscsi_zone_to_cluster | iSCSI Z1 to C2 | Pass | | test_21_iscsi_zone_to_zone | iSCSI Z1 to Z2 onto a C2 host | Pass | | test_22_reject_pool_not_reachable_from_destination_host | Cluster-1 pool mapped to a cluster-2 host is rejected | Pass | destination host) | Test | What it covers | Status | | --- | --- | --- | | test_01_nfs3_default_primary_to_cluster | DefaultPrimary to NFS3 C1a | Pass | | test_02_nfs3_cluster_to_cluster_same_cluster | NFS3 between cluster pools in the same cluster | Pass | | test_03_nfs3_cluster_to_cluster_across_clusters | NFS3 to a pool in the second cluster | Pass | | test_04_nfs3_cluster_to_zone | NFS3 cluster pool to zone-wide | Pass | | test_05_nfs3_zone_to_zone | NFS3 between two zone-wide pools | Pass | | test_06_nfs3_zone_to_cluster | NFS3 zone-wide back to C1a | Pass | | test_07_iscsi_default_primary_to_cluster | DefaultPrimary to iSCSI C1a | Pass | | test_08_iscsi_cluster_to_cluster_same_cluster | iSCSI between cluster pools in the same cluster | Pass | | test_09_iscsi_cluster_to_cluster_across_clusters | iSCSI to a pool in the second cluster | Pass | | test_10_iscsi_cluster_to_zone | iSCSI cluster pool to zone-wide | Pass | | test_11_iscsi_zone_to_zone | iSCSI between two zone-wide pools | Pass | | test_12_iscsi_zone_to_cluster | iSCSI zone-wide back to C1a | Pass | | test_13_reject_nfs3_to_iscsi | Stopped-VM NFS3-to-iSCSI is rejected | Pass | | test_14_reject_iscsi_to_nfs3 | Stopped-VM iSCSI-to-NFS3 is rejected | Pass | | test_15_reject_running_vm | Stopped-VM API form is rejected once the VM is running | Pass | | Test | What it covers | Status | | --- | --- | --- | | test_01_nfs3_detached_default_primary_to_cluster | Detached NFS3, DefaultPrimary to C1a | Pass | | test_02_nfs3_detached_cluster_to_cluster_same_cluster | Detached NFS3, C1a to C1b | Pass | | test_03_nfs3_detached_cluster_to_cluster_across_clusters | Detached NFS3, C1b to C2 | Pass | | test_04_nfs3_detached_cluster_to_zone | Detached NFS3, C2 to Z1 | Pass | | test_05_nfs3_detached_zone_to_zone | Detached NFS3, Z1 to Z2 | Pass | | test_06_nfs3_detached_zone_to_cluster | Detached NFS3, Z2 back to C1a | Pass | | test_07_iscsi_detached_default_primary_to_cluster | Detached iSCSI, DefaultPrimary to C1a | Pass | | test_08_iscsi_detached_cluster_to_cluster_same_cluster | Detached iSCSI, C1a to C1b | Pass | | test_09_iscsi_detached_cluster_to_cluster_across_clusters | Detached iSCSI, C1b to C2 | Pass | | test_10_iscsi_detached_cluster_to_zone | Detached iSCSI, C2 to Z1 | Pass | | test_11_iscsi_detached_zone_to_zone | Detached iSCSI, Z1 to Z2 | Pass | | test_12_iscsi_detached_zone_to_cluster | Detached iSCSI, Z2 back to C1a | Pass | | test_13_nfs3_attached_stopped_vm_cluster_to_zone | Stopped-attached NFS3 data, C1a to Z1; root stays | Pass | | test_14_iscsi_attached_stopped_vm_cluster_to_zone | Stopped-attached iSCSI data, C1a to Z1; root stays | Pass | | test_15_nfs3_attached_stopped_vm_default_to_ontap | Stopped-attached non-ONTAP data to ONTAP NFS3 | Pass | | test_16_iscsi_attached_stopped_vm_default_to_ontap | Stopped-attached non-ONTAP data to ONTAP iSCSI | Pass | | test_17_reject_detached_nfs3_to_iscsi | Detached NFS3-to-iSCSI is rejected | Pass | | test_18_reject_detached_iscsi_to_nfs3 | Detached iSCSI-to-NFS3 is rejected | Pass | | test_19_reject_stopped_attached_nfs3_to_iscsi | Stopped-attached NFS3-to-iSCSI is rejected | Pass | | test_20_reject_stopped_attached_iscsi_to_nfs3 | Stopped-attached iSCSI-to-NFS3 is rejected | Pass | | test_21_reject_attached_running_vm_without_livemigrate | Running-attached NFS3 without livemigrate is rejected | Pass | | test_22_reject_attached_running_vm_with_livemigrate | Live volume-only migration is rejected | Pass | | test_23_reject_same_pool | Migration to the volume's current pool is rejected | Pass | --- .../cloud/vm/VirtualMachineManagerImpl.java | 53 + .../vm/VirtualMachineManagerImplTest.java | 56 + .../StorageSystemDataMotionStrategy.java | 28 +- .../StorageSystemDataMotionStrategyTest.java | 45 + .../kvm/storage/KVMStorageProcessor.java | 27 +- .../kvm/storage/KVMStorageProcessorTest.java | 236 + plugins/storage/volume/ontap/pom.xml | 48 + .../driver/OntapPrimaryDatastoreDriver.java | 1997 ++++++++- .../storage/feign/client/SANFeignClient.java | 10 +- .../cloudstack/storage/feign/model/Lun.java | 58 + .../storage/listener/OntapHostListener.java | 5 +- .../motion/OntapDataMotionStrategy.java | 811 ++++ .../storage/service/StorageStrategy.java | 598 ++- .../storage/service/UnifiedNASStrategy.java | 216 +- .../storage/service/UnifiedSANStrategy.java | 568 ++- .../storage/utils/OntapStorageConstants.java | 131 +- .../spring-storage-volume-ontap-context.xml | 3 + .../OntapPrimaryDatastoreDriverTest.java | 3827 ++++++++++++++++- .../feign/client/SANFeignClientTest.java | 59 + .../motion/OntapDataMotionStrategyTest.java | 757 ++++ .../storage/service/StorageStrategyTest.java | 798 +++- .../service/UnifiedNASStrategyTest.java | 662 ++- .../service/UnifiedSANStrategyTest.java | 1388 +++++- 23 files changed, 11619 insertions(+), 762 deletions(-) create mode 100644 plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/motion/OntapDataMotionStrategy.java create mode 100644 plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/feign/client/SANFeignClientTest.java create mode 100644 plugins/storage/volume/ontap/src/test/java/org/apache/cloudstack/storage/motion/OntapDataMotionStrategyTest.java diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index cd5cac7228eb..3cc884ef7705 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -19,6 +19,7 @@ import static com.cloud.configuration.ConfigurationManagerImpl.EXPOSE_ERRORS_TO_USER; import static com.cloud.configuration.ConfigurationManagerImpl.MIGRATE_VM_ACROSS_CLUSTERS; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Field; import java.net.URI; @@ -320,6 +321,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public static final String VM_WORK_JOB_HANDLER = VirtualMachineManagerImpl.class.getSimpleName(); private static final String VM_SYNC_ALERT_SUBJECT = "VM state sync alert"; + private static final String ONTAP_SVM_NAME_DETAIL = "svmName"; + private static final String ONTAP_SVM_UUID_DETAIL = "svmUUID"; + private static final String ONTAP_STORAGE_IP_DETAIL = "storageIP"; + private static final String ONTAP_PROTOCOL_DETAIL = "protocol"; @Inject private UserVmManager _userVmMgr; @@ -3567,15 +3572,63 @@ protected void executeManagedStorageChecksWhenTargetStoragePoolProvided(StorageP if (currentPool.getId() == targetPool.getId()) { return; } + if (isSupportedOntapLiveStorageMigration(currentPool, targetPool)) { + return; + } Map details = _storagePoolDao.getDetails(currentPool.getId()); if (details != null && Boolean.parseBoolean(details.get(Storage.Capability.ALLOW_MIGRATE_OTHER_POOLS.toString()))) { return; } + if (DataStoreProvider.ONTAP_PLUGIN_NAME.equals(currentPool.getStorageProviderName()) + && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(targetPool.getStorageProviderName())) { + Map targetDetails = _storagePoolDao.getDetails(targetPool.getId()); + throw new CloudRuntimeException(String.format("ONTAP migration requires matching storageIP, SVM, protocol, and pool type " + + "[source: storageIP=%s, svmUUID=%s, svmName=%s, protocol=%s, type=%s; destination: storageIP=%s, svmUUID=%s, svmName=%s, protocol=%s, type=%s].", + details != null ? details.get(ONTAP_STORAGE_IP_DETAIL) : null, + details != null ? details.get(ONTAP_SVM_UUID_DETAIL) : null, + details != null ? details.get(ONTAP_SVM_NAME_DETAIL) : null, details != null ? details.get(ONTAP_PROTOCOL_DETAIL) : null, + currentPool.getPoolType(), targetDetails != null ? targetDetails.get(ONTAP_STORAGE_IP_DETAIL) : null, + targetDetails != null ? targetDetails.get(ONTAP_SVM_UUID_DETAIL) : null, + targetDetails != null ? targetDetails.get(ONTAP_SVM_NAME_DETAIL) : null, + targetDetails != null ? targetDetails.get(ONTAP_PROTOCOL_DETAIL) : null, targetPool.getPoolType())); + } throw new CloudRuntimeException(String.format("Currently, a volume on managed storage can only be 'migrated' to itself " + "[volumeId=%s, currentStoragePoolId=%s, targetStoragePoolId=%s].", volume.getUuid(), currentPool.getUuid(), targetPool.getUuid())); } + protected boolean isSupportedOntapLiveStorageMigration(StoragePoolVO currentPool, StoragePoolVO targetPool) { + if (!DataStoreProvider.ONTAP_PLUGIN_NAME.equals(currentPool.getStorageProviderName()) + || !DataStoreProvider.ONTAP_PLUGIN_NAME.equals(targetPool.getStorageProviderName())) { + return false; + } + + Map currentDetails = _storagePoolDao.getDetails(currentPool.getId()); + Map targetDetails = _storagePoolDao.getDetails(targetPool.getId()); + if (currentDetails == null || targetDetails == null) { + return false; + } + + String currentSvmName = currentDetails.get(ONTAP_SVM_NAME_DETAIL); + String targetSvmName = targetDetails.get(ONTAP_SVM_NAME_DETAIL); + String currentSvmUuid = currentDetails.get(ONTAP_SVM_UUID_DETAIL); + String targetSvmUuid = targetDetails.get(ONTAP_SVM_UUID_DETAIL); + String currentStorageIp = currentDetails.get(ONTAP_STORAGE_IP_DETAIL); + String targetStorageIp = targetDetails.get(ONTAP_STORAGE_IP_DETAIL); + String currentProtocol = currentDetails.get(ONTAP_PROTOCOL_DETAIL); + String targetProtocol = targetDetails.get(ONTAP_PROTOCOL_DETAIL); + boolean isSameSvm = isNotBlank(currentSvmUuid) || isNotBlank(targetSvmUuid) + ? isNotBlank(currentSvmUuid) && currentSvmUuid.equals(targetSvmUuid) + : isNotBlank(currentSvmName) && currentSvmName.equals(targetSvmName); + return isNotBlank(currentStorageIp) + && currentStorageIp.equals(targetStorageIp) + && isSameSvm + && isNotBlank(currentProtocol) + && currentProtocol.equalsIgnoreCase(targetProtocol) + && currentPool.getPoolType() != null + && currentPool.getPoolType() == targetPool.getPoolType(); + } + /** * For each one of the volumes we will map it to a storage pool that is available via the target host. * An exception is thrown if we cannot find a storage pool that is accessible in the target host to migrate the volume to. diff --git a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java index fe51440bd81b..3292c6bd5c9e 100644 --- a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java +++ b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java @@ -567,6 +567,62 @@ public void allowVolumeMigrationsForPowerFlexStorage() { verify(storagePoolVoMock, Mockito.times(0)).getId(); } + @Test + public void allowVolumeMigrationBetweenOntapPoolsOnSameSvmAndProtocol() { + StoragePoolVO targetPool = Mockito.mock(StoragePoolVO.class); + Mockito.doReturn(true).when(storagePoolVoMock).isManaged(); + Mockito.doReturn(Storage.StoragePoolType.OntapiSCSI).when(storagePoolVoMock).getPoolType(); + Mockito.doReturn(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.ONTAP_PLUGIN_NAME) + .when(storagePoolVoMock).getStorageProviderName(); + Mockito.doReturn(12L).when(targetPool).getId(); + Mockito.doReturn(Storage.StoragePoolType.OntapiSCSI).when(targetPool).getPoolType(); + Mockito.doReturn(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.ONTAP_PLUGIN_NAME) + .when(targetPool).getStorageProviderName(); + Mockito.doReturn(Map.of("storageIP", "10.0.0.1", "svmName", "svm1", "protocol", "ISCSI")) + .when(storagePoolDaoMock).getDetails(storagePoolVoMockId); + Mockito.doReturn(Map.of("storageIP", "10.0.0.1", "svmName", "svm1", "protocol", "ISCSI")) + .when(storagePoolDaoMock).getDetails(12L); + + virtualMachineManagerImpl.executeManagedStorageChecksWhenTargetStoragePoolProvided(storagePoolVoMock, volumeVoMock, targetPool); + } + + @Test + public void rejectVolumeMigrationBetweenOntapPoolsUsingDifferentProtocols() { + StoragePoolVO targetPool = Mockito.mock(StoragePoolVO.class); + Mockito.doReturn(true).when(storagePoolVoMock).isManaged(); + Mockito.doReturn(Storage.StoragePoolType.OntapiSCSI).when(storagePoolVoMock).getPoolType(); + Mockito.doReturn(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.ONTAP_PLUGIN_NAME) + .when(storagePoolVoMock).getStorageProviderName(); + Mockito.doReturn(12L).when(targetPool).getId(); + Mockito.doReturn(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.ONTAP_PLUGIN_NAME) + .when(targetPool).getStorageProviderName(); + Mockito.doReturn(Map.of("storageIP", "10.0.0.1", "svmName", "svm1", "protocol", "ISCSI")) + .when(storagePoolDaoMock).getDetails(storagePoolVoMockId); + Mockito.doReturn(Map.of("storageIP", "10.0.0.1", "svmName", "svm1", "protocol", "NFS3")) + .when(storagePoolDaoMock).getDetails(12L); + + CloudRuntimeException exception = assertThrows(CloudRuntimeException.class, + () -> virtualMachineManagerImpl.executeManagedStorageChecksWhenTargetStoragePoolProvided(storagePoolVoMock, volumeVoMock, targetPool)); + assertTrue(exception.getMessage().contains("protocol=ISCSI")); + assertTrue(exception.getMessage().contains("protocol=NFS3")); + } + + @Test + public void rejectOntapPoolsWithSameSvmNameOnDifferentStorageSystems() { + StoragePoolVO targetPool = Mockito.mock(StoragePoolVO.class); + Mockito.doReturn(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.ONTAP_PLUGIN_NAME) + .when(storagePoolVoMock).getStorageProviderName(); + Mockito.doReturn(12L).when(targetPool).getId(); + Mockito.doReturn(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.ONTAP_PLUGIN_NAME) + .when(targetPool).getStorageProviderName(); + Mockito.doReturn(Map.of("storageIP", "10.0.0.1", "svmName", "svm1", "protocol", "NFS3")) + .when(storagePoolDaoMock).getDetails(storagePoolVoMockId); + Mockito.doReturn(Map.of("storageIP", "10.0.0.2", "svmName", "svm1", "protocol", "NFS3")) + .when(storagePoolDaoMock).getDetails(12L); + + assertFalse(virtualMachineManagerImpl.isSupportedOntapLiveStorageMigration(storagePoolVoMock, targetPool)); + } + @Test public void executeManagedStorageChecksWhenTargetStoragePoolProvidedTestCurrentStoragePoolEqualsTargetPool() { Mockito.doReturn(true).when(storagePoolVoMock).isManaged(); diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java index 6d37059eb201..da66b5caeab6 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java @@ -48,6 +48,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; @@ -240,13 +241,22 @@ public StrategyPriority canHandle(DataObject srcData, DataObject destData) { if (srcData instanceof VolumeInfo && destData instanceof VolumeInfo) { VolumeInfo srcVolumeInfo = (VolumeInfo)srcData; + VolumeInfo destVolumeInfo = (VolumeInfo)destData; + + // OntapDataMotionStrategy also returns HIGHEST for these and a tie keeps the first strategy. + if (srcVolumeInfo.getState() == Volume.State.Migrating) { + StoragePoolVO srcPool = _storagePoolDao.findById(srcVolumeInfo.getDataStore().getId()); + StoragePoolVO destPool = _storagePoolDao.findById(destVolumeInfo.getDataStore().getId()); + if ((srcPool != null && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(srcPool.getStorageProviderName())) + || (destPool != null && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(destPool.getStorageProviderName()))) { + return StrategyPriority.CANT_HANDLE; + } + } if (isVolumeOnManagedStorage(srcVolumeInfo)) { return StrategyPriority.HIGHEST; } - VolumeInfo destVolumeInfo = (VolumeInfo)destData; - if (isVolumeOnManagedStorage(destVolumeInfo)) { return StrategyPriority.HIGHEST; } @@ -327,6 +337,20 @@ public final StrategyPriority canHandle(Map volumeMap, Ho * Handles migrating volumes on managed Storage. */ protected StrategyPriority internalCanHandle(Map volumeMap, Host srcHost, Host destHost) { + // OntapDataMotionStrategy also returns HIGHEST for these and a tie keeps the first strategy. + for (VolumeInfo volumeInfo : volumeMap.keySet()) { + StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId()); + if (storagePoolVO != null && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(storagePoolVO.getStorageProviderName())) { + return StrategyPriority.CANT_HANDLE; + } + } + for (DataStore dataStore : volumeMap.values()) { + StoragePoolVO storagePoolVO = _storagePoolDao.findById(dataStore.getId()); + if (storagePoolVO != null && DataStoreProvider.ONTAP_PLUGIN_NAME.equals(storagePoolVO.getStorageProviderName())) { + return StrategyPriority.CANT_HANDLE; + } + } + Set volumeInfoSet = volumeMap.keySet(); for (VolumeInfo volumeInfo : volumeInfoSet) { diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java index fc51eeba7b6e..2680b7c25faf 100644 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java @@ -30,6 +30,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore; import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; @@ -133,6 +134,46 @@ public void internalCanHandleTestNoStoragePoolsIsManaged() { configureAndTestInternalCanHandle(false, false, StrategyPriority.CANT_HANDLE); } + @Test + public void canHandleDeclinesMigratingVolumeOnOntapPrimary() { + PrimaryDataStore srcStore = mock(PrimaryDataStoreImpl.class); + PrimaryDataStore destStore = mock(PrimaryDataStoreImpl.class); + VolumeObject srcVolume = mock(VolumeObject.class); + VolumeObject destVolume = mock(VolumeObject.class); + doReturn(Volume.State.Migrating).when(srcVolume).getState(); + doReturn(srcStore).when(srcVolume).getDataStore(); + doReturn(destStore).when(destVolume).getDataStore(); + doReturn(1L).when(srcStore).getId(); + doReturn(2L).when(destStore).getId(); + StoragePoolVO srcPool = Mockito.spy(new StoragePoolVO()); + StoragePoolVO destPool = Mockito.spy(new StoragePoolVO()); + lenient().doReturn(true).when(srcPool).isManaged(); + doReturn(DataStoreProvider.ONTAP_PLUGIN_NAME).when(destPool).getStorageProviderName(); + doReturn(srcPool).when(primaryDataStoreDao).findById(1L); + doReturn(destPool).when(primaryDataStoreDao).findById(2L); + + Assert.assertEquals(StrategyPriority.CANT_HANDLE, strategy.canHandle(srcVolume, destVolume)); + } + + @Test + public void internalCanHandleDeclinesMapWithOntapPool() { + VolumeObject volumeInfo = Mockito.spy(new VolumeObject()); + Mockito.doReturn(0L).when(volumeInfo).getPoolId(); + DataStore ds = Mockito.spy(new PrimaryDataStoreImpl()); + Mockito.doReturn(1L).when(ds).getId(); + Map volumeMap = new HashMap<>(); + volumeMap.put(volumeInfo, ds); + StoragePoolVO srcPool = Mockito.spy(new StoragePoolVO()); + lenient().doReturn(true).when(srcPool).isManaged(); + StoragePoolVO destPool = Mockito.spy(new StoragePoolVO()); + Mockito.doReturn(DataStoreProvider.ONTAP_PLUGIN_NAME).when(destPool).getStorageProviderName(); + Mockito.doReturn(srcPool).when(primaryDataStoreDao).findById(0L); + Mockito.doReturn(destPool).when(primaryDataStoreDao).findById(1L); + + Assert.assertEquals(StrategyPriority.CANT_HANDLE, + strategy.internalCanHandle(volumeMap, new HostVO("srcHostUuid"), new HostVO("destHostUuid"))); + } + private void configureAndTestInternalCanHandle(boolean sPool0IsManaged, boolean sPool1IsManaged, StrategyPriority expectedStrategyPriority) { VolumeObject volumeInfo = Mockito.spy(new VolumeObject()); Mockito.doReturn(0l).when(volumeInfo).getPoolId(); @@ -555,6 +596,7 @@ public void testInternalCanHandle_ClvmSourceManagedDestination() { Mockito.doReturn(0L).when(volumeInfo).getPoolId(); DataStore ds = Mockito.spy(new PrimaryDataStoreImpl()); + Mockito.lenient().doReturn(1L).when(ds).getId(); Map volumeMap = new HashMap<>(); volumeMap.put(volumeInfo, ds); @@ -580,6 +622,7 @@ public void testInternalCanHandle_ClvmNgSourceManagedDestination() { Mockito.doReturn(0L).when(volumeInfo).getPoolId(); DataStore ds = Mockito.spy(new PrimaryDataStoreImpl()); + Mockito.lenient().doReturn(1L).when(ds).getId(); Map volumeMap = new HashMap<>(); volumeMap.put(volumeInfo, ds); @@ -605,6 +648,7 @@ public void testInternalCanHandle_ClvmToClvmNg() { Mockito.doReturn(0L).when(volumeInfo).getPoolId(); DataStore ds = Mockito.spy(new PrimaryDataStoreImpl()); + Mockito.lenient().doReturn(1L).when(ds).getId(); Map volumeMap = new HashMap<>(); volumeMap.put(volumeInfo, ds); @@ -633,6 +677,7 @@ public void testInternalCanHandle_ClvmNgToClvm() { Mockito.doReturn(0L).when(volumeInfo).getPoolId(); DataStore ds = Mockito.spy(new PrimaryDataStoreImpl()); + Mockito.lenient().doReturn(1L).when(ds).getId(); Map volumeMap = new HashMap<>(); volumeMap.put(volumeInfo, ds); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index 235949502c71..eead672bc18d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -37,6 +37,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -3426,8 +3427,13 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { destFormat, destVolumePath, destPrimaryStore.getId(), destPrimaryStore.getUuid(), destPrimaryStore.getName(), destPrimaryStore.getPoolType())); + Map srcDetails = ObjectUtils.defaultIfNull( + ObjectUtils.firstNonNull(srcPrimaryStore.getDetails(), cmd.getOptions()), Collections.emptyMap()); + Map destDetails = ObjectUtils.defaultIfNull( + ObjectUtils.firstNonNull(destPrimaryStore.getDetails(), cmd.getOptions2()), Collections.emptyMap()); + if (srcPrimaryStore.isManaged()) { - if (!storagePoolMgr.connectPhysicalDisk(srcPrimaryStore.getPoolType(), srcPrimaryStore.getUuid(), srcVolumePath, srcPrimaryStore.getDetails())) { + if (!storagePoolMgr.connectPhysicalDisk(srcPrimaryStore.getPoolType(), srcPrimaryStore.getUuid(), srcVolumePath, srcDetails)) { logger.warn(String.format("Failed to connect src volume %s, in storage pool %s", srcVol, srcPrimaryStore)); } } @@ -3443,12 +3449,25 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { volume.setVmName(srcVol.getVmName()); KVMPhysicalDisk newVolume; String destVolumeName; - destPool = storagePoolMgr.getStoragePool(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid()); + try { + destPool = storagePoolMgr.getStoragePool(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid()); + } catch (CloudRuntimeException e) { + if (destPrimaryStore.isManaged() && e.getMessage().contains("not found")) { + destPool = storagePoolMgr.createStoragePool(destPrimaryStore.getUuid(), destPrimaryStore.getHost(), + destPrimaryStore.getPort(), destPrimaryStore.getPath(), null, destPrimaryStore.getPoolType(), + destDetails); + } else { + throw e; + } + } if (destPrimaryStore.isManaged()) { - if (!storagePoolMgr.connectPhysicalDisk(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid(), destVolumePath, destPrimaryStore.getDetails())) { + if (!storagePoolMgr.connectPhysicalDisk(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid(), destVolumePath, destDetails)) { logger.warn("Failed to connect dest volume {}, in storage pool {}", destVol, destPrimaryStore); } - destVolumeName = derivePath(destPrimaryStore, destData, destPrimaryStore.getDetails()); + } + if (destPrimaryStore.isManaged()) { + destVolumeName = StringUtils.defaultIfBlank( + derivePath(destPrimaryStore, destData, destDetails), destVolumePath); } else { PhysicalDiskFormat destPoolDefaultFormat = destPool.getDefaultFormat(); destFormat = getFormat(destPoolDefaultFormat); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessorTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessorTest.java index a85fc31224e0..1a03e19cc8f0 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessorTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessorTest.java @@ -29,10 +29,14 @@ import com.cloud.storage.Storage.StoragePoolType; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef; import com.cloud.storage.Storage; +import com.cloud.storage.Volume; import com.cloud.storage.template.TemplateConstants; import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; +import org.apache.cloudstack.storage.command.CopyCmdAnswer; +import org.apache.cloudstack.storage.command.CopyCommand; +import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.utils.qemu.QemuImageOptions; @@ -49,6 +53,7 @@ import org.libvirt.Domain; import org.libvirt.LibvirtException; import org.mockito.InjectMocks; +import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockedConstruction; import org.mockito.MockedStatic; @@ -162,6 +167,237 @@ public void testIsEnoughSpaceForDownloadTemplateOnTemporaryLocationEnoughSpace() } } + @Test + public void copyManagedVolumeWithoutTargetReturnsCopiedDiskPath() { + CopyCommand command = Mockito.mock(CopyCommand.class); + VolumeObjectTO sourceVolume = Mockito.mock(VolumeObjectTO.class); + VolumeObjectTO destinationVolume = Mockito.mock(VolumeObjectTO.class); + PrimaryDataStoreTO sourceStore = Mockito.mock(PrimaryDataStoreTO.class); + PrimaryDataStoreTO destinationStore = Mockito.mock(PrimaryDataStoreTO.class); + KVMStoragePool destinationPool = Mockito.mock(KVMStoragePool.class); + KVMPhysicalDisk sourceDisk = Mockito.mock(KVMPhysicalDisk.class); + KVMPhysicalDisk copiedDisk = Mockito.mock(KVMPhysicalDisk.class); + Map destinationDetails = Map.of(); + + Mockito.when(command.getSrcTO()).thenReturn(sourceVolume); + Mockito.when(command.getDestTO()).thenReturn(destinationVolume); + Mockito.when(command.getWaitInMillSeconds()).thenReturn(60); + Mockito.when(sourceVolume.getDataStore()).thenReturn(sourceStore); + Mockito.when(destinationVolume.getDataStore()).thenReturn(destinationStore); + Mockito.when(sourceVolume.getPath()).thenReturn("source-path"); + Mockito.when(destinationVolume.getPath()).thenReturn("destination-path"); + Mockito.when(sourceVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(destinationVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(sourceVolume.getVolumeType()).thenReturn(Volume.Type.DATADISK); + Mockito.when(sourceStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(destinationStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(sourceStore.getUuid()).thenReturn("source-pool"); + Mockito.when(destinationStore.getUuid()).thenReturn("destination-pool"); + Mockito.when(destinationStore.getHost()).thenReturn("destination-host"); + Mockito.when(destinationStore.getPort()).thenReturn(2049); + Mockito.when(destinationStore.getPath()).thenReturn("/destination-export"); + Mockito.when(sourceStore.isManaged()).thenReturn(true); + Mockito.when(destinationStore.isManaged()).thenReturn(true); + Mockito.when(destinationStore.getDetails()).thenReturn(destinationDetails); + Mockito.when(storagePoolManager.getStoragePool( + Storage.StoragePoolType.NetworkFilesystem, + "destination-pool")).thenThrow(new CloudRuntimeException("not found")); + Mockito.when(storagePoolManager.createStoragePool( + "destination-pool", "destination-host", 2049, "/destination-export", null, + Storage.StoragePoolType.NetworkFilesystem, destinationDetails)).thenReturn(destinationPool); + Mockito.when(storagePoolManager.getPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "source-pool", "source-path")).thenReturn(sourceDisk); + Mockito.when(storagePoolManager.copyPhysicalDisk( + Mockito.eq(sourceDisk), Mockito.eq("destination-path"), + Mockito.eq(destinationPool), Mockito.eq(60))).thenReturn(copiedDisk); + Mockito.when(copiedDisk.getFormat()).thenReturn(QemuImg.PhysicalDiskFormat.QCOW2); + + CopyCmdAnswer answer = (CopyCmdAnswer)storageProcessor.copyVolumeFromPrimaryToPrimary(command); + + InOrder destinationPoolSetup = Mockito.inOrder(storagePoolManager); + destinationPoolSetup.verify(storagePoolManager).getStoragePool( + Storage.StoragePoolType.NetworkFilesystem, "destination-pool"); + destinationPoolSetup.verify(storagePoolManager).createStoragePool( + "destination-pool", "destination-host", 2049, "/destination-export", null, + Storage.StoragePoolType.NetworkFilesystem, destinationDetails); + destinationPoolSetup.verify(storagePoolManager).connectPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "destination-pool", "destination-path", destinationStore.getDetails()); + Assert.assertTrue(answer.getResult()); + Assert.assertEquals("destination-path", answer.getNewData().getPath()); + } + + @Test + public void copyVolumeFromPrimaryToPrimaryUsesCommandOptionsWhenStoreDetailsAreNull() { + CopyCommand command = Mockito.mock(CopyCommand.class); + VolumeObjectTO sourceVolume = Mockito.mock(VolumeObjectTO.class); + VolumeObjectTO destinationVolume = Mockito.mock(VolumeObjectTO.class); + PrimaryDataStoreTO sourceStore = Mockito.mock(PrimaryDataStoreTO.class); + PrimaryDataStoreTO destinationStore = Mockito.mock(PrimaryDataStoreTO.class); + KVMStoragePool destinationPool = Mockito.mock(KVMStoragePool.class); + KVMPhysicalDisk sourceDisk = Mockito.mock(KVMPhysicalDisk.class); + KVMPhysicalDisk copiedDisk = Mockito.mock(KVMPhysicalDisk.class); + Map sourceDetails = Map.of("iqn", "/iqn.source/7"); + Map destinationDetails = Map.of(); + + Mockito.when(command.getSrcTO()).thenReturn(sourceVolume); + Mockito.when(command.getDestTO()).thenReturn(destinationVolume); + Mockito.when(command.getWaitInMillSeconds()).thenReturn(60); + Mockito.when(command.getOptions()).thenReturn(sourceDetails); + Mockito.when(sourceVolume.getDataStore()).thenReturn(sourceStore); + Mockito.when(destinationVolume.getDataStore()).thenReturn(destinationStore); + Mockito.when(sourceVolume.getPath()).thenReturn("source-path"); + Mockito.when(destinationVolume.getPath()).thenReturn("destination-path"); + Mockito.when(sourceVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(destinationVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(sourceVolume.getVolumeType()).thenReturn(Volume.Type.DATADISK); + Mockito.when(sourceStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(destinationStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(sourceStore.getUuid()).thenReturn("source-pool"); + Mockito.when(destinationStore.getUuid()).thenReturn("destination-pool"); + Mockito.when(sourceStore.isManaged()).thenReturn(true); + Mockito.when(destinationStore.isManaged()).thenReturn(true); + Mockito.when(sourceStore.getDetails()).thenReturn(null); + Mockito.when(destinationStore.getDetails()).thenReturn(destinationDetails); + Mockito.when(storagePoolManager.getStoragePool( + Storage.StoragePoolType.NetworkFilesystem, + "destination-pool")).thenReturn(destinationPool); + Mockito.when(storagePoolManager.getPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "source-pool", "source-path")).thenReturn(sourceDisk); + Mockito.when(storagePoolManager.copyPhysicalDisk( + Mockito.eq(sourceDisk), Mockito.eq("destination-path"), + Mockito.eq(destinationPool), Mockito.eq(60))).thenReturn(copiedDisk); + Mockito.when(copiedDisk.getFormat()).thenReturn(QemuImg.PhysicalDiskFormat.QCOW2); + + CopyCmdAnswer answer = (CopyCmdAnswer)storageProcessor.copyVolumeFromPrimaryToPrimary(command); + + Mockito.verify(storagePoolManager).connectPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "source-pool", "source-path", sourceDetails); + Assert.assertTrue(answer.getResult()); + Assert.assertEquals("destination-path", answer.getNewData().getPath()); + } + + @Test + public void copyVolumeFromPrimaryToPrimaryUsesCommandOptions2WhenStoreDetailsAreNull() { + CopyCommand command = Mockito.mock(CopyCommand.class); + VolumeObjectTO sourceVolume = Mockito.mock(VolumeObjectTO.class); + VolumeObjectTO destinationVolume = Mockito.mock(VolumeObjectTO.class); + PrimaryDataStoreTO sourceStore = Mockito.mock(PrimaryDataStoreTO.class); + PrimaryDataStoreTO destinationStore = Mockito.mock(PrimaryDataStoreTO.class); + KVMStoragePool destinationPool = Mockito.mock(KVMStoragePool.class); + KVMPhysicalDisk sourceDisk = Mockito.mock(KVMPhysicalDisk.class); + KVMPhysicalDisk copiedDisk = Mockito.mock(KVMPhysicalDisk.class); + Map destinationDetails = Map.of("managedStoreTarget", "destination-iqn-path"); + + Mockito.when(command.getSrcTO()).thenReturn(sourceVolume); + Mockito.when(command.getDestTO()).thenReturn(destinationVolume); + Mockito.when(command.getWaitInMillSeconds()).thenReturn(60); + Mockito.when(command.getOptions2()).thenReturn(destinationDetails); + Mockito.when(sourceVolume.getDataStore()).thenReturn(sourceStore); + Mockito.when(destinationVolume.getDataStore()).thenReturn(destinationStore); + Mockito.when(sourceVolume.getPath()).thenReturn("source-path"); + Mockito.when(destinationVolume.getPath()).thenReturn("destination-path"); + Mockito.when(sourceVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(destinationVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(sourceVolume.getVolumeType()).thenReturn(Volume.Type.DATADISK); + Mockito.when(sourceStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(destinationStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(sourceStore.getUuid()).thenReturn("source-pool"); + Mockito.when(destinationStore.getUuid()).thenReturn("destination-pool"); + Mockito.when(destinationStore.getHost()).thenReturn("destination-host"); + Mockito.when(destinationStore.getPort()).thenReturn(2049); + Mockito.when(destinationStore.getPath()).thenReturn("/destination-export"); + Mockito.when(sourceStore.isManaged()).thenReturn(true); + Mockito.when(destinationStore.isManaged()).thenReturn(true); + Mockito.when(destinationStore.getDetails()).thenReturn(null); + Mockito.when(storagePoolManager.getStoragePool( + Storage.StoragePoolType.NetworkFilesystem, + "destination-pool")).thenThrow(new CloudRuntimeException("not found")); + Mockito.when(storagePoolManager.createStoragePool( + "destination-pool", "destination-host", 2049, "/destination-export", null, + Storage.StoragePoolType.NetworkFilesystem, destinationDetails)).thenReturn(destinationPool); + Mockito.when(storagePoolManager.getPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "source-pool", "source-path")).thenReturn(sourceDisk); + Mockito.when(storagePoolManager.copyPhysicalDisk( + Mockito.eq(sourceDisk), Mockito.eq("destination-iqn-path"), + Mockito.eq(destinationPool), Mockito.eq(60))).thenReturn(copiedDisk); + Mockito.when(copiedDisk.getFormat()).thenReturn(QemuImg.PhysicalDiskFormat.QCOW2); + + CopyCmdAnswer answer = (CopyCmdAnswer)storageProcessor.copyVolumeFromPrimaryToPrimary(command); + + Mockito.verify(storagePoolManager).createStoragePool( + "destination-pool", "destination-host", 2049, "/destination-export", null, + Storage.StoragePoolType.NetworkFilesystem, destinationDetails); + Mockito.verify(storagePoolManager).connectPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "destination-pool", "destination-path", destinationDetails); + Assert.assertTrue(answer.getResult()); + Assert.assertEquals("destination-iqn-path", answer.getNewData().getPath()); + } + + @Test + public void copyVolumeFromPrimaryToPrimaryPrefersStoreDetailsOverCommandOptions() { + CopyCommand command = Mockito.mock(CopyCommand.class); + VolumeObjectTO sourceVolume = Mockito.mock(VolumeObjectTO.class); + VolumeObjectTO destinationVolume = Mockito.mock(VolumeObjectTO.class); + PrimaryDataStoreTO sourceStore = Mockito.mock(PrimaryDataStoreTO.class); + PrimaryDataStoreTO destinationStore = Mockito.mock(PrimaryDataStoreTO.class); + KVMStoragePool destinationPool = Mockito.mock(KVMStoragePool.class); + KVMPhysicalDisk sourceDisk = Mockito.mock(KVMPhysicalDisk.class); + KVMPhysicalDisk copiedDisk = Mockito.mock(KVMPhysicalDisk.class); + Map sourceStoreDetails = Map.of("iqn", "/iqn.store/1"); + Map destinationStoreDetails = Map.of("nfsMountOpts", "vers=3"); + + Mockito.when(command.getSrcTO()).thenReturn(sourceVolume); + Mockito.when(command.getDestTO()).thenReturn(destinationVolume); + Mockito.when(command.getWaitInMillSeconds()).thenReturn(60); + Mockito.when(command.getOptions()).thenReturn(Map.of("iqn", "/iqn.command/9")); + Mockito.when(command.getOptions2()).thenReturn(Map.of("managedStoreTarget", "command-target")); + Mockito.when(sourceVolume.getDataStore()).thenReturn(sourceStore); + Mockito.when(destinationVolume.getDataStore()).thenReturn(destinationStore); + Mockito.when(sourceVolume.getPath()).thenReturn("source-path"); + Mockito.when(destinationVolume.getPath()).thenReturn("destination-path"); + Mockito.when(sourceVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(destinationVolume.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + Mockito.when(sourceVolume.getVolumeType()).thenReturn(Volume.Type.DATADISK); + Mockito.when(sourceStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(destinationStore.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem); + Mockito.when(sourceStore.getUuid()).thenReturn("source-pool"); + Mockito.when(destinationStore.getUuid()).thenReturn("destination-pool"); + Mockito.when(sourceStore.isManaged()).thenReturn(true); + Mockito.when(destinationStore.isManaged()).thenReturn(true); + Mockito.when(sourceStore.getDetails()).thenReturn(sourceStoreDetails); + Mockito.when(destinationStore.getDetails()).thenReturn(destinationStoreDetails); + Mockito.when(storagePoolManager.getStoragePool( + Storage.StoragePoolType.NetworkFilesystem, + "destination-pool")).thenReturn(destinationPool); + Mockito.when(storagePoolManager.getPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "source-pool", "source-path")).thenReturn(sourceDisk); + Mockito.when(storagePoolManager.copyPhysicalDisk( + Mockito.eq(sourceDisk), Mockito.eq("destination-path"), + Mockito.eq(destinationPool), Mockito.eq(60))).thenReturn(copiedDisk); + Mockito.when(copiedDisk.getFormat()).thenReturn(QemuImg.PhysicalDiskFormat.QCOW2); + + CopyCmdAnswer answer = (CopyCmdAnswer)storageProcessor.copyVolumeFromPrimaryToPrimary(command); + + Mockito.verify(storagePoolManager).connectPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "source-pool", "source-path", sourceStoreDetails); + Mockito.verify(storagePoolManager).connectPhysicalDisk( + Storage.StoragePoolType.NetworkFilesystem, + "destination-pool", "destination-path", destinationStoreDetails); + Mockito.verify(storagePoolManager, Mockito.never()).createStoragePool( + Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyString(), + Mockito.nullable(String.class), Mockito.any(Storage.StoragePoolType.class), Mockito.any()); + Assert.assertTrue(answer.getResult()); + Assert.assertEquals("destination-path", answer.getNewData().getPath()); + } + @Test public void testIsEnoughSpaceForDownloadTemplateOnTemporaryLocationNotExistingLocation() { try (MockedStatic