NPE fix for secRules,secGroups without tenantId on delete 13/63613/2
authorMichal Cmarada <mcmarada@cisco.com>
Wed, 27 Sep 2017 12:28:43 +0000 (14:28 +0200)
committerMichal Cmarada <mcmarada@cisco.com>
Wed, 27 Sep 2017 12:28:43 +0000 (14:28 +0200)
Some rules/groups that neutron configures don't use
TenantId, We didn't create those rules at first place, we
can skip the delete operation as well.

Change-Id: Ie13d7cb27f7d0c8ddc2e6ebf11b0c53858e72472
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronSecurityGroupAware.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/rule/NeutronSecurityRuleAware.java
neutron-vpp-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/vpp/mapper/processors/NetworkAware.java

index dd7bea423cffb9ed1cdbbb1f486d63e89fda1eb8..90ecae6185b256f8ad1444b1ab96f22b22a9dd70 100644 (file)
@@ -60,7 +60,7 @@ public class NeutronSecurityGroupAware implements NeutronAware<SecurityGroup> {
         ruleAware.flushPendingSecurityRulesFor(createdSecGroup.getKey(), neutron);
     }
 
-    public boolean addNeutronSecurityGroup(SecurityGroup secGroup, ReadWriteTransaction rwTx) {
+    boolean addNeutronSecurityGroup(SecurityGroup secGroup, ReadWriteTransaction rwTx) {
         if (secGroup.getTenantId() == null) {
             LOG.warn("Skip processing group {} because TenantId is null.", secGroup);
             // TODO This needs to be reworked, SecGroups shouldn't use TenantId, Neutron doesn't always configure it
@@ -96,15 +96,18 @@ public class NeutronSecurityGroupAware implements NeutronAware<SecurityGroup> {
 
     @Override
     public void onDeleted(SecurityGroup deletedSecGroup, Neutron oldNeutron, Neutron newNeutron) {
+        if (deletedSecGroup.getTenantId() == null) {
+            LOG.warn("Skip deleting SecGroup {} because TenantId is null.", deletedSecGroup);
+            // TODO This needs to be reworked, SecGroups shouldn't use TenantId, Neutron doesn't always configure it
+            return;
+        }
         LOG.trace("deleted securityGroup - {}", deletedSecGroup);
         if (newNeutron != null && newNeutron.getSecurityRules() != null
                 && newNeutron.getSecurityRules().getSecurityRule() != null
                 && newNeutron.getSecurityRules()
                     .getSecurityRule()
                     .stream()
-                    .filter(sr -> sr.getSecurityGroupId().equals(deletedSecGroup.getUuid()))
-                    .findAny()
-                    .isPresent()) {
+                    .anyMatch(sr -> sr.getSecurityGroupId().equals(deletedSecGroup.getUuid()))) {
             LOG.warn("Cannot remove security group {} before removing last security rule.", deletedSecGroup.getKey());
             ruleAware.addPendingDeletedSecGroup(deletedSecGroup);
             return;
index 2bc757f074989899f9c10871c86c2a62afdb80cc..f2626a669dbcc0b6828b07073c20a7262cfa5104 100644 (file)
@@ -361,6 +361,11 @@ public class NeutronSecurityRuleAware implements NeutronAware<SecurityRule> {
 
     @Override
     public void onDeleted(SecurityRule deletedSecRule, Neutron oldNeutron, Neutron newNeutron) {
+        if (deletedSecRule.getTenantId() == null) {
+            LOG.warn("Skip deleting SecRule {} because TenantId is null.", deletedSecRule);
+            // TODO This needs to be reworked, SecGroups shouldn't use TenantId, Neutron doesn't always configure it
+            return;
+        }
         LOG.trace("deleted securityRule - {}", deletedSecRule);
         ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
         boolean isNeutronSecurityRuleDeleted = deleteNeutronSecurityRule(deletedSecRule, oldNeutron, rwTx);
index 577e36eaf96ce17c506d4022f5861d2155748cdb..885c0b6054f3a692085f5c136c493acac4a21213 100644 (file)
@@ -80,7 +80,7 @@ public class NetworkAware implements MappingProvider<Network> {
         bridgeDomainBuilder.setId(network.getUuid().getValue());
         NetworkProviderExtension providerAug = network.getAugmentation(NetworkProviderExtension.class);
         if (providerAug == null || providerAug.getNetworkType() == null) {
-            LOG.error("Cannot create VPP bridge domain. Network type not specified in neutron network: {}", network);
+            LOG.warn("Cannot create VPP bridge domain. Network type not specified in neutron network: {}", network);
             return null;
         }
         Class<? extends NetworkTypeBase> netType = convertNetworkType(providerAug.getNetworkType());