|
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; |
|
96 | 98 | import com.cloud.utils.net.Ip; |
97 | 99 | import com.cloud.vm.ConsoleSessionVO; |
98 | 100 | import com.cloud.vm.NicSecondaryIp; |
| 101 | +import com.cloud.vm.NicVO; |
99 | 102 | import com.cloud.vm.VMInstanceVO; |
| 103 | +import com.cloud.vm.VirtualMachine; |
100 | 104 | import org.apache.cloudstack.api.ResponseObject; |
101 | 105 | import org.apache.cloudstack.api.response.ConsoleSessionResponse; |
102 | 106 |
|
@@ -759,4 +763,27 @@ public void createConsoleSessionResponseTestShouldReturnFullResponse() { |
759 | 763 | Assert.assertEquals(expected.getVmName(), response.getVmName()); |
760 | 764 | } |
761 | 765 | } |
| 766 | + |
| 767 | + @Test |
| 768 | + public void showVmInfoForSharedNetworksTestRouterIp() { |
| 769 | + IpAddress ipAddress = Mockito.mock(IpAddress.class); |
| 770 | + when(ipAddress.getAddress()).thenReturn(new Ip("10.1.1.2")); |
| 771 | + when(ipAddress.getNetworkId()).thenReturn(1L); |
| 772 | + NicVO routerNic = new NicVO("DirectNetworkGuru", 2L, 1L, VirtualMachine.Type.DomainRouter); |
| 773 | + IPAddressResponse ipResponse = Mockito.mock(IPAddressResponse.class); |
| 774 | + |
| 775 | + try (MockedStatic<ApiDBUtils> ignored = Mockito.mockStatic(ApiDBUtils.class)) { |
| 776 | + when(ApiDBUtils.findNonPlaceHolderByIp4AddressAndNetworkId("10.1.1.2", 1L)).thenReturn(routerNic); |
| 777 | + when(ApiDBUtils.findVMInstanceById(2L)).thenReturn(vmInstanceVOMock); |
| 778 | + when(vmInstanceVOMock.getUuid()).thenReturn("router-uuid"); |
| 779 | + when(vmInstanceVOMock.getHostName()).thenReturn("r-2-VM"); |
| 780 | + when(vmInstanceVOMock.getType()).thenReturn(VirtualMachine.Type.DomainRouter); |
| 781 | + |
| 782 | + apiResponseHelper.showVmInfoForSharedNetworks(false, ipAddress, ipResponse); |
| 783 | + |
| 784 | + verify(ipResponse).setIsSystem(true); |
| 785 | + verify(ipResponse).setVirtualMachineId("router-uuid"); |
| 786 | + verify(ipResponse).setVirtualMachineName("r-2-VM"); |
| 787 | + } |
| 788 | + } |
762 | 789 | } |
0 commit comments