@@ -331,6 +331,7 @@ public void testCreateVpnGatewayNoSourceNatIp() {
331331 CreateVpnGatewayCmd cmd = mock (CreateVpnGatewayCmd .class );
332332 when (cmd .getVpcId ()).thenReturn (VPC_ID );
333333 when (cmd .getEntityOwnerId ()).thenReturn (ACCOUNT_ID );
334+ when (cmd .getIpAddressId ()).thenReturn (null );
334335
335336 when (_vpcDao .findById (VPC_ID )).thenReturn (vpc );
336337 when (_vpnGatewayDao .findByVpcId (VPC_ID )).thenReturn (null );
@@ -340,6 +341,46 @@ public void testCreateVpnGatewayNoSourceNatIp() {
340341 site2SiteVpnManager .createVpnGateway (cmd );
341342 }
342343
344+ @ Test
345+ public void testCreateVpnGatewaySkipsSystemVmSourceNatIp () {
346+ CreateVpnGatewayCmd cmd = mock (CreateVpnGatewayCmd .class );
347+ when (cmd .getVpcId ()).thenReturn (VPC_ID );
348+ when (cmd .getEntityOwnerId ()).thenReturn (ACCOUNT_ID );
349+ when (cmd .getIpAddressId ()).thenReturn (null );
350+ when (cmd .isDisplay ()).thenReturn (true );
351+ IPAddressVO systemVmIp = mock (IPAddressVO .class );
352+ when (systemVmIp .isForSystemVms ()).thenReturn (true );
353+ when (_vpcDao .findById (VPC_ID )).thenReturn (vpc );
354+ when (_vpnGatewayDao .findByVpcId (VPC_ID )).thenReturn (null );
355+ mockVpcVirtualRouterProvider ();
356+ when (_ipAddressDao .listByAssociatedVpc (VPC_ID , true )).thenReturn (List .of (systemVmIp , ipAddress ));
357+ when (_vpnGatewayDao .persist (any (Site2SiteVpnGatewayVO .class ))).thenReturn (vpnGateway );
358+
359+ Site2SiteVpnGateway result = site2SiteVpnManager .createVpnGateway (cmd );
360+
361+ assertNotNull (result );
362+ ArgumentCaptor <Site2SiteVpnGatewayVO > gatewayCaptor = ArgumentCaptor .forClass (Site2SiteVpnGatewayVO .class );
363+ verify (_vpnGatewayDao ).persist (gatewayCaptor .capture ());
364+ assertEquals (IP_ADDRESS_ID .longValue (), gatewayCaptor .getValue ().getAddrId ());
365+ }
366+
367+ @ Test (expected = CloudRuntimeException .class )
368+ public void testCreateVpnGatewayRejectsMultipleCustomerSourceNatIps () {
369+ CreateVpnGatewayCmd cmd = mock (CreateVpnGatewayCmd .class );
370+ when (cmd .getVpcId ()).thenReturn (VPC_ID );
371+ when (cmd .getEntityOwnerId ()).thenReturn (ACCOUNT_ID );
372+ when (cmd .getIpAddressId ()).thenReturn (null );
373+ IPAddressVO secondIp = mock (IPAddressVO .class );
374+ when (ipAddress .getAddress ()).thenReturn (new Ip ("203.0.113.34" ));
375+ when (secondIp .getAddress ()).thenReturn (new Ip ("203.0.113.35" ));
376+ when (_vpcDao .findById (VPC_ID )).thenReturn (vpc );
377+ when (_vpnGatewayDao .findByVpcId (VPC_ID )).thenReturn (null );
378+ mockVpcVirtualRouterProvider ();
379+ when (_ipAddressDao .listByAssociatedVpc (VPC_ID , true )).thenReturn (List .of (ipAddress , secondIp ));
380+
381+ site2SiteVpnManager .createVpnGateway (cmd );
382+ }
383+
343384 @ Test (expected = InvalidParameterValueException .class )
344385 public void testCreateCustomerGatewayInvalidIp () {
345386 CreateVpnCustomerGatewayCmd cmd = mock (CreateVpnCustomerGatewayCmd .class );
0 commit comments