9797import com .cloud .user .dao .UserDataDao ;
9898import com .cloud .utils .net .Ip ;
9999import com .cloud .vm .ConsoleSessionVO ;
100+ import com .cloud .vm .Nic ;
100101import com .cloud .vm .NicSecondaryIp ;
101102import com .cloud .vm .NicVO ;
102103import com .cloud .vm .VMInstanceVO ;
@@ -769,10 +770,13 @@ public void showVmInfoForSharedNetworksTestRouterIp() {
769770 IpAddress ipAddress = Mockito .mock (IpAddress .class );
770771 when (ipAddress .getAddress ()).thenReturn (new Ip ("10.1.1.2" ));
771772 when (ipAddress .getNetworkId ()).thenReturn (1L );
773+ NicVO placeholderNic = new NicVO (null , null , 1L , VirtualMachine .Type .DomainRouter );
774+ placeholderNic .setReservationStrategy (Nic .ReservationStrategy .PlaceHolder );
772775 NicVO routerNic = new NicVO ("DirectNetworkGuru" , 2L , 1L , VirtualMachine .Type .DomainRouter );
773776 IPAddressResponse ipResponse = Mockito .mock (IPAddressResponse .class );
774777
775778 try (MockedStatic <ApiDBUtils > ignored = Mockito .mockStatic (ApiDBUtils .class )) {
779+ when (ApiDBUtils .findByIp4AddressAndNetworkId ("10.1.1.2" , 1L )).thenReturn (placeholderNic );
776780 when (ApiDBUtils .findNonPlaceHolderByIp4AddressAndNetworkId ("10.1.1.2" , 1L )).thenReturn (routerNic );
777781 when (ApiDBUtils .findVMInstanceById (2L )).thenReturn (vmInstanceVOMock );
778782 when (vmInstanceVOMock .getUuid ()).thenReturn ("router-uuid" );
@@ -786,4 +790,24 @@ public void showVmInfoForSharedNetworksTestRouterIp() {
786790 verify (ipResponse ).setVirtualMachineName ("r-2-VM" );
787791 }
788792 }
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+ }
789813}
0 commit comments