Bug 4736 - Add null poiner check of getFixedIPs() 46/30946/1
authorIsaku Yamahata <isaku.yamahata@intel.com>
Tue, 1 Sep 2015 18:49:45 +0000 (11:49 -0700)
committerIsaku Yamahata <isaku.yamahata@intel.com>
Tue, 8 Dec 2015 02:31:39 +0000 (18:31 -0800)
NeutronPort.getFixedIPs() can return null.  In netvirt code, some
codes have null pointer check, some doesn't inconsistently.  Add null
pointer check consistently to avoid potential null pointer exception.

Change-Id: I69054f21bd2b18d6861e310a2f5e3e34d8b5a6de
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/NeutronL3Adapter.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityGroupCacheManagerImpl.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/SecurityServicesImpl.java

index 8d379f416fb06258daccb1525b36d667ceffc011..e266852a47f16fdd686c64fe3b7c3bbb811ae3c0 100644 (file)
@@ -400,14 +400,16 @@ public class NeutronL3Adapter implements ConfigInterface {
         if (neutronPort.getDeviceOwner().equalsIgnoreCase(OWNER_ROUTER_INTERFACE) ||
             neutronPort.getDeviceOwner().equalsIgnoreCase(OWNER_ROUTER_INTERFACE_DISTRIBUTED)) {
 
-            for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
-                NeutronRouter_Interface neutronRouterInterface =
+            if (neutronPort.getFixedIPs() != null) {
+                for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
+                    NeutronRouter_Interface neutronRouterInterface =
                         new NeutronRouter_Interface(neutronIP.getSubnetUUID(), neutronPort.getPortUUID());
-                // id of router interface to be same as subnet
-                neutronRouterInterface.setID(neutronIP.getSubnetUUID());
-                neutronRouterInterface.setTenantID(neutronPort.getTenantID());
+                    // id of router interface to be same as subnet
+                    neutronRouterInterface.setID(neutronIP.getSubnetUUID());
+                    neutronRouterInterface.setTenantID(neutronPort.getTenantID());
 
-                this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
+                    this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
+                }
             }
         } else {
             // We made it here, port is not used as a router interface. If this is not a delete action, make sure that
@@ -468,10 +470,12 @@ public class NeutronL3Adapter implements ConfigInterface {
             boolean currPortShouldBeDeleted = false;
             // Note: delete in this case only applies to 1)router interface delete and 2)ports on the same subnet
             if (isDelete) {
-                for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
-                    if (neutronRouterInterface.getSubnetUUID().equalsIgnoreCase(neutronIP.getSubnetUUID())) {
-                        currPortShouldBeDeleted = true;
-                        break;
+                if (neutronPort.getFixedIPs() != null) {
+                    for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
+                        if (neutronRouterInterface.getSubnetUUID().equalsIgnoreCase(neutronIP.getSubnetUUID())) {
+                            currPortShouldBeDeleted = true;
+                            break;
+                        }
                     }
                 }
             }
@@ -798,7 +802,9 @@ public class NeutronL3Adapter implements ConfigInterface {
             if (dpid == null) {
                 continue;
             }
-
+            if (neutronPort.getFixedIPs() == null) {
+                continue;
+            }
             for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
                 final String tenantIpStr = neutronIP.getIpAddress();
                 if (tenantIpStr.isEmpty()) {
@@ -1361,6 +1367,9 @@ public class NeutronL3Adapter implements ConfigInterface {
     }
 
     private NeutronSubnet getExternalNetworkSubnet(NeutronPort gatewayPort){
+        if (gatewayPort.getFixedIPs() == null) {
+            return null;
+        }
         for (Neutron_IPs neutronIPs : gatewayPort.getFixedIPs()) {
             String subnetUUID = neutronIPs.getSubnetUUID();
             NeutronSubnet extSubnet = neutronSubnetCache.getSubnet(subnetUUID);
@@ -1402,7 +1411,8 @@ public class NeutronL3Adapter implements ConfigInterface {
 
                 // TODO: address IPv6 case.
                 if (externalSubnet != null &&
-                    externalSubnet.getIpVersion() == 4) {
+                    externalSubnet.getIpVersion() == 4 &&
+                    gatewayPort.getFixedIPs() != null) {
                     LOG.info("Trigger MAC resolution for gateway ip {} on Node {}",externalSubnet.getGatewayIP(),node.getNodeId());
                     ListenableFuture<MacAddress> gatewayMacAddress =
                         gatewayMacResolver.resolveMacAddress(getDpidForExternalBridge(node),
index 53231ec23d18679c8342d402b843249122692145..d6e41cc2298d4b425299e6761767d142a1b1ade8 100644 (file)
@@ -105,6 +105,9 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
             }
             List<NeutronSecurityRule> remoteSecurityRules = retrieveSecurityRules(securityGroupUuid, cachedportUuid);
             for (NeutronSecurityRule securityRule : remoteSecurityRules) {
+                if (port.getFixedIPs() == null) {
+                    continue;
+                }
                 for (Neutron_IPs vmIp : port.getFixedIPs()) {
                     securityServicesManager.syncSecurityRule(cachedport, securityRule, vmIp, true);
                 }
@@ -132,6 +135,9 @@ public class SecurityGroupCacheManagerImpl implements ConfigInterface, SecurityG
             }
             List<NeutronSecurityRule> remoteSecurityRules = retrieveSecurityRules(securityGroupUuid, cachedportUuid);
             for (NeutronSecurityRule securityRule : remoteSecurityRules) {
+                if (port.getFixedIPs() == null) {
+                    continue;
+                }
                 for (Neutron_IPs vmIp : port.getFixedIPs()) {
                     securityServicesManager.syncSecurityRule(cachedport, securityRule, vmIp, false);
                 }
index 55f8fbf79ee26654c3e3bbdf8a5719d0afc72aad..61bb634ab1a373165a4b63021456f12023799ddf 100644 (file)
@@ -320,7 +320,9 @@ public class SecurityServicesImpl implements ConfigInterface, SecurityServicesMa
                         if (securityGroup.getSecurityGroupUUID().equals(securityGroupUuid)) {
                             LOG.debug("getVMListForSecurityGroup : adding ports with ips {} "
                                     + "compute port", neutronPort.getFixedIPs());
-                            vmListForSecurityGroup.addAll(neutronPort.getFixedIPs());
+                            if (neutronPort.getFixedIPs() != null) {
+                                vmListForSecurityGroup.addAll(neutronPort.getFixedIPs());
+                            }
                         }
                     }
                 }