From 338171c114743c0e03def04ef551231f0d9c93f8 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Wed, 6 Aug 2014 10:13:32 -0700 Subject: [PATCH] Fix 404 error fetching metadata when using DVR The metadata agent was unable to find networks attached to the DVR router because it was only filtering ports for 'centralized' routers. To fix the issue, this patch expands the search filters to include DVR router interfaces during the network lookup operation. The extra filter cause no evident performance loss while serving the request; a different approach would require to pass the router type around to narrow down the search filter, but it sounds like an overkill. Closes-bug: #1353271 Change-Id: Iefbefa1ff300adad48ab9fc472d5eb1913fbe488 --- neutron/agent/metadata/agent.py | 3 ++- neutron/tests/unit/test_metadata_agent.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py index 9365c4f02..c5b572154 100644 --- a/neutron/agent/metadata/agent.py +++ b/neutron/agent/metadata/agent.py @@ -144,7 +144,8 @@ class MetadataProxyHandler(object): internal_ports = qclient.list_ports( device_id=router_id, - device_owner=n_const.DEVICE_OWNER_ROUTER_INTF)['ports'] + device_owner=[n_const.DEVICE_OWNER_ROUTER_INTF, + n_const.DEVICE_OWNER_DVR_INTERFACE])['ports'] return tuple(p['network_id'] for p in internal_ports) @utils.cache_method_results diff --git a/neutron/tests/unit/test_metadata_agent.py b/neutron/tests/unit/test_metadata_agent.py index 5c7cb59c1..6a1e51cac 100644 --- a/neutron/tests/unit/test_metadata_agent.py +++ b/neutron/tests/unit/test_metadata_agent.py @@ -27,6 +27,12 @@ from neutron.common import utils from neutron.tests import base +EXPECTED_OWNER_ROUTERS = [ + constants.DEVICE_OWNER_ROUTER_INTF, + constants.DEVICE_OWNER_DVR_INTERFACE +] + + class FakeConf(object): admin_user = 'neutron' admin_password = 'password' @@ -104,7 +110,7 @@ class TestMetadataProxyHandlerCache(base.BaseTestCase): networks = self.handler._get_router_networks(router_id) mock_list_ports.assert_called_once_with( device_id=router_id, - device_owner=constants.DEVICE_OWNER_ROUTER_INTF) + device_owner=EXPECTED_OWNER_ROUTERS) self.assertEqual(expected, networks) def _test_get_router_networks_twice_helper(self): @@ -119,7 +125,7 @@ class TestMetadataProxyHandlerCache(base.BaseTestCase): networks = self.handler._get_router_networks(router_id) mock_list_ports.assert_called_once_with( device_id=router_id, - device_owner=constants.DEVICE_OWNER_ROUTER_INTF) + device_owner=EXPECTED_OWNER_ROUTERS) self.assertEqual(expected_networks, networks) networks = self.handler._get_router_networks(router_id) @@ -232,7 +238,7 @@ class TestMetadataProxyHandlerCache(base.BaseTestCase): new_qclient_call, mock.call().list_ports( device_id=router_id, - device_owner=constants.DEVICE_OWNER_ROUTER_INTF + device_owner=EXPECTED_OWNER_ROUTERS ) ]) -- 2.45.2