Fix for incorrect request assumption in Update Neutron Port op 34/2534/1
authorRyan Moats <rmoats@us.ibm.com>
Fri, 8 Nov 2013 04:49:15 +0000 (22:49 -0600)
committerRyan Moats <rmoats@us.ibm.com>
Fri, 8 Nov 2013 04:49:15 +0000 (22:49 -0600)
Neutron Port update code incorrectly assumed that request body
would always include fixed_ip information.  Bracket fixed_ip
adjustment code with proper test.

Change-Id: Icee6b594869e5cba74c0ef339fc0fe7a4d7c671a
Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java

index 273d420..8f1e70f 100644 (file)
@@ -46,26 +46,26 @@ public class NeutronPortInterface implements INeutronPortCRUD {
 \r
     void setClusterContainerService(IClusterContainerServices s) {\r
         logger.debug("Cluster Service set");\r
-        this.clusterContainerService = s;\r
+        clusterContainerService = s;\r
     }\r
 \r
     void unsetClusterContainerService(IClusterContainerServices s) {\r
-        if (this.clusterContainerService == s) {\r
+        if (clusterContainerService == s) {\r
             logger.debug("Cluster Service removed!");\r
-            this.clusterContainerService = null;\r
+            clusterContainerService = null;\r
         }\r
     }\r
 \r
     @SuppressWarnings("deprecation")\r
     private void allocateCache() {\r
-        if (this.clusterContainerService == null) {\r
+        if (clusterContainerService == null) {\r
             logger.error("un-initialized clusterContainerService, can't create cache");\r
             return;\r
         }\r
         logger.debug("Creating Cache for OpenDOVE");\r
         try {\r
             // neutron caches\r
-            this.clusterContainerService.createCache("neutronPorts",\r
+            clusterContainerService.createCache("neutronPorts",\r
                     EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
         } catch (CacheConfigException cce) {\r
             logger.error("Cache couldn't be created for OpenDOVE -  check cache mode");\r
@@ -77,13 +77,13 @@ public class NeutronPortInterface implements INeutronPortCRUD {
 \r
     @SuppressWarnings({ "unchecked", "deprecation" })\r
     private void retrieveCache() {\r
-        if (this.clusterContainerService == null) {\r
+        if (clusterContainerService == null) {\r
             logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
             return;\r
         }\r
 \r
         logger.debug("Retrieving cache for Neutron Ports");\r
-        portDB = (ConcurrentMap<String, NeutronPort>) this.clusterContainerService\r
+        portDB = (ConcurrentMap<String, NeutronPort>) clusterContainerService\r
         .getCache("neutronPorts");\r
         if (portDB == null) {\r
             logger.error("Cache couldn't be retrieved for Neutron Ports");\r
@@ -93,12 +93,12 @@ public class NeutronPortInterface implements INeutronPortCRUD {
 \r
     @SuppressWarnings("deprecation")\r
     private void destroyCache() {\r
-        if (this.clusterContainerService == null) {\r
+        if (clusterContainerService == null) {\r
             logger.error("un-initialized clusterMger, can't destroy cache");\r
             return;\r
         }\r
         logger.debug("Destroying Cache for HostTracker");\r
-        this.clusterContainerService.destroyCache("neutronPorts");\r
+        clusterContainerService.destroyCache("neutronPorts");\r
     }\r
 \r
     private void startUp() {\r
@@ -114,11 +114,11 @@ public class NeutronPortInterface implements INeutronPortCRUD {
     void init(Component c) {\r
         Dictionary<?, ?> props = c.getServiceProperties();\r
         if (props != null) {\r
-            this.containerName = (String) props.get("containerName");\r
-            logger.debug("Running containerName: {}", this.containerName);\r
+            containerName = (String) props.get("containerName");\r
+            logger.debug("Running containerName: {}", containerName);\r
         } else {\r
             // In the Global instance case the containerName is empty\r
-            this.containerName = "";\r
+            containerName = "";\r
         }\r
         startUp();\r
     }\r
@@ -179,16 +179,20 @@ public class NeutronPortInterface implements INeutronPortCRUD {
 \r
     // IfNBPortCRUD methods\r
 \r
+    @Override\r
     public boolean portExists(String uuid) {\r
         return portDB.containsKey(uuid);\r
     }\r
 \r
+    @Override\r
     public NeutronPort getPort(String uuid) {\r
-        if (!portExists(uuid))\r
+        if (!portExists(uuid)) {\r
             return null;\r
+        }\r
         return portDB.get(uuid);\r
     }\r
 \r
+    @Override\r
     public List<NeutronPort> getAllPorts() {\r
         Set<NeutronPort> allPorts = new HashSet<NeutronPort>();\r
         for (Entry<String, NeutronPort> entry : portDB.entrySet()) {\r
@@ -201,9 +205,11 @@ public class NeutronPortInterface implements INeutronPortCRUD {
         return ans;\r
     }\r
 \r
+    @Override\r
     public boolean addPort(NeutronPort input) {\r
-        if (portExists(input.getID()))\r
+        if (portExists(input.getID())) {\r
             return false;\r
+        }\r
         portDB.putIfAbsent(input.getID(), input);\r
         // if there are no fixed IPs, allocate one for each subnet in the network\r
         INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
@@ -212,16 +218,18 @@ public class NeutronPortInterface implements INeutronPortCRUD {
             Iterator<NeutronSubnet> subnetIterator = systemCRUD.getAllSubnets().iterator();\r
             while (subnetIterator.hasNext()) {\r
                 NeutronSubnet subnet = subnetIterator.next();\r
-                if (subnet.getNetworkUUID().equals(input.getNetworkUUID()))\r
+                if (subnet.getNetworkUUID().equals(input.getNetworkUUID())) {\r
                     list.add(new Neutron_IPs(subnet.getID()));\r
+                }\r
             }\r
         }\r
         Iterator<Neutron_IPs> fixedIPIterator = input.getFixedIPs().iterator();\r
         while (fixedIPIterator.hasNext()) {\r
             Neutron_IPs ip = fixedIPIterator.next();\r
             NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
-            if (ip.getIpAddress() == null)\r
+            if (ip.getIpAddress() == null) {\r
                 ip.setIpAddress(subnet.getLowAddr());\r
+            }\r
             if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {\r
                 subnet.allocateIP(ip.getIpAddress());\r
             }\r
@@ -237,9 +245,11 @@ public class NeutronPortInterface implements INeutronPortCRUD {
         return true;\r
     }\r
 \r
+    @Override\r
     public boolean removePort(String uuid) {\r
-        if (!portExists(uuid))\r
+        if (!portExists(uuid)) {\r
             return false;\r
+        }\r
         NeutronPort port = getPort(uuid);\r
         portDB.remove(uuid);\r
         INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
@@ -262,43 +272,47 @@ public class NeutronPortInterface implements INeutronPortCRUD {
         return true;\r
     }\r
 \r
+    @Override\r
     public boolean updatePort(String uuid, NeutronPort delta) {\r
-        if (!portExists(uuid))\r
+        if (!portExists(uuid)) {\r
             return false;\r
+        }\r
         NeutronPort target = portDB.get(uuid);\r
         // remove old Fixed_IPs\r
-        NeutronPort port = getPort(uuid);\r
-        INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
-        Iterator<Neutron_IPs> fixedIPIterator = port.getFixedIPs().iterator();\r
-        while (fixedIPIterator.hasNext()) {\r
-            Neutron_IPs ip = fixedIPIterator.next();\r
-            NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
-            subnet.releaseIP(ip.getIpAddress());\r
-        }\r
+        if (delta.getFixedIPs() != null) {\r
+            NeutronPort port = getPort(uuid);\r
+            INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
+            for (Neutron_IPs ip: port.getFixedIPs()) {\r
+                NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
+                subnet.releaseIP(ip.getIpAddress());\r
+            }\r
 \r
-        // allocate new Fixed_IPs\r
-        fixedIPIterator = delta.getFixedIPs().iterator();\r
-        while (fixedIPIterator.hasNext()) {\r
-            Neutron_IPs ip = fixedIPIterator.next();\r
-            NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
-            if (ip.getIpAddress() == null)\r
-                ip.setIpAddress(subnet.getLowAddr());\r
-            subnet.allocateIP(ip.getIpAddress());\r
+            // allocate new Fixed_IPs\r
+            for (Neutron_IPs ip: delta.getFixedIPs()) {\r
+                NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
+                if (ip.getIpAddress() == null) {\r
+                    ip.setIpAddress(subnet.getLowAddr());\r
+                }\r
+                subnet.allocateIP(ip.getIpAddress());\r
+            }\r
         }\r
         return overwrite(target, delta);\r
     }\r
 \r
+    @Override\r
     public boolean macInUse(String macAddress) {\r
         List<NeutronPort> ports = getAllPorts();\r
         Iterator<NeutronPort> portIterator = ports.iterator();\r
         while (portIterator.hasNext()) {\r
             NeutronPort port = portIterator.next();\r
-            if (macAddress.equalsIgnoreCase(port.getMacAddress()))\r
+            if (macAddress.equalsIgnoreCase(port.getMacAddress())) {\r
                 return true;\r
+            }\r
         }\r
         return false;\r
     }\r
 \r
+    @Override\r
     public NeutronPort getGatewayPort(String subnetUUID) {\r
         INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
         NeutronSubnet subnet = systemCRUD.getSubnet(subnetUUID);\r
@@ -307,8 +321,9 @@ public class NeutronPortInterface implements INeutronPortCRUD {
             NeutronPort port = portIterator.next();\r
             List<Neutron_IPs> fixedIPs = port.getFixedIPs();\r
             if (fixedIPs.size() == 1) {\r
-                if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress()))\r
+                if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress())) {\r
                     return port;\r
+                }\r
             }\r
         }\r
         return null;\r