Skip to content

Commit aba75f3

Browse files
Add VPC firewall check
1 parent 18da777 commit aba75f3

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

server/src/main/java/com/cloud/network/firewall/FirewallManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ protected void validateFirewallRuleForVpc(Account caller, IPAddressVO ipAddress,
434434
Map<Network.Capability, String> caps = null;
435435
if (purpose == Purpose.Firewall) {
436436
caps = getFirewallServiceCapabilitiesForVpc(vpcId);
437+
if (caps == null) {
438+
throw new InvalidParameterValueException("Firewall service is not supported in VPC " + vpc);
439+
}
437440
}
438441

439442
if (caps != null) {

server/src/test/java/com/cloud/network/firewall/FirewallManagerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,17 @@ public void testValidateFirewallRuleForVpcThrowsWhenActiveVpcNotFound() {
549549
_firewallMgr.validateFirewallRuleForVpc(caller, ipAddress, 80, 80, "tcp", Purpose.Firewall, FirewallRuleType.User, 10L, FirewallRule.TrafficType.Ingress);
550550
}
551551

552+
@Test(expected = InvalidParameterValueException.class)
553+
public void testValidateFirewallRuleForVpcThrowsWhenFirewallServiceNotSupported() {
554+
Account caller = Mockito.mock(Account.class);
555+
IPAddressVO ipAddress = Mockito.mock(IPAddressVO.class);
556+
Vpc vpc = Mockito.mock(Vpc.class);
557+
when(_vpcMgr.getActiveVpc(10L)).thenReturn(vpc);
558+
_firewallMgr._firewallElements = Collections.emptyList();
559+
560+
_firewallMgr.validateFirewallRuleForVpc(caller, ipAddress, 80, 80, "tcp", Purpose.Firewall, FirewallRuleType.User, 10L, FirewallRule.TrafficType.Ingress);
561+
}
562+
552563
@Test(expected = InvalidParameterValueException.class)
553564
public void testValidateFirewallRuleForVpcThrowsOnUnsupportedProtocol() {
554565
Account caller = Mockito.mock(Account.class);

0 commit comments

Comments
 (0)