|
31 | 31 | import java.util.List; |
32 | 32 | import java.util.Map; |
33 | 33 |
|
| 34 | +import com.cloud.exception.InvalidParameterValueException; |
| 35 | +import com.cloud.offering.ServiceOffering; |
34 | 36 | import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; |
35 | 37 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
36 | 38 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
| 39 | +import org.apache.commons.collections.CollectionUtils; |
37 | 40 | import org.junit.Assert; |
38 | 41 | import org.junit.Before; |
39 | 42 | import org.junit.Test; |
|
43 | 46 | import org.mockito.Mock; |
44 | 47 | import org.mockito.Mockito; |
45 | 48 | import org.mockito.Spy; |
46 | | -import org.mockito.runners.MockitoJUnitRunner; |
| 49 | +import org.mockito.junit.MockitoJUnitRunner; |
47 | 50 |
|
48 | 51 | import com.cloud.agent.AgentManager; |
49 | 52 | import com.cloud.agent.api.Command; |
@@ -624,4 +627,59 @@ public void matchesOfSorts() { |
624 | 627 | assertTrue(VirtualMachineManagerImpl.matches(tags,three)); |
625 | 628 | assertTrue(VirtualMachineManagerImpl.matches(others,three)); |
626 | 629 | } |
| 630 | + |
| 631 | + @Test |
| 632 | + public void isRootVolumeOnLocalStorageTestOnLocal() { |
| 633 | + prepareAndTestIsRootVolumeOnLocalStorage(ScopeType.HOST, true); |
| 634 | + } |
| 635 | + |
| 636 | + @Test |
| 637 | + public void isRootVolumeOnLocalStorageTestCluster() { |
| 638 | + prepareAndTestIsRootVolumeOnLocalStorage(ScopeType.CLUSTER, false); |
| 639 | + } |
| 640 | + |
| 641 | + @Test |
| 642 | + public void isRootVolumeOnLocalStorageTestZone() { |
| 643 | + prepareAndTestIsRootVolumeOnLocalStorage(ScopeType.ZONE, false); |
| 644 | + } |
| 645 | + |
| 646 | + private void prepareAndTestIsRootVolumeOnLocalStorage(ScopeType scope, boolean expected) { |
| 647 | + StoragePoolVO storagePoolVoMock = Mockito.mock(StoragePoolVO.class); |
| 648 | + Mockito.doReturn(storagePoolVoMock).when(storagePoolDaoMock).findById(Mockito.anyLong()); |
| 649 | + Mockito.doReturn(scope).when(storagePoolVoMock).getScope(); |
| 650 | + List<VolumeVO> mockedVolumes = new ArrayList<>(); |
| 651 | + mockedVolumes.add(volumeVoMock); |
| 652 | + Mockito.doReturn(mockedVolumes).when(volumeDaoMock).findByInstanceAndType(Mockito.anyLong(), Mockito.any()); |
| 653 | + |
| 654 | + boolean result = virtualMachineManagerImpl.isRootVolumeOnLocalStorage(0l); |
| 655 | + |
| 656 | + Assert.assertEquals(expected, result); |
| 657 | + } |
| 658 | + |
| 659 | + @Test |
| 660 | + public void checkIfNewOfferingStorageScopeMatchesStoragePoolTestLocalLocal() { |
| 661 | + prepareAndRunCheckIfNewOfferingStorageScopeMatchesStoragePool(true, true); |
| 662 | + } |
| 663 | + |
| 664 | + @Test |
| 665 | + public void checkIfNewOfferingStorageScopeMatchesStoragePoolTestSharedShared() { |
| 666 | + prepareAndRunCheckIfNewOfferingStorageScopeMatchesStoragePool(false, false); |
| 667 | + } |
| 668 | + |
| 669 | + @Test (expected = InvalidParameterValueException.class) |
| 670 | + public void checkIfNewOfferingStorageScopeMatchesStoragePoolTestLocalShared() { |
| 671 | + prepareAndRunCheckIfNewOfferingStorageScopeMatchesStoragePool(true, false); |
| 672 | + } |
| 673 | + |
| 674 | + @Test (expected = InvalidParameterValueException.class) |
| 675 | + public void checkIfNewOfferingStorageScopeMatchesStoragePoolTestSharedLocal() { |
| 676 | + prepareAndRunCheckIfNewOfferingStorageScopeMatchesStoragePool(false, true); |
| 677 | + } |
| 678 | + |
| 679 | + private void prepareAndRunCheckIfNewOfferingStorageScopeMatchesStoragePool(boolean isRootOnLocal, boolean isOfferingUsingLocal) { |
| 680 | + Mockito.doReturn(isRootOnLocal).when(virtualMachineManagerImpl).isRootVolumeOnLocalStorage(Mockito.anyLong()); |
| 681 | + Mockito.doReturn("vmInstanceMockedToString").when(vmInstanceMock).toString(); |
| 682 | + Mockito.doReturn(isOfferingUsingLocal).when(serviceOfferingMock).isUseLocalStorage(); |
| 683 | + virtualMachineManagerImpl.checkIfNewOfferingStorageScopeMatchesStoragePool(vmInstanceMock, serviceOfferingMock); |
| 684 | + } |
627 | 685 | } |
0 commit comments