mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
engine/orchestration: enable unit tests and fix errors (#7034)
The unit tests in engine/orchestration module are skipped for now. This PR enables the unit tests and fixes the errors with the unit tests.
This commit is contained in:
parent
1c2728da91
commit
0bedb58fbe
@ -73,9 +73,6 @@
|
|||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
|
||||||
<skipTests>true</skipTests>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>integration-test</phase>
|
<phase>integration-test</phase>
|
||||||
|
|||||||
@ -26,16 +26,13 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.cloud.agent.api.routing.NetworkElementCommand;
|
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
|
||||||
import com.cloud.storage.StorageManager;
|
|
||||||
import com.cloud.host.Host;
|
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
|
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||||
@ -55,16 +52,22 @@ import com.cloud.agent.AgentManager;
|
|||||||
import com.cloud.agent.api.Command;
|
import com.cloud.agent.api.Command;
|
||||||
import com.cloud.agent.api.StopAnswer;
|
import com.cloud.agent.api.StopAnswer;
|
||||||
import com.cloud.agent.api.StopCommand;
|
import com.cloud.agent.api.StopCommand;
|
||||||
|
import com.cloud.agent.api.routing.NetworkElementCommand;
|
||||||
|
import com.cloud.api.query.dao.UserVmJoinDao;
|
||||||
import com.cloud.deploy.DataCenterDeployment;
|
import com.cloud.deploy.DataCenterDeployment;
|
||||||
import com.cloud.deploy.DeploymentPlan;
|
import com.cloud.deploy.DeploymentPlan;
|
||||||
import com.cloud.deploy.DeploymentPlanner;
|
import com.cloud.deploy.DeploymentPlanner;
|
||||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||||
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
|
import com.cloud.host.Host;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
|
import com.cloud.host.dao.HostDao;
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.service.ServiceOfferingVO;
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
import com.cloud.service.dao.ServiceOfferingDao;
|
import com.cloud.service.dao.ServiceOfferingDao;
|
||||||
import com.cloud.storage.DiskOfferingVO;
|
import com.cloud.storage.DiskOfferingVO;
|
||||||
import com.cloud.storage.ScopeType;
|
import com.cloud.storage.ScopeType;
|
||||||
|
import com.cloud.storage.StorageManager;
|
||||||
import com.cloud.storage.StoragePool;
|
import com.cloud.storage.StoragePool;
|
||||||
import com.cloud.storage.StoragePoolHostVO;
|
import com.cloud.storage.StoragePoolHostVO;
|
||||||
import com.cloud.storage.Volume;
|
import com.cloud.storage.Volume;
|
||||||
@ -74,6 +77,7 @@ import com.cloud.storage.dao.StoragePoolHostDao;
|
|||||||
import com.cloud.storage.dao.VolumeDao;
|
import com.cloud.storage.dao.VolumeDao;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.vm.VirtualMachine.State;
|
import com.cloud.vm.VirtualMachine.State;
|
||||||
|
import com.cloud.vm.dao.UserVmDao;
|
||||||
import com.cloud.vm.dao.VMInstanceDao;
|
import com.cloud.vm.dao.VMInstanceDao;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
@ -103,6 +107,8 @@ public class VirtualMachineManagerImplTest {
|
|||||||
private DiskOfferingVO diskOfferingMock;
|
private DiskOfferingVO diskOfferingMock;
|
||||||
|
|
||||||
private long hostMockId = 1L;
|
private long hostMockId = 1L;
|
||||||
|
private long clusterMockId = 2L;
|
||||||
|
private long zoneMockId = 3L;
|
||||||
@Mock
|
@Mock
|
||||||
private HostVO hostMock;
|
private HostVO hostMock;
|
||||||
@Mock
|
@Mock
|
||||||
@ -128,22 +134,34 @@ public class VirtualMachineManagerImplTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private DiskOfferingDao diskOfferingDaoMock;
|
private DiskOfferingDao diskOfferingDaoMock;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private HostDao hostDaoMock;
|
||||||
|
@Mock
|
||||||
|
private UserVmJoinDao userVmJoinDaoMock;
|
||||||
|
@Mock
|
||||||
|
private UserVmDao userVmDaoMock;
|
||||||
|
@Mock
|
||||||
|
private UserVmVO userVmMock;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
virtualMachineManagerImpl.setHostAllocators(new ArrayList<>());
|
virtualMachineManagerImpl.setHostAllocators(new ArrayList<>());
|
||||||
|
|
||||||
when(vmInstanceMock.getId()).thenReturn(vmInstanceVoMockId);
|
when(vmInstanceMock.getId()).thenReturn(vmInstanceVoMockId);
|
||||||
when(vmInstanceMock.getServiceOfferingId()).thenReturn(2L);
|
when(vmInstanceMock.getServiceOfferingId()).thenReturn(2L);
|
||||||
when(vmInstanceMock.getInstanceName()).thenReturn("myVm");
|
|
||||||
when(vmInstanceMock.getHostId()).thenReturn(2L);
|
|
||||||
when(vmInstanceMock.getType()).thenReturn(VirtualMachine.Type.User);
|
|
||||||
when(hostMock.getId()).thenReturn(hostMockId);
|
when(hostMock.getId()).thenReturn(hostMockId);
|
||||||
when(dataCenterDeploymentMock.getHostId()).thenReturn(hostMockId);
|
when(dataCenterDeploymentMock.getHostId()).thenReturn(hostMockId);
|
||||||
|
when(dataCenterDeploymentMock.getClusterId()).thenReturn(clusterMockId);
|
||||||
|
|
||||||
|
when(hostMock.getDataCenterId()).thenReturn(zoneMockId);
|
||||||
|
when(hostDaoMock.findById(any())).thenReturn(hostMock);
|
||||||
|
|
||||||
|
when(userVmJoinDaoMock.searchByIds(any())).thenReturn(new ArrayList<>());
|
||||||
|
when(userVmDaoMock.findById(any())).thenReturn(userVmMock);
|
||||||
|
|
||||||
Mockito.doReturn(vmInstanceVoMockId).when(virtualMachineProfileMock).getId();
|
Mockito.doReturn(vmInstanceVoMockId).when(virtualMachineProfileMock).getId();
|
||||||
|
|
||||||
Mockito.doReturn(storagePoolVoMockId).when(storagePoolVoMock).getId();
|
Mockito.doReturn(storagePoolVoMockId).when(storagePoolVoMock).getId();
|
||||||
Mockito.doReturn(storagePoolVoMockClusterId).when(storagePoolVoMock).getClusterId();
|
|
||||||
|
|
||||||
Mockito.doReturn(volumeMockId).when(volumeVoMock).getId();
|
Mockito.doReturn(volumeMockId).when(volumeVoMock).getId();
|
||||||
Mockito.doReturn(storagePoolVoMockId).when(volumeVoMock).getPoolId();
|
Mockito.doReturn(storagePoolVoMockId).when(volumeVoMock).getPoolId();
|
||||||
@ -191,7 +209,6 @@ public class VirtualMachineManagerImplTest {
|
|||||||
|
|
||||||
when(testConfig.valueIn(dataCenterId)).thenReturn(false);
|
when(testConfig.valueIn(dataCenterId)).thenReturn(false);
|
||||||
when(vmHost.getDataCenterId()).thenReturn(dataCenterId);
|
when(vmHost.getDataCenterId()).thenReturn(dataCenterId);
|
||||||
when(vmHost.getPrivateIpAddress()).thenReturn(hostIp);
|
|
||||||
|
|
||||||
virtualMachineManagerImpl.addHostIpToCertDetailsIfConfigAllows(vmHost, ipAddresses, testConfig);
|
virtualMachineManagerImpl.addHostIpToCertDetailsIfConfigAllows(vmHost, ipAddresses, testConfig);
|
||||||
assertFalse(ipAddresses.containsKey(NetworkElementCommand.HYPERVISOR_HOST_PRIVATE_IP));
|
assertFalse(ipAddresses.containsKey(NetworkElementCommand.HYPERVISOR_HOST_PRIVATE_IP));
|
||||||
@ -201,9 +218,6 @@ public class VirtualMachineManagerImplTest {
|
|||||||
|
|
||||||
@Test(expected = CloudRuntimeException.class)
|
@Test(expected = CloudRuntimeException.class)
|
||||||
public void testScaleVM3() throws Exception {
|
public void testScaleVM3() throws Exception {
|
||||||
when(vmInstanceMock.getHostId()).thenReturn(null);
|
|
||||||
when(vmInstanceDaoMock.findById(anyLong())).thenReturn(vmInstanceMock);
|
|
||||||
when(vmInstanceDaoMock.findByUuid(any(String.class))).thenReturn(vmInstanceMock);
|
|
||||||
DeploymentPlanner.ExcludeList excludeHostList = new DeploymentPlanner.ExcludeList();
|
DeploymentPlanner.ExcludeList excludeHostList = new DeploymentPlanner.ExcludeList();
|
||||||
virtualMachineManagerImpl.findHostAndMigrate(vmInstanceMock.getUuid(), 2l, null, excludeHostList);
|
virtualMachineManagerImpl.findHostAndMigrate(vmInstanceMock.getUuid(), 2l, null, excludeHostList);
|
||||||
}
|
}
|
||||||
@ -258,19 +272,26 @@ public class VirtualMachineManagerImplTest {
|
|||||||
assertTrue(virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.KVM) == false);
|
assertTrue(virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.KVM) == false);
|
||||||
assertTrue(virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.Ovm3) == VirtualMachineManager.ExecuteInSequence.value());
|
assertTrue(virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.Ovm3) == VirtualMachineManager.ExecuteInSequence.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void overrideDefaultConfigValue(final ConfigKey configKey, final String value) throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
final Field f = ConfigKey.class.getDeclaredField("_defaultValue");
|
||||||
|
f.setAccessible(true);
|
||||||
|
f.set(configKey, value);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExeceuteInSequenceVmware() {
|
public void testExeceuteInSequenceVmware() throws IllegalAccessException, NoSuchFieldException {
|
||||||
when(StorageManager.getFullCloneConfiguration(anyLong())).thenReturn(Boolean.FALSE);
|
overrideDefaultConfigValue(StorageManager.VmwareCreateCloneFull, "false");
|
||||||
when(StorageManager.getAllowParallelExecutionConfiguration()).thenReturn(Boolean.FALSE);
|
overrideDefaultConfigValue(StorageManager.VmwareAllowParallelExecution, "false");
|
||||||
assertFalse("no full clones so no need to execute in sequence", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
assertFalse("no full clones so no need to execute in sequence", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
||||||
when(StorageManager.getFullCloneConfiguration(anyLong())).thenReturn(Boolean.TRUE);
|
overrideDefaultConfigValue(StorageManager.VmwareCreateCloneFull, "true");
|
||||||
when(StorageManager.getAllowParallelExecutionConfiguration()).thenReturn(Boolean.FALSE);
|
overrideDefaultConfigValue(StorageManager.VmwareAllowParallelExecution, "false");
|
||||||
assertTrue("full clones and no explicit parallel execution allowed, should execute in sequence", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
assertTrue("full clones and no explicit parallel execution allowed, should execute in sequence", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
||||||
when(StorageManager.getFullCloneConfiguration(anyLong())).thenReturn(Boolean.TRUE);
|
overrideDefaultConfigValue(StorageManager.VmwareCreateCloneFull, "true");
|
||||||
when(StorageManager.getAllowParallelExecutionConfiguration()).thenReturn(Boolean.TRUE);
|
overrideDefaultConfigValue(StorageManager.VmwareAllowParallelExecution, "true");
|
||||||
assertFalse("execute in sequence should not be needed as parallel is allowed", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
assertFalse("execute in sequence should not be needed as parallel is allowed", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
||||||
when(StorageManager.getFullCloneConfiguration(anyLong())).thenReturn(Boolean.FALSE);
|
overrideDefaultConfigValue(StorageManager.VmwareCreateCloneFull, "false");
|
||||||
when(StorageManager.getAllowParallelExecutionConfiguration()).thenReturn(Boolean.TRUE);
|
overrideDefaultConfigValue(StorageManager.VmwareAllowParallelExecution, "true");
|
||||||
assertFalse("double reasons to allow parallel execution", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
assertFalse("double reasons to allow parallel execution", virtualMachineManagerImpl.getExecuteInSequence(HypervisorType.VMware));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,18 +300,20 @@ public class VirtualMachineManagerImplTest {
|
|||||||
when(vmInstanceMock.getState()).thenReturn(State.Stopped);
|
when(vmInstanceMock.getState()).thenReturn(State.Stopped);
|
||||||
when(serviceOfferingMock.isDynamic()).thenReturn(true);
|
when(serviceOfferingMock.isDynamic()).thenReturn(true);
|
||||||
when(vmInstanceMock.getServiceOfferingId()).thenReturn(1l);
|
when(vmInstanceMock.getServiceOfferingId()).thenReturn(1l);
|
||||||
when(serviceOfferingMock.getId()).thenReturn(2l);
|
|
||||||
|
|
||||||
ServiceOfferingVO mockCurrentServiceOffering = mock(ServiceOfferingVO.class);
|
ServiceOfferingVO mockCurrentServiceOffering = mock(ServiceOfferingVO.class);
|
||||||
DiskOfferingVO mockCurrentDiskOffering = mock(DiskOfferingVO.class);
|
DiskOfferingVO mockCurrentDiskOffering = mock(DiskOfferingVO.class);
|
||||||
|
|
||||||
when(serviceOfferingDaoMock.findByIdIncludingRemoved(anyLong(), anyLong())).thenReturn(mockCurrentServiceOffering);
|
when(serviceOfferingDaoMock.findByIdIncludingRemoved(anyLong(), anyLong())).thenReturn(mockCurrentServiceOffering);
|
||||||
when(mockCurrentDiskOffering.isUseLocalStorage()).thenReturn(true);
|
when(diskOfferingDaoMock.findByIdIncludingRemoved(anyLong())).thenReturn(mockCurrentDiskOffering);
|
||||||
when(diskOfferingMock.isUseLocalStorage()).thenReturn(true);
|
when(diskOfferingDaoMock.findById(anyLong())).thenReturn(diskOfferingMock);
|
||||||
|
when(diskOfferingMock.isUseLocalStorage()).thenReturn(false);
|
||||||
when(mockCurrentServiceOffering.isSystemUse()).thenReturn(true);
|
when(mockCurrentServiceOffering.isSystemUse()).thenReturn(true);
|
||||||
when(serviceOfferingMock.isSystemUse()).thenReturn(true);
|
when(serviceOfferingMock.isSystemUse()).thenReturn(true);
|
||||||
when(mockCurrentDiskOffering.getTags()).thenReturn("x,y");
|
String[] oldDOStorageTags = {"x","y"};
|
||||||
when(diskOfferingMock.getTags()).thenReturn("z,x,y");
|
String[] newDOStorageTags = {"z","x","y"};
|
||||||
|
when(mockCurrentDiskOffering.getTagsArray()).thenReturn(oldDOStorageTags);
|
||||||
|
when(diskOfferingMock.getTagsArray()).thenReturn(newDOStorageTags);
|
||||||
|
|
||||||
virtualMachineManagerImpl.checkIfCanUpgrade(vmInstanceMock, serviceOfferingMock);
|
virtualMachineManagerImpl.checkIfCanUpgrade(vmInstanceMock, serviceOfferingMock);
|
||||||
}
|
}
|
||||||
@ -317,8 +340,6 @@ public class VirtualMachineManagerImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isStorageCrossClusterMigrationTestStorageTypeEqualsZone() {
|
public void isStorageCrossClusterMigrationTestStorageTypeEqualsZone() {
|
||||||
Mockito.doReturn(1L).when(hostMock).getClusterId();
|
|
||||||
Mockito.doReturn(2L).when(storagePoolVoMock).getClusterId();
|
|
||||||
Mockito.doReturn(ScopeType.ZONE).when(storagePoolVoMock).getScope();
|
Mockito.doReturn(ScopeType.ZONE).when(storagePoolVoMock).getScope();
|
||||||
|
|
||||||
boolean returnedValue = virtualMachineManagerImpl.isStorageCrossClusterMigration(1L, storagePoolVoMock);
|
boolean returnedValue = virtualMachineManagerImpl.isStorageCrossClusterMigration(1L, storagePoolVoMock);
|
||||||
@ -470,7 +491,7 @@ public class VirtualMachineManagerImplTest {
|
|||||||
Mockito.doReturn(poolListMock).when(storagePoolAllocatorMock).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class),
|
Mockito.doReturn(poolListMock).when(storagePoolAllocatorMock).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class),
|
||||||
Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
|
Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
|
||||||
|
|
||||||
Mockito.doReturn(true).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(hostMockId, storagePoolVoMock);
|
Mockito.doReturn(true).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(clusterMockId, storagePoolVoMock);
|
||||||
List<StoragePool> poolList = virtualMachineManagerImpl.getCandidateStoragePoolsToMigrateLocalVolume(virtualMachineProfileMock, dataCenterDeploymentMock, volumeVoMock);
|
List<StoragePool> poolList = virtualMachineManagerImpl.getCandidateStoragePoolsToMigrateLocalVolume(virtualMachineProfileMock, dataCenterDeploymentMock, volumeVoMock);
|
||||||
|
|
||||||
assertEquals(1, poolList.size());
|
assertEquals(1, poolList.size());
|
||||||
@ -489,7 +510,7 @@ public class VirtualMachineManagerImplTest {
|
|||||||
Mockito.doReturn(poolListMock).when(storagePoolAllocatorMock).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class),
|
Mockito.doReturn(poolListMock).when(storagePoolAllocatorMock).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class),
|
||||||
Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
|
Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
|
||||||
|
|
||||||
Mockito.doReturn(false).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(hostMockId, storagePoolVoMock);
|
Mockito.doReturn(false).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(clusterMockId, storagePoolVoMock);
|
||||||
List<StoragePool> poolList = virtualMachineManagerImpl.getCandidateStoragePoolsToMigrateLocalVolume(virtualMachineProfileMock, dataCenterDeploymentMock, volumeVoMock);
|
List<StoragePool> poolList = virtualMachineManagerImpl.getCandidateStoragePoolsToMigrateLocalVolume(virtualMachineProfileMock, dataCenterDeploymentMock, volumeVoMock);
|
||||||
|
|
||||||
Assert.assertTrue(poolList.isEmpty());
|
Assert.assertTrue(poolList.isEmpty());
|
||||||
@ -523,7 +544,7 @@ public class VirtualMachineManagerImplTest {
|
|||||||
Mockito.doReturn(new ArrayList<>()).when(storagePoolAllocatorMock3).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class),
|
Mockito.doReturn(new ArrayList<>()).when(storagePoolAllocatorMock3).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class),
|
||||||
Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
|
Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
|
||||||
|
|
||||||
Mockito.doReturn(false).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(hostMockId, storagePoolVoMock);
|
Mockito.doReturn(false).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(clusterMockId, storagePoolVoMock);
|
||||||
List<StoragePool> poolList = virtualMachineManagerImpl.getCandidateStoragePoolsToMigrateLocalVolume(virtualMachineProfileMock, dataCenterDeploymentMock, volumeVoMock);
|
List<StoragePool> poolList = virtualMachineManagerImpl.getCandidateStoragePoolsToMigrateLocalVolume(virtualMachineProfileMock, dataCenterDeploymentMock, volumeVoMock);
|
||||||
|
|
||||||
Assert.assertTrue(poolList.isEmpty());
|
Assert.assertTrue(poolList.isEmpty());
|
||||||
@ -604,14 +625,14 @@ public class VirtualMachineManagerImplTest {
|
|||||||
Mockito.doReturn(ScopeType.CLUSTER).when(storagePoolVoMock).getScope();
|
Mockito.doReturn(ScopeType.CLUSTER).when(storagePoolVoMock).getScope();
|
||||||
Mockito.doNothing().when(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(hostMock, storagePoolVoMock, volumeVoMock);
|
Mockito.doNothing().when(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(hostMock, storagePoolVoMock, volumeVoMock);
|
||||||
Mockito.doNothing().when(virtualMachineManagerImpl).createVolumeToStoragePoolMappingIfPossible(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumeVoMock, storagePoolVoMock);
|
Mockito.doNothing().when(virtualMachineManagerImpl).createVolumeToStoragePoolMappingIfPossible(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumeVoMock, storagePoolVoMock);
|
||||||
Mockito.doReturn(true).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(hostMockId, storagePoolVoMock);
|
Mockito.doReturn(true).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(clusterMockId, storagePoolVoMock);
|
||||||
|
|
||||||
virtualMachineManagerImpl.createStoragePoolMappingsForVolumes(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, allVolumes);
|
virtualMachineManagerImpl.createStoragePoolMappingsForVolumes(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, allVolumes);
|
||||||
|
|
||||||
Assert.assertTrue(volumeToPoolObjectMap.isEmpty());
|
Assert.assertTrue(volumeToPoolObjectMap.isEmpty());
|
||||||
Mockito.verify(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(hostMock, storagePoolVoMock, volumeVoMock);
|
Mockito.verify(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(hostMock, storagePoolVoMock, volumeVoMock);
|
||||||
Mockito.verify(virtualMachineManagerImpl).createVolumeToStoragePoolMappingIfPossible(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumeVoMock, storagePoolVoMock);
|
Mockito.verify(virtualMachineManagerImpl).createVolumeToStoragePoolMappingIfPossible(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumeVoMock, storagePoolVoMock);
|
||||||
Mockito.verify(virtualMachineManagerImpl).isStorageCrossClusterMigration(hostMockId, storagePoolVoMock);
|
Mockito.verify(virtualMachineManagerImpl).isStorageCrossClusterMigration(clusterMockId, storagePoolVoMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -623,7 +644,6 @@ public class VirtualMachineManagerImplTest {
|
|||||||
|
|
||||||
Mockito.doReturn(ScopeType.CLUSTER).when(storagePoolVoMock).getScope();
|
Mockito.doReturn(ScopeType.CLUSTER).when(storagePoolVoMock).getScope();
|
||||||
Mockito.doNothing().when(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(Mockito.any(), Mockito.any(), Mockito.any());
|
Mockito.doNothing().when(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(Mockito.any(), Mockito.any(), Mockito.any());
|
||||||
Mockito.doNothing().when(virtualMachineManagerImpl).createVolumeToStoragePoolMappingIfPossible(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
|
|
||||||
Mockito.doReturn(false).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(Mockito.anyLong(), Mockito.any());
|
Mockito.doReturn(false).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(Mockito.anyLong(), Mockito.any());
|
||||||
|
|
||||||
virtualMachineManagerImpl.createStoragePoolMappingsForVolumes(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, allVolumes);
|
virtualMachineManagerImpl.createStoragePoolMappingsForVolumes(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, allVolumes);
|
||||||
@ -632,7 +652,7 @@ public class VirtualMachineManagerImplTest {
|
|||||||
assertEquals(storagePoolVoMock, volumeToPoolObjectMap.get(volumeVoMock));
|
assertEquals(storagePoolVoMock, volumeToPoolObjectMap.get(volumeVoMock));
|
||||||
|
|
||||||
Mockito.verify(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(hostMock, storagePoolVoMock, volumeVoMock);
|
Mockito.verify(virtualMachineManagerImpl).executeManagedStorageChecksWhenTargetStoragePoolNotProvided(hostMock, storagePoolVoMock, volumeVoMock);
|
||||||
Mockito.verify(virtualMachineManagerImpl).isStorageCrossClusterMigration(hostMockId, storagePoolVoMock);
|
Mockito.verify(virtualMachineManagerImpl).isStorageCrossClusterMigration(clusterMockId, storagePoolVoMock);
|
||||||
Mockito.verify(virtualMachineManagerImpl, Mockito.times(0)).createVolumeToStoragePoolMappingIfPossible(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumeVoMock,
|
Mockito.verify(virtualMachineManagerImpl, Mockito.times(0)).createVolumeToStoragePoolMappingIfPossible(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumeVoMock,
|
||||||
storagePoolVoMock);
|
storagePoolVoMock);
|
||||||
}
|
}
|
||||||
@ -646,7 +666,8 @@ public class VirtualMachineManagerImplTest {
|
|||||||
Mockito.anyMapOf(Long.class, Long.class));
|
Mockito.anyMapOf(Long.class, Long.class));
|
||||||
|
|
||||||
Mockito.doReturn(volumesNotMapped).when(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap);
|
Mockito.doReturn(volumesNotMapped).when(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap);
|
||||||
Mockito.doNothing().when(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumesNotMapped);
|
Mockito.doNothing().when(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(Mockito.eq(virtualMachineProfileMock),
|
||||||
|
Mockito.any(DataCenterDeployment.class), Mockito.eq(volumeToPoolObjectMap), Mockito.eq(volumesNotMapped));
|
||||||
|
|
||||||
Map<Volume, StoragePool> mappingVolumeAndStoragePool = virtualMachineManagerImpl.createMappingVolumeAndStoragePool(virtualMachineProfileMock, hostMock, new HashMap<>());
|
Map<Volume, StoragePool> mappingVolumeAndStoragePool = virtualMachineManagerImpl.createMappingVolumeAndStoragePool(virtualMachineProfileMock, hostMock, new HashMap<>());
|
||||||
|
|
||||||
@ -655,7 +676,8 @@ public class VirtualMachineManagerImplTest {
|
|||||||
InOrder inOrder = Mockito.inOrder(virtualMachineManagerImpl);
|
InOrder inOrder = Mockito.inOrder(virtualMachineManagerImpl);
|
||||||
inOrder.verify(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), Mockito.anyMapOf(Long.class, Long.class));
|
inOrder.verify(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), Mockito.anyMapOf(Long.class, Long.class));
|
||||||
inOrder.verify(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap);
|
inOrder.verify(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap);
|
||||||
inOrder.verify(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(virtualMachineProfileMock, dataCenterDeploymentMock, volumeToPoolObjectMap, volumesNotMapped);
|
inOrder.verify(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(Mockito.eq(virtualMachineProfileMock),
|
||||||
|
Mockito.any(DataCenterDeployment.class), Mockito.eq(volumeToPoolObjectMap), Mockito.eq(volumesNotMapped));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -22,17 +22,19 @@ package org.apache.cloudstack.engine.provisioning.test;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceManager;
|
||||||
|
import org.apache.cloudstack.engine.service.api.ProvisioningServiceImpl;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Matchers;
|
import org.mockito.Matchers;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.mockito.Spy;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
|
import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
|
||||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
|
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
|
||||||
@ -51,46 +53,49 @@ import org.apache.cloudstack.engine.service.api.ProvisioningService;
|
|||||||
|
|
||||||
import com.cloud.dc.DataCenter.NetworkType;
|
import com.cloud.dc.DataCenter.NetworkType;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@ContextConfiguration(locations = "classpath:/resource/provisioningContext.xml")
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ProvisioningTest extends TestCase {
|
public class ProvisioningTest extends TestCase {
|
||||||
|
|
||||||
@Inject
|
@Spy
|
||||||
ProvisioningService service;
|
@InjectMocks
|
||||||
|
ProvisioningService service = new ProvisioningServiceImpl();
|
||||||
|
|
||||||
@Inject
|
@Mock
|
||||||
|
DataCenterResourceManager dataCenterResourceManager;
|
||||||
|
|
||||||
|
@Mock
|
||||||
EngineDataCenterDao dcDao;
|
EngineDataCenterDao dcDao;
|
||||||
|
|
||||||
@Inject
|
@Mock
|
||||||
EngineHostPodDao _podDao;
|
EngineHostPodDao _podDao;
|
||||||
|
|
||||||
@Inject
|
@Mock
|
||||||
EngineClusterDao _clusterDao;
|
EngineClusterDao _clusterDao;
|
||||||
|
|
||||||
@Inject
|
@Mock
|
||||||
EngineHostDao _hostDao;
|
EngineHostDao _hostDao;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
EngineDataCenterVO dataCenterVO;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
EngineHostPodVO podVO;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
EngineClusterVO clusterVO;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
EngineHostVO hostVO;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
EngineDataCenterVO dc =
|
Mockito.when(dataCenterResourceManager.loadDataCenter(any())).thenReturn(dataCenterVO);
|
||||||
new EngineDataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null,
|
Mockito.when(dataCenterResourceManager.loadPod(any())).thenReturn(podVO);
|
||||||
true, true, null, null);
|
Mockito.when(dataCenterResourceManager.loadCluster(any())).thenReturn(clusterVO);
|
||||||
Mockito.when(dcDao.findByUuid(Matchers.anyString())).thenReturn(dc);
|
Mockito.when(dataCenterResourceManager.loadHost(any())).thenReturn(hostVO);
|
||||||
Mockito.when(dcDao.persist((EngineDataCenterVO)Matchers.anyObject())).thenReturn(dc);
|
|
||||||
|
|
||||||
EngineHostPodVO pod = new EngineHostPodVO("lab", 123, "10.0.0.1", "10.0.0.1", 24, "test");
|
|
||||||
Mockito.when(_podDao.findByUuid(Matchers.anyString())).thenReturn(pod);
|
|
||||||
Mockito.when(_podDao.persist((EngineHostPodVO)Matchers.anyObject())).thenReturn(pod);
|
|
||||||
|
|
||||||
EngineClusterVO cluster = new EngineClusterVO();
|
|
||||||
Mockito.when(_clusterDao.findByUuid(Matchers.anyString())).thenReturn(cluster);
|
|
||||||
Mockito.when(_clusterDao.persist((EngineClusterVO)Matchers.anyObject())).thenReturn(cluster);
|
|
||||||
|
|
||||||
EngineHostVO host = new EngineHostVO("68765876598");
|
|
||||||
Mockito.when(_hostDao.findByUuid(Matchers.anyString())).thenReturn(host);
|
|
||||||
Mockito.when(_hostDao.persist((EngineHostVO)Matchers.anyObject())).thenReturn(host);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerAndEnableZone() {
|
private void registerAndEnableZone() {
|
||||||
|
|||||||
@ -1,47 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/tx
|
|
||||||
http://www.springframework.org/schema/tx/spring-tx.xsd
|
|
||||||
http://www.springframework.org/schema/aop
|
|
||||||
http://www.springframework.org/schema/aop/spring-aop.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
|
||||||
<context:annotation-config />
|
|
||||||
<context:component-scan base-package="org.apache.cloudstack.engine" />
|
|
||||||
|
|
||||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
|
||||||
<!-- bean id="aopTestBean" class="org.apache.cloudstack.storage.test.AopTestAdvice"/-->
|
|
||||||
<!-- aop:config proxy-target-class="true" >
|
|
||||||
<aop:aspect id="AopTestAdvice" ref="aopTestBean">
|
|
||||||
<aop:pointcut id="aoptest"
|
|
||||||
expression="@annotation(com.cloud.utils.db.DB)" />
|
|
||||||
<aop:around pointcut-ref="aoptest" method="AopTestMethod"/>
|
|
||||||
</aop:aspect>
|
|
||||||
</aop:config>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<bean class="org.apache.cloudstack.engine.provisioning.test.ChildTestConfiguration" />
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user