]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix 404 error fetching metadata when using DVR
authorarmando-migliaccio <armamig@gmail.com>
Wed, 6 Aug 2014 17:13:32 +0000 (10:13 -0700)
committerarmando-migliaccio <armamig@gmail.com>
Tue, 12 Aug 2014 19:26:31 +0000 (12:26 -0700)
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
neutron/tests/unit/test_metadata_agent.py

index 9365c4f02ca464ddd76b84378d38fe69c81be447..c5b572154cc472a211560052cb4d931bbfbdcf45 100644 (file)
@@ -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
index 5c7cb59c16c95fdf815d0747b8dab0f7cb95be4c..6a1e51cac3033bb1522966a9482482fa651d0125 100644 (file)
@@ -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
                 )
             ])