Merge "Port update with existing ip_address only causes exception"

This commit is contained in:
Jenkins 2013-02-27 17:37:14 +00:00 committed by Gerrit Code Review
commit 6b511d70b5
3 changed files with 30 additions and 6 deletions

View File

@ -647,10 +647,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
# Remove all of the intersecting elements # Remove all of the intersecting elements
for original_ip in original_ips[:]: for original_ip in original_ips[:]:
for new_ip in new_ips[:]: for new_ip in new_ips[:]:
if 'ip_address' in new_ip: if ('ip_address' in new_ip and
if (original_ip['ip_address'] == new_ip['ip_address'] original_ip['ip_address'] == new_ip['ip_address']):
and
original_ip['subnet_id'] == new_ip['subnet_id']):
original_ips.remove(original_ip) original_ips.remove(original_ip)
new_ips.remove(new_ip) new_ips.remove(new_ip)

View File

@ -622,6 +622,11 @@ class TestMidonetPortsV2(test_plugin.TestPortsV2,
self._setup_port_mocks() self._setup_port_mocks()
super(TestMidonetPortsV2, self).test_update_port_update_ip() 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): def test_update_port_update_ips(self):
self._setup_port_mocks() self._setup_port_mocks()
super(TestMidonetPortsV2, self).test_update_port_update_ips() super(TestMidonetPortsV2, self).test_update_port_update_ips()

View File

@ -1167,6 +1167,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]['ip_address'], '10.0.0.10')
self.assertEqual(ips[0]['subnet_id'], subnet['subnet']['id']) 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): def test_update_port_update_ips(self):
"""Update IP and generate new IP on port. """Update IP and generate new IP on port.