Port update with existing ip_address only causes exception

Fixes bug 1132852

Change-Id: Iedb0dce3ece270eb0a58af6aa8800e2047dc920d
This commit is contained in:
Gary Kotton 2013-02-25 16:04:13 +00:00
parent b93d9853d2
commit 394b5c4418
3 changed files with 30 additions and 6 deletions

View File

@ -639,10 +639,8 @@ 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']):
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)

View 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()

View 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.