diff --git a/api/src/main/java/org/apache/cloudstack/network/RoutedIpv4Manager.java b/api/src/main/java/org/apache/cloudstack/network/RoutedIpv4Manager.java index b247130b579a..221a550ad630 100644 --- a/api/src/main/java/org/apache/cloudstack/network/RoutedIpv4Manager.java +++ b/api/src/main/java/org/apache/cloudstack/network/RoutedIpv4Manager.java @@ -203,4 +203,6 @@ public interface RoutedIpv4Manager extends PluggableService, Configurable { void removeBgpPeersByAccountId(long accountId); void removeBgpPeersByDomainId(long domainId); + + Boolean isRoutedNetworkVpcEnabled(long zoneId); } diff --git a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java index a815fb57240e..e6885bdb52f4 100644 --- a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java @@ -1395,7 +1395,7 @@ void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, Netw throw new InvalidParameterValueException("network cidr and cidr size are mutually exclusive"); } if (NetworkOffering.NetworkMode.ROUTED.equals(networkOffering.getNetworkMode()) - && !routedIpv4Manager.RoutedNetworkVpcEnabled.valueIn(zoneId)) { + && !routedIpv4Manager.isRoutedNetworkVpcEnabled(zoneId)) { throw new InvalidParameterValueException("Routed network is not enabled in this zone"); } if (NetworkOffering.NetworkMode.ROUTED.equals(networkOffering.getNetworkMode()) @@ -1409,11 +1409,11 @@ void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, Netw if (cidrSize == null) { throw new InvalidParameterValueException("network cidr or cidr size is required for Isolated networks with ROUTED mode"); } - Integer maxCidrSize = routedIpv4Manager.RoutedNetworkIPv4MaxCidrSize.valueIn(accountId); + Integer maxCidrSize = RoutedIpv4Manager.RoutedNetworkIPv4MaxCidrSize.valueIn(accountId); if (cidrSize > maxCidrSize) { throw new InvalidParameterValueException("network cidr size cannot be bigger than maximum cidr size " + maxCidrSize); } - Integer minCidrSize = routedIpv4Manager.RoutedNetworkIPv4MinCidrSize.valueIn(accountId); + Integer minCidrSize = RoutedIpv4Manager.RoutedNetworkIPv4MinCidrSize.valueIn(accountId); if (cidrSize < minCidrSize) { throw new InvalidParameterValueException("network cidr size cannot be smaller than minimum cidr size " + minCidrSize); } diff --git a/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java b/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java index 1e5f82877813..5083f11331cb 100644 --- a/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/network/RoutedIpv4ManagerImpl.java @@ -1640,4 +1640,9 @@ public void removeBgpPeersByAccountId(long accountId) { public void removeBgpPeersByDomainId(long domainId) { bgpPeerDao.removeByDomainId(domainId); } + + @Override + public Boolean isRoutedNetworkVpcEnabled(long zoneId) { + return RoutedNetworkVpcEnabled.valueIn(zoneId); + } } diff --git a/server/src/test/java/com/cloud/network/NetworkServiceImplTest.java b/server/src/test/java/com/cloud/network/NetworkServiceImplTest.java index 2d12a9883294..6999593f5bcd 100644 --- a/server/src/test/java/com/cloud/network/NetworkServiceImplTest.java +++ b/server/src/test/java/com/cloud/network/NetworkServiceImplTest.java @@ -763,6 +763,7 @@ public void testCreateIpv4RoutedNetwork() { prepareCreateNetworkDnsMocks(cmd, Network.GuestType.Isolated, false, false, true); when(networkOfferingVO.getNetworkMode()).thenReturn(NetworkOffering.NetworkMode.ROUTED); when(networkOfferingVO.getRoutingMode()).thenReturn(NetworkOffering.RoutingMode.Static); + when(routedIpv4Manager.isRoutedNetworkVpcEnabled(any())).thenReturn(true); when(routedIpv4Manager.isVirtualRouterGateway(networkOfferingVO)).thenReturn(true); doNothing().when(routedIpv4Manager).assignIpv4SubnetToNetwork(nullable(Network.class)); @@ -791,6 +792,7 @@ public void testCreateIpv4RoutedNetworkWithBgpPeersFailure1() { prepareCreateNetworkDnsMocks(cmd, Network.GuestType.Isolated, false, true, true); when(networkOfferingVO.getNetworkMode()).thenReturn(NetworkOffering.NetworkMode.ROUTED); when(networkOfferingVO.getRoutingMode()).thenReturn(NetworkOffering.RoutingMode.Static); + when(routedIpv4Manager.isRoutedNetworkVpcEnabled(any())).thenReturn(true); when(routedIpv4Manager.isVirtualRouterGateway(networkOfferingVO)).thenReturn(true); DataCenterVO zone = Mockito.mock(DataCenterVO.class); @@ -818,6 +820,7 @@ public void testCreateIpv4RoutedNetworkWithBgpPeersFailure2() { prepareCreateNetworkDnsMocks(cmd, Network.GuestType.Isolated, false, false, true); when(networkOfferingVO.getNetworkMode()).thenReturn(NetworkOffering.NetworkMode.ROUTED); when(networkOfferingVO.getRoutingMode()).thenReturn(NetworkOffering.RoutingMode.Static); + when(routedIpv4Manager.isRoutedNetworkVpcEnabled(any())).thenReturn(true); when(routedIpv4Manager.isVirtualRouterGateway(networkOfferingVO)).thenReturn(true); DataCenterVO zone = Mockito.mock(DataCenterVO.class); @@ -845,6 +848,7 @@ public void testCreateIpv4RoutedNetworkWithBgpPeersFailure3() { prepareCreateNetworkDnsMocks(cmd, Network.GuestType.Isolated, false, false, true); when(networkOfferingVO.getNetworkMode()).thenReturn(NetworkOffering.NetworkMode.ROUTED); when(networkOfferingVO.getRoutingMode()).thenReturn(NetworkOffering.RoutingMode.Static); + when(routedIpv4Manager.isRoutedNetworkVpcEnabled(any())).thenReturn(true); when(routedIpv4Manager.isVirtualRouterGateway(networkOfferingVO)).thenReturn(true); when(routedIpv4Manager.isDynamicRoutedNetwork(networkOfferingVO)).thenReturn(true); doThrow(new InvalidParameterValueException("validation error")).when(routedIpv4Manager).validateBgpPeers(nullable(Account.class), nullable(Long.class), any(List.class));