From 46fe14b1403fd4a1b4c15a5f3e5a10bd7fba31c8 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Mon, 24 Feb 2014 10:44:46 -0800 Subject: [PATCH] NSX: Fix status sync with correct mappings The code that syncs router status to the neutron_db was using the nsx router id instead of the neutron router id thus synchronize_router would never update the database. Also, the switch synchronization routine was not fetching the appropriate neutron id tag thus causing switch synchronization to be skipped. This patch also fixes the error in the unit tests which allowed for the bug to be introduced. Co-Authored-By: Salvatore Orlando Closes-bug: 1283856 Change-Id: I26342ecea6ad546b224b7fca1e55f754b4883363 --- neutron/plugins/nicira/common/sync.py | 19 +++++++++++++++---- neutron/tests/unit/vmware/test_nsx_sync.py | 10 ++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/neutron/plugins/nicira/common/sync.py b/neutron/plugins/nicira/common/sync.py index 8a5c63327..b208c6c60 100644 --- a/neutron/plugins/nicira/common/sync.py +++ b/neutron/plugins/nicira/common/sync.py @@ -300,7 +300,7 @@ class NvpSynchronizer(): lswitch = (self._nvp_cache[ls_uuid].get('data') or self._nvp_cache[ls_uuid].get('data_bk')) tags = self._get_tag_dict(lswitch['tags']) - neutron_id = tags.get('neutron_net_id', ls_uuid) + neutron_id = tags.get('quantum_net_id') neutron_net_ids.add(neutron_id) neutron_nvp_mappings[neutron_id] = ( neutron_nvp_mappings.get(neutron_id, []) + @@ -309,7 +309,6 @@ class NvpSynchronizer(): filters = {'router:external': [False]} if not scan_missing: filters['id'] = neutron_net_ids - # TODO(salv-orlando): Filter out external networks networks = self._plugin._get_collection_query( ctx, models_v2.Network, filters=filters) for network in networks: @@ -356,8 +355,20 @@ class NvpSynchronizer(): def _synchronize_lrouters(self, ctx, lr_uuids, scan_missing=False): if not lr_uuids and not scan_missing: return - neutron_router_mappings = ( - dict((lr_uuid, self._nvp_cache[lr_uuid]) for lr_uuid in lr_uuids)) + # TODO(salvatore-orlando): Deal with the case the tag + # has been tampered with + neutron_router_mappings = {} + for lr_uuid in lr_uuids: + lrouter = (self._nvp_cache[lr_uuid].get('data') or + self._nvp_cache[lr_uuid].get('data_bk')) + tags = self._get_tag_dict(lrouter['tags']) + neutron_router_id = tags.get('q_router_id') + if neutron_router_id: + neutron_router_mappings[neutron_router_id] = ( + self._nvp_cache[lr_uuid]) + else: + LOG.warn(_("Unable to find Neutron router id for " + "NSX logical router: %s"), lr_uuid) # Fetch neutron routers from database filters = ({} if scan_missing else {'id': neutron_router_mappings.keys()}) diff --git a/neutron/tests/unit/vmware/test_nsx_sync.py b/neutron/tests/unit/vmware/test_nsx_sync.py index 11db173a5..4ba57f1af 100644 --- a/neutron/tests/unit/vmware/test_nsx_sync.py +++ b/neutron/tests/unit/vmware/test_nsx_sync.py @@ -425,9 +425,12 @@ class SyncTestCase(base.BaseTestCase): with self._populate_data(ctx): sp = sync.SyncParameters(100) self._plugin._synchronizer._synchronize_state(sp) + # Ensure the synchronizer performs a resync + sp.init_sync_performed = True self._test_sync( constants.NET_STATUS_DOWN, constants.PORT_STATUS_DOWN, - constants.NET_STATUS_DOWN, self._action_callback_status_down) + constants.NET_STATUS_DOWN, self._action_callback_status_down, + sp=sp) def _action_callback_del_resource(self, ls_uuid, lp_uuid, lr_uuid): del self.fc._fake_lswitch_dict[ls_uuid] @@ -446,9 +449,12 @@ class SyncTestCase(base.BaseTestCase): with self._populate_data(ctx): sp = sync.SyncParameters(100) self._plugin._synchronizer._synchronize_state(sp) + # Ensure the synchronizer performs a resync + sp.init_sync_performed = True self._test_sync( constants.NET_STATUS_ERROR, constants.PORT_STATUS_ERROR, - constants.NET_STATUS_ERROR, self._action_callback_del_resource) + constants.NET_STATUS_ERROR, self._action_callback_del_resource, + sp=sp) def _test_sync_with_chunk_larger_maxpagesize( self, net_size, port_size, router_size, chunk_size, exp_calls): -- 2.45.2