From 394b5c4418d310b75b10c1e63320423fd8432dbe Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Mon, 25 Feb 2013 16:04:13 +0000 Subject: [PATCH] Port update with existing ip_address only causes exception Fixes bug 1132852 Change-Id: Iedb0dce3ece270eb0a58af6aa8800e2047dc920d --- quantum/db/db_base_plugin_v2.py | 10 ++++----- .../tests/unit/midonet/test_midonet_plugin.py | 5 +++++ quantum/tests/unit/test_db_plugin.py | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/quantum/db/db_base_plugin_v2.py b/quantum/db/db_base_plugin_v2.py index 675ad86eb4..9e6df5bb7a 100644 --- a/quantum/db/db_base_plugin_v2.py +++ b/quantum/db/db_base_plugin_v2.py @@ -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) diff --git a/quantum/tests/unit/midonet/test_midonet_plugin.py b/quantum/tests/unit/midonet/test_midonet_plugin.py index 7e80310571..550a424f84 100644 --- a/quantum/tests/unit/midonet/test_midonet_plugin.py +++ b/quantum/tests/unit/midonet/test_midonet_plugin.py @@ -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() diff --git a/quantum/tests/unit/test_db_plugin.py b/quantum/tests/unit/test_db_plugin.py index b073b9a342..b257590d2c 100644 --- a/quantum/tests/unit/test_db_plugin.py +++ b/quantum/tests/unit/test_db_plugin.py @@ -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.