summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-11-13 21:12:21 +0000
committerGerrit Code Review <review@openstack.org>2014-11-13 21:12:21 +0000
commitb526e606e3e708a91313cc9b31771aed1dd1f427 (patch)
treefe6576defa5f8ccace319f913c520aa11c7c056d
parentb5d7e827dd996a02efb7526b7c3be6a93cfde350 (diff)
parentb0d3e7423c2b0eb95a1df00ba479cd9ed896c116 (diff)
downloadneutron-b526e606e3e708a91313cc9b31771aed1dd1f427.tar.gz
Merge "Fix KeyError in dhcp_rpc when plugin.port_update raise exception" into stable/juno
-rw-r--r--neutron/api/rpc/handlers/dhcp_rpc.py8
-rw-r--r--neutron/tests/unit/test_dhcp_rpc.py35
2 files changed, 36 insertions, 7 deletions
diff --git a/neutron/api/rpc/handlers/dhcp_rpc.py b/neutron/api/rpc/handlers/dhcp_rpc.py
index 56016be708..58317eac4b 100644
--- a/neutron/api/rpc/handlers/dhcp_rpc.py
+++ b/neutron/api/rpc/handlers/dhcp_rpc.py
@@ -60,7 +60,7 @@ class DhcpRpcCallback(n_rpc.RpcCallback):
if action == 'create_port':
return plugin.create_port(context, port)
elif action == 'update_port':
- return plugin.update_port(context, port['id'], port['port'])
+ return plugin.update_port(context, port['id'], port)
else:
msg = _('Unrecognized action')
raise n_exc.Invalid(message=msg)
@@ -282,13 +282,11 @@ class DhcpRpcCallback(n_rpc.RpcCallback):
def update_dhcp_port(self, context, **kwargs):
"""Update the dhcp port."""
host = kwargs.get('host')
- port_id = kwargs.get('port_id')
port = kwargs.get('port')
+ port['id'] = kwargs.get('port_id')
LOG.debug(_('Update dhcp port %(port)s '
'from %(host)s.'),
{'port': port,
'host': host})
plugin = manager.NeutronManager.get_plugin()
- return self._port_action(plugin, context,
- {'id': port_id, 'port': port},
- 'update_port')
+ return self._port_action(plugin, context, port, 'update_port')
diff --git a/neutron/tests/unit/test_dhcp_rpc.py b/neutron/tests/unit/test_dhcp_rpc.py
index 6a2ed16d7e..2c4c5c9e6e 100644
--- a/neutron/tests/unit/test_dhcp_rpc.py
+++ b/neutron/tests/unit/test_dhcp_rpc.py
@@ -161,13 +161,44 @@ class TestDhcpRpcCallback(base.BaseTestCase):
self.plugin.assert_has_calls(expected)
return retval
+ def test_update_dhcp_port_verify_port_action_port_dict(self):
+ port = {'port': {'network_id': 'foo_network_id',
+ 'device_owner': constants.DEVICE_OWNER_DHCP,
+ 'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]}
+ }
+ expected_port = {'port': {'network_id': 'foo_network_id',
+ 'device_owner': constants.DEVICE_OWNER_DHCP,
+ 'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]
+ },
+ 'id': 'foo_port_id'
+ }
+
+ def _fake_port_action(plugin, context, port, action):
+ self.assertEqual(expected_port, port)
+
+ self.callbacks._port_action = _fake_port_action
+ self.callbacks.update_dhcp_port(mock.Mock(),
+ host='foo_host',
+ port_id='foo_port_id',
+ port=port)
+
def test_update_dhcp_port(self):
+ port = {'port': {'network_id': 'foo_network_id',
+ 'device_owner': constants.DEVICE_OWNER_DHCP,
+ 'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]}
+ }
+ expected_port = {'port': {'network_id': 'foo_network_id',
+ 'device_owner': constants.DEVICE_OWNER_DHCP,
+ 'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]
+ },
+ 'id': 'foo_port_id'
+ }
self.callbacks.update_dhcp_port(mock.Mock(),
host='foo_host',
port_id='foo_port_id',
- port=mock.Mock())
+ port=port)
self.plugin.assert_has_calls(
- mock.call.update_port(mock.ANY, 'foo_port_id', mock.ANY))
+ mock.call.update_port(mock.ANY, 'foo_port_id', expected_port))
def test_get_dhcp_port_existing(self):
port_retval = dict(id='port_id', fixed_ips=[dict(subnet_id='a')])