|
42 | 42 | import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse; |
43 | 43 | import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse; |
44 | 44 | import org.apache.cloudstack.api.response.GuestOSCategoryResponse; |
| 45 | +import org.apache.cloudstack.api.response.IPAddressResponse; |
45 | 46 | import org.apache.cloudstack.api.response.IpQuarantineResponse; |
46 | 47 | import org.apache.cloudstack.api.response.NicSecondaryIpResponse; |
47 | 48 | import org.apache.cloudstack.api.response.ResourceIconResponse; |
|
68 | 69 | import com.cloud.configuration.Resource; |
69 | 70 | import com.cloud.domain.DomainVO; |
70 | 71 | import com.cloud.host.HostVO; |
| 72 | +import com.cloud.network.IpAddress; |
71 | 73 | import com.cloud.network.PublicIpQuarantine; |
72 | 74 | import com.cloud.network.as.AutoScaleVmGroup; |
73 | 75 | import com.cloud.network.as.AutoScaleVmGroupVO; |
|
95 | 97 | import com.cloud.user.dao.UserDataDao; |
96 | 98 | import com.cloud.utils.net.Ip; |
97 | 99 | import com.cloud.vm.ConsoleSessionVO; |
| 100 | +import com.cloud.vm.Nic; |
98 | 101 | import com.cloud.vm.NicSecondaryIp; |
| 102 | +import com.cloud.vm.NicVO; |
99 | 103 | import com.cloud.vm.VMInstanceVO; |
| 104 | +import com.cloud.vm.VirtualMachine; |
100 | 105 | import org.apache.cloudstack.api.ResponseObject; |
101 | 106 | import org.apache.cloudstack.api.response.ConsoleSessionResponse; |
102 | 107 |
|
@@ -759,4 +764,50 @@ public void createConsoleSessionResponseTestShouldReturnFullResponse() { |
759 | 764 | Assert.assertEquals(expected.getVmName(), response.getVmName()); |
760 | 765 | } |
761 | 766 | } |
| 767 | + |
| 768 | + @Test |
| 769 | + public void showVmInfoForSharedNetworksTestRouterIp() { |
| 770 | + IpAddress ipAddress = Mockito.mock(IpAddress.class); |
| 771 | + when(ipAddress.getAddress()).thenReturn(new Ip("10.1.1.2")); |
| 772 | + when(ipAddress.getNetworkId()).thenReturn(1L); |
| 773 | + NicVO placeholderNic = new NicVO(null, null, 1L, VirtualMachine.Type.DomainRouter); |
| 774 | + placeholderNic.setReservationStrategy(Nic.ReservationStrategy.PlaceHolder); |
| 775 | + NicVO routerNic = new NicVO("DirectNetworkGuru", 2L, 1L, VirtualMachine.Type.DomainRouter); |
| 776 | + IPAddressResponse ipResponse = Mockito.mock(IPAddressResponse.class); |
| 777 | + |
| 778 | + try (MockedStatic<ApiDBUtils> ignored = Mockito.mockStatic(ApiDBUtils.class)) { |
| 779 | + when(ApiDBUtils.findByIp4AddressAndNetworkId("10.1.1.2", 1L)).thenReturn(placeholderNic); |
| 780 | + when(ApiDBUtils.findNonPlaceHolderByIp4AddressAndNetworkId("10.1.1.2", 1L)).thenReturn(routerNic); |
| 781 | + when(ApiDBUtils.findVMInstanceById(2L)).thenReturn(vmInstanceVOMock); |
| 782 | + when(vmInstanceVOMock.getUuid()).thenReturn("router-uuid"); |
| 783 | + when(vmInstanceVOMock.getHostName()).thenReturn("r-2-VM"); |
| 784 | + when(vmInstanceVOMock.getType()).thenReturn(VirtualMachine.Type.DomainRouter); |
| 785 | + |
| 786 | + apiResponseHelper.showVmInfoForSharedNetworks(false, ipAddress, ipResponse); |
| 787 | + |
| 788 | + verify(ipResponse).setIsSystem(true); |
| 789 | + verify(ipResponse).setVirtualMachineId("router-uuid"); |
| 790 | + verify(ipResponse).setVirtualMachineName("r-2-VM"); |
| 791 | + } |
| 792 | + } |
| 793 | + |
| 794 | + @Test |
| 795 | + public void showVmInfoForSharedNetworksTestRouterPlaceholderOnly() { |
| 796 | + IpAddress ipAddress = Mockito.mock(IpAddress.class); |
| 797 | + when(ipAddress.getAddress()).thenReturn(new Ip("10.1.1.2")); |
| 798 | + when(ipAddress.getNetworkId()).thenReturn(1L); |
| 799 | + NicVO placeholderNic = new NicVO(null, null, 1L, VirtualMachine.Type.DomainRouter); |
| 800 | + placeholderNic.setReservationStrategy(Nic.ReservationStrategy.PlaceHolder); |
| 801 | + IPAddressResponse ipResponse = Mockito.mock(IPAddressResponse.class); |
| 802 | + |
| 803 | + try (MockedStatic<ApiDBUtils> ignored = Mockito.mockStatic(ApiDBUtils.class)) { |
| 804 | + when(ApiDBUtils.findNonPlaceHolderByIp4AddressAndNetworkId("10.1.1.2", 1L)).thenReturn(null); |
| 805 | + when(ApiDBUtils.findByIp4AddressAndNetworkId("10.1.1.2", 1L)).thenReturn(placeholderNic); |
| 806 | + |
| 807 | + apiResponseHelper.showVmInfoForSharedNetworks(false, ipAddress, ipResponse); |
| 808 | + |
| 809 | + verify(ipResponse).setIsSystem(true); |
| 810 | + verify(ipResponse, Mockito.never()).setVirtualMachineId(Mockito.anyString()); |
| 811 | + } |
| 812 | + } |
762 | 813 | } |
0 commit comments