]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Port update with existing ip_address only causes exception
authorGary Kotton <gkotton@redhat.com>
Mon, 25 Feb 2013 16:04:13 +0000 (16:04 +0000)
committerGary Kotton <gkotton@redhat.com>
Tue, 26 Feb 2013 08:26:44 +0000 (08:26 +0000)
Fixes bug 1132852

Change-Id: Iedb0dce3ece270eb0a58af6aa8800e2047dc920d

quantum/db/db_base_plugin_v2.py
quantum/tests/unit/midonet/test_midonet_plugin.py
quantum/tests/unit/test_db_plugin.py

index 675ad86eb482b7074feddafa7f477f4f6f270ce9..9e6df5bb7a5716a597e84a925ee556f0e2292089 100644 (file)
@@ -639,12 +639,10 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
         # Remove all of the intersecting elements
         for original_ip in original_ips[:]:
             for new_ip in new_ips[:]:
-                if 'ip_address' in new_ip:
-                    if (original_ip['ip_address'] == new_ip['ip_address']
-                            and
-                            original_ip['subnet_id'] == new_ip['subnet_id']):
-                        original_ips.remove(original_ip)
-                        new_ips.remove(new_ip)
+                if ('ip_address' in new_ip and
+                    original_ip['ip_address'] == new_ip['ip_address']):
+                    original_ips.remove(original_ip)
+                    new_ips.remove(new_ip)
 
         # Check if the IP's to add are OK
         to_add = self._test_fixed_ips_for_port(context, network_id, new_ips)
index 7e80310571010649e8398bb1e791b99f21ed761f..550a424f841f98f887646513a0c2def1018a154f 100644 (file)
@@ -622,6 +622,11 @@ class TestMidonetPortsV2(test_plugin.TestPortsV2,
         self._setup_port_mocks()
         super(TestMidonetPortsV2, self).test_update_port_update_ip()
 
+    def test_update_port_update_ip_address_only(self):
+        self._setup_port_mocks()
+        super(TestMidonetPortsV2,
+              self).test_update_port_update_ip_address_only()
+
     def test_update_port_update_ips(self):
         self._setup_port_mocks()
         super(TestMidonetPortsV2, self).test_update_port_update_ips()
index b073b9a34265255495104e7604f30e99cb89834f..b257590d2c583a18de87ca5936abfd75d70d9039 100644 (file)
@@ -1163,6 +1163,27 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
                 self.assertEqual(ips[0]['ip_address'], '10.0.0.10')
                 self.assertEqual(ips[0]['subnet_id'], subnet['subnet']['id'])
 
+    def test_update_port_update_ip_address_only(self):
+        with self.subnet() as subnet:
+            with self.port(subnet=subnet) as port:
+                ips = port['port']['fixed_ips']
+                self.assertEqual(len(ips), 1)
+                self.assertEqual(ips[0]['ip_address'], '10.0.0.2')
+                self.assertEqual(ips[0]['subnet_id'], subnet['subnet']['id'])
+                data = {'port': {'fixed_ips': [{'subnet_id':
+                                                subnet['subnet']['id'],
+                                                'ip_address': "10.0.0.10"},
+                                               {'ip_address': "10.0.0.2"}]}}
+                req = self.new_update_request('ports', data,
+                                              port['port']['id'])
+                res = self.deserialize(self.fmt, req.get_response(self.api))
+                ips = res['port']['fixed_ips']
+                self.assertEqual(len(ips), 2)
+                self.assertEqual(ips[0]['ip_address'], '10.0.0.2')
+                self.assertEqual(ips[0]['subnet_id'], subnet['subnet']['id'])
+                self.assertEqual(ips[1]['ip_address'], '10.0.0.10')
+                self.assertEqual(ips[1]['subnet_id'], subnet['subnet']['id'])
+
     def test_update_port_update_ips(self):
         """Update IP and generate new IP on port.