From 295efa00081c770a57a5541652d9d3ffd5c1074d Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Mon, 18 Aug 2014 21:49:31 -0700 Subject: [PATCH] Big Switch: Check for 'id' in port before lookup Check for the presence of the 'id' key before trying to do a lookup based on the value. This is necessary because a 'fields' param to get_port(s) may exclude the 'id' field before the host_id lookup. Closes-Bug: #1358668 Change-Id: If30567d5deaeabd2de6c6287fac7a81695a41cc5 --- neutron/plugins/bigswitch/plugin.py | 4 +++- neutron/tests/unit/bigswitch/test_restproxy_plugin.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/bigswitch/plugin.py b/neutron/plugins/bigswitch/plugin.py index dde693ea4..7a1a7e6b4 100644 --- a/neutron/plugins/bigswitch/plugin.py +++ b/neutron/plugins/bigswitch/plugin.py @@ -357,8 +357,10 @@ class NeutronRestProxyV2Base(db_base_plugin_v2.NeutronDbPluginV2, # In ML2, the host_id is already populated if portbindings.HOST_ID in port: hostid = port[portbindings.HOST_ID] - else: + elif 'id' in port: hostid = porttracker_db.get_port_hostid(context, port['id']) + else: + hostid = None if hostid: port[portbindings.HOST_ID] = hostid override = self._check_hostvif_override(hostid) diff --git a/neutron/tests/unit/bigswitch/test_restproxy_plugin.py b/neutron/tests/unit/bigswitch/test_restproxy_plugin.py index 81b374961..7c5d7f29d 100644 --- a/neutron/tests/unit/bigswitch/test_restproxy_plugin.py +++ b/neutron/tests/unit/bigswitch/test_restproxy_plugin.py @@ -81,6 +81,12 @@ class TestBigSwitchProxyPortsV2(test_plugin.TestPortsV2, super(TestBigSwitchProxyPortsV2, self).setUp(self._plugin_name) + def test_get_ports_no_id(self): + with self.port(name='test'): + ports = manager.NeutronManager.get_plugin().get_ports( + context.get_admin_context(), fields=['name']) + self.assertEqual(['name'], ports[0].keys()) + def test_router_port_status_active(self): # router ports screw up port auto-deletion so it has to be # disabled for this test -- 2.45.2