Skip to content

Commit 7441659

Browse files
committed
Direct Routed networks: let VM deploys with security groups target L3 networks
Deploying an Instance with securitygroupids into an L3 (Direct Routed) network failed with 'Can't create vm with security groups; security group feature is not enabled per zone' The message is misleading: the zone flag is only the first half of the gate. checkSecurityGroupSupportForNetwork() also accepts a deploy when one of the requested networks itself supports the SecurityGroup service - but that check compared the guest type against Shared only, so an L3 network carrying the SecurityGroup service (as DefaultL3NetworkOffering does) never qualified and the deploy fell through to the error. Accept GuestType.L3 alongside Shared. Every other security group touchpoint already treats L3 like Shared (offering validation, the secondary-IP paths, the security_group.py dispatch); this deploy-time gate was the one spot left behind. The zone-level securitygroupenabled flag stays untouched - it selects the legacy shared-only zone mode, which forbids public IP ranges and is exactly what a direct routed zone must not be.
1 parent 655530c commit 7441659

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

server/src/main/java/com/cloud/network/NetworkModelImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3097,7 +3097,8 @@ public boolean checkSecurityGroupSupportForNetwork(Account account, DataCenter z
30973097
if (network == null) {
30983098
throw new InvalidParameterValueException("Unable to find network by id " + networkId);
30993099
}
3100-
if (network.getGuestType() == Network.GuestType.Shared && isSecurityGroupSupportedInNetwork(network)) {
3100+
if ((network.getGuestType() == Network.GuestType.Shared || network.getGuestType() == Network.GuestType.L3)
3101+
&& isSecurityGroupSupportedInNetwork(network)) {
31013102
return true;
31023103
}
31033104
}

server/src/test/java/com/cloud/network/NetworkModelImplTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,35 @@ public void listSupportedNetworkServiceProvidersExcludesExtensionBackedProviders
452452
Mockito.verify(physicalNetworkServiceProviderDao, Mockito.times(1)).listAll();
453453
Mockito.verify(physicalNetworkServiceProviderDao, Mockito.never()).listBy(Mockito.anyLong());
454454
}
455+
456+
private boolean checkSecurityGroupSupportFor(Network.GuestType guestType, boolean sgSupportedInNetwork) {
457+
DataCenter zone = mock(DataCenter.class);
458+
when(zone.isSecurityGroupEnabled()).thenReturn(false);
459+
NetworkVO network = mock(NetworkVO.class);
460+
when(network.getGuestType()).thenReturn(guestType);
461+
when(_networksDao.findById(42L)).thenReturn(network);
462+
doReturn(sgSupportedInNetwork).when(networkModel).isSecurityGroupSupportedInNetwork(network);
463+
return networkModel.checkSecurityGroupSupportForNetwork(mock(com.cloud.user.Account.class), zone, List.of(42L), null);
464+
}
465+
466+
@Test
467+
public void checkSecurityGroupSupportForNetworkAcceptsSharedNetworkWithSecurityGroupService() {
468+
assertTrue(checkSecurityGroupSupportFor(Network.GuestType.Shared, true));
469+
}
470+
471+
/**
472+
* Regression: deploying with securitygroupids into an L3 (Direct Routed) network failed with
473+
* "security group feature is not enabled per zone" because the guest-type check accepted
474+
* only Shared, while L3 offerings carry the SecurityGroup service per network.
475+
*/
476+
@Test
477+
public void checkSecurityGroupSupportForNetworkAcceptsL3NetworkWithSecurityGroupService() {
478+
assertTrue(checkSecurityGroupSupportFor(Network.GuestType.L3, true));
479+
}
480+
481+
@Test
482+
public void checkSecurityGroupSupportForNetworkRejectsNetworkWithoutSecurityGroupService() {
483+
assertFalse(checkSecurityGroupSupportFor(Network.GuestType.L3, false));
484+
assertFalse(checkSecurityGroupSupportFor(Network.GuestType.Isolated, true));
485+
}
455486
}

0 commit comments

Comments
 (0)