mirror of https://github.com/apache/cloudstack.git
Unit tests to check if volume belongs to same or different storage scaleio cluster
This commit is contained in:
parent
32c083ded3
commit
dedd104d48
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue