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 dedd104d4815c345da2e1e78cfdce59d45ad7313 Author: Harikrishna Patnala <[email protected]> AuthorDate: Thu Apr 6 13:52:31 2023 +0530 Unit tests to check if volume belongs to same or different storage scaleio cluster --- .../driver/ScaleIOPrimaryDataStoreDriver.java | 2 +- .../client/ScaleIOPrimaryDataStoreDriverTest.java | 114 +++++++++++++++++++++ .../com/cloud/storage/VolumeApiServiceImpl.java | 2 +- .../cloud/storage/VolumeApiServiceImplTest.java | 57 +++++++++++ 4 files changed, 173 insertions(+), 2 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 5d6d6f372ac..c16cdaa5f41 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 @@ -1068,7 +1068,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver { return answer; } - private boolean isSameScaleIOStorageInstance(DataStore srcStore, DataStore destStore) { + public boolean isSameScaleIOStorageInstance(DataStore srcStore, DataStore destStore) { long srcPoolId = srcStore.getId(); String srcPoolSystemId = null; StoragePoolDetailVO srcPoolSystemIdDetail = storagePoolDetailsDao.findDetail(srcPoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID); 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 new file mode 100644 index 00000000000..4ed31e6d8c1 --- /dev/null +++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/client/ScaleIOPrimaryDataStoreDriverTest.java @@ -0,0 +1,114 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package org.apache.cloudstack.storage.datastore.driver.client; + +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient; +import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; +import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; +import org.apache.cloudstack.storage.datastore.driver.ScaleIOPrimaryDataStoreDriver; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ScaleIOPrimaryDataStoreDriverTest { + + @Spy + @InjectMocks + ScaleIOPrimaryDataStoreDriver scaleIOPrimaryDataStoreDriver; + + @Mock + StoragePoolDetailsDao storagePoolDetailsDao; + + @Test + public void testSameScaleIOStorageInstance() { + DataStore srcStore = Mockito.mock(DataStore.class); + DataStore destStore = Mockito.mock(DataStore.class); + when(srcStore.getId()).thenReturn(1L); + when(destStore.getId()).thenReturn(2L); + + StoragePoolDetailVO srcPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String srcPoolSystemId = "610204d03e3ad60f"; + when(srcPoolSystemIdDetail.getValue()).thenReturn(srcPoolSystemId); + + StoragePoolDetailVO destPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String destPoolSystemId = "610204d03e3ad60f"; + when(destPoolSystemIdDetail.getValue()).thenReturn(destPoolSystemId); + + when(storagePoolDetailsDao.findDetail(1L,ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(srcPoolSystemIdDetail); + when(storagePoolDetailsDao.findDetail(2L,ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(destPoolSystemIdDetail); + + boolean result = scaleIOPrimaryDataStoreDriver.isSameScaleIOStorageInstance(srcStore, destStore); + + Assert.assertTrue(result); + } + + @Test + public void testDifferentScaleIOStorageInstance() { + DataStore srcStore = Mockito.mock(DataStore.class); + DataStore destStore = Mockito.mock(DataStore.class); + when(srcStore.getId()).thenReturn(1L); + when(destStore.getId()).thenReturn(2L); + + StoragePoolDetailVO srcPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String srcPoolSystemId = "610204d03e3ad60f"; + when(srcPoolSystemIdDetail.getValue()).thenReturn(srcPoolSystemId); + + StoragePoolDetailVO destPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String destPoolSystemId = "7332760565f6340f"; + when(destPoolSystemIdDetail.getValue()).thenReturn(destPoolSystemId); + + when(storagePoolDetailsDao.findDetail(1L,ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(srcPoolSystemIdDetail); + when(storagePoolDetailsDao.findDetail(2L,ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(destPoolSystemIdDetail); + + boolean result = scaleIOPrimaryDataStoreDriver.isSameScaleIOStorageInstance(srcStore, destStore); + + Assert.assertFalse(result); + } + + @Test (expected = CloudRuntimeException.class) + public void testCheckVolumeOnDifferentScaleIOStorageInstanceSystemIdShouldNotBeNull() { + DataStore srcStore = Mockito.mock(DataStore.class); + DataStore destStore = Mockito.mock(DataStore.class); + when(srcStore.getId()).thenReturn(1L); + when(destStore.getId()).thenReturn(2L); + + StoragePoolDetailVO srcPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String srcPoolSystemId = "610204d03e3ad60f"; + when(srcPoolSystemIdDetail.getValue()).thenReturn(srcPoolSystemId); + + StoragePoolDetailVO destPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + when(destPoolSystemIdDetail.getValue()).thenReturn(null); + + when(storagePoolDetailsDao.findDetail(1L,ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(srcPoolSystemIdDetail); + when(storagePoolDetailsDao.findDetail(2L,ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)).thenReturn(destPoolSystemIdDetail); + + scaleIOPrimaryDataStoreDriver.isSameScaleIOStorageInstance(srcStore, destStore); + } +} \ No newline at end of file diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index e554241aa4d..a6d396b15e4 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -3164,7 +3164,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic return orchestrateMigrateVolume(vol, destPool, liveMigrateVolume, newDiskOffering); } - private boolean isScaleIOVolumeOnDifferentScaleIOStorageInstances(long srcPoolId, long destPoolId) { + protected boolean isScaleIOVolumeOnDifferentScaleIOStorageInstances(long srcPoolId, long destPoolId) { String SCALEIO_STORAGE_POOL_SYSTEM_ID = "powerflex.storagepool.system.id"; String srcPoolSystemId = null; StoragePoolDetailVO srcPoolSystemIdDetail = storagePoolDetailsDao.findDetail(srcPoolId, SCALEIO_STORAGE_POOL_SYSTEM_ID); diff --git a/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java b/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java index 16c7887ef91..a0ece775c92 100644 --- a/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java +++ b/server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java @@ -54,6 +54,8 @@ import org.apache.cloudstack.framework.jobs.dao.AsyncJobJoinMapDao; import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; +import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; @@ -113,6 +115,7 @@ import com.cloud.user.User; import com.cloud.user.UserVO; import com.cloud.user.dao.AccountDao; import com.cloud.utils.db.TransactionLegacy; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.fsm.NoTransitionException; import com.cloud.vm.UserVmManager; import com.cloud.vm.UserVmVO; @@ -210,6 +213,8 @@ public class VolumeApiServiceImplTest { @Mock private ProjectManager projectManagerMock; + @Mock + private StoragePoolDetailsDao storagePoolDetailsDao; private long accountMockId = 456l; private long volumeMockId = 12313l; private long vmInstanceMockId = 1123l; @@ -1563,4 +1568,56 @@ public class VolumeApiServiceImplTest { Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM); Assert.assertFalse(volumeApiServiceImpl.isSendCommandForVmVolumeAttachDetach(host, Mockito.mock(StoragePoolVO.class))); } + + @Test + public void testVolumeOnDifferentScaleIOStorageInstance() { + StoragePoolDetailVO srcPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String srcPoolSystemId = "610204d03e3ad60f"; + when(srcPoolSystemIdDetail.getValue()).thenReturn(srcPoolSystemId); + + StoragePoolDetailVO destPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String destPoolSystemId = "7332760565f6340f"; + when(destPoolSystemIdDetail.getValue()).thenReturn(destPoolSystemId); + + when(storagePoolDetailsDao.findDetail(1L,"powerflex.storagepool.system.id")).thenReturn(srcPoolSystemIdDetail); + when(storagePoolDetailsDao.findDetail(2L,"powerflex.storagepool.system.id")).thenReturn(destPoolSystemIdDetail); + + boolean result = volumeApiServiceImpl.isScaleIOVolumeOnDifferentScaleIOStorageInstances(1L, 2L); + + Assert.assertTrue(result); + } + + @Test + public void testVolumeOnSameScaleIOStorageInstance() { + StoragePoolDetailVO srcPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String srcPoolSystemId = "610204d03e3ad60f"; + when(srcPoolSystemIdDetail.getValue()).thenReturn(srcPoolSystemId); + + StoragePoolDetailVO destPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String destPoolSystemId = "610204d03e3ad60f"; + when(destPoolSystemIdDetail.getValue()).thenReturn(destPoolSystemId); + + when(storagePoolDetailsDao.findDetail(1L,"powerflex.storagepool.system.id")).thenReturn(srcPoolSystemIdDetail); + when(storagePoolDetailsDao.findDetail(2L,"powerflex.storagepool.system.id")).thenReturn(destPoolSystemIdDetail); + + boolean result = volumeApiServiceImpl.isScaleIOVolumeOnDifferentScaleIOStorageInstances(1L, 2L); + + Assert.assertFalse(result); + } + + @Test (expected = CloudRuntimeException.class) + public void testCheckVolumeOnDifferentScaleIOStorageInstanceSystemIdShouldNotBeNull() { + StoragePoolDetailVO srcPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + String srcPoolSystemId = "610204d03e3ad60f"; + when(srcPoolSystemIdDetail.getValue()).thenReturn(srcPoolSystemId); + + StoragePoolDetailVO destPoolSystemIdDetail = Mockito.mock(StoragePoolDetailVO.class); + when(destPoolSystemIdDetail.getValue()).thenReturn(null); + + when(storagePoolDetailsDao.findDetail(1L,"powerflex.storagepool.system.id")).thenReturn(srcPoolSystemIdDetail); + when(storagePoolDetailsDao.findDetail(2L,"powerflex.storagepool.system.id")).thenReturn(destPoolSystemIdDetail); + + volumeApiServiceImpl.isScaleIOVolumeOnDifferentScaleIOStorageInstances(1L, 2L); + } + }
