From: Kevin Benton Date: Mon, 30 Mar 2015 18:49:40 +0000 (-0700) Subject: Pass correct port ID back to RPC caller X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=76fa87e12eb69c962dd85a3399d3dbce0c5a3271;p=openstack-build%2Fneutron-build.git Pass correct port ID back to RPC caller The previous response to get_device_details calls was returning whatever the caller requested as the port_id in the response. This was only correct in the case where the port_id was used directly. In cases where device names were passed in, there was no way to retrieve the full port ID. This corrects that behavior by using the port ID from the database and adds tests to ensure the behavior remains correct. Closes-Bug: #1443714 Change-Id: Ibfc7b6659a29e892dfe6e83bd9340feb40e920dd --- diff --git a/neutron/plugins/ml2/rpc.py b/neutron/plugins/ml2/rpc.py index ee01bfb54..e06d916f3 100644 --- a/neutron/plugins/ml2/rpc.py +++ b/neutron/plugins/ml2/rpc.py @@ -105,7 +105,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): entry = {'device': device, 'network_id': port['network_id'], - 'port_id': port_id, + 'port_id': port['id'], 'mac_address': port['mac_address'], 'admin_state_up': port['admin_state_up'], 'network_type': segment[api.NETWORK_TYPE], diff --git a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py index 69e3b3c50..06a9b26c6 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/l2pop/test_mech_driver.py @@ -781,6 +781,21 @@ class TestL2PopulationRpcTestCase(test_plugin.Ml2PluginV2TestCase): self.assertFalse(mock_fanout.called) fanout_patch.stop() + def test_get_device_details_port_id(self): + self._register_ml2_agents() + host_arg = {portbindings.HOST_ID: L2_AGENT['host']} + with self.port(arg_list=(portbindings.HOST_ID,), + **host_arg) as port: + port_id = port['port']['id'] + # ensure various formats all result in correct port_id + formats = ['tap' + port_id[0:8], port_id, + port['port']['mac_address']] + for device in formats: + details = self.callbacks.get_device_details( + self.adminContext, device=device, + agent_id=L2_AGENT_2['host']) + self.assertEqual(port_id, details['port_id']) + def test_host_changed(self): self._register_ml2_agents() with self.subnet(network=self._network) as subnet: