]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: Fix status sync with correct mappings
authorSalvatore Orlando <salv.orlando@gmail.com>
Mon, 24 Feb 2014 18:44:46 +0000 (10:44 -0800)
committerThomas Goirand <thomas@goirand.fr>
Thu, 13 Mar 2014 07:20:31 +0000 (15:20 +0800)
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 <salv.orlando@gmail.com>
Closes-bug: 1283856

Change-Id: I26342ecea6ad546b224b7fca1e55f754b4883363

neutron/plugins/nicira/common/sync.py
neutron/tests/unit/vmware/test_nsx_sync.py

index 8a5c6332764550765539ca9bfae005a91a2a9573..b208c6c6024f4f21b1a58127918c850ce598537d 100644 (file)
@@ -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()})
index 11db173a57a57e8c9075b37498813569b2a9cdbc..4ba57f1af5c803ea55787b844e8363cdbb02477a 100644 (file)
@@ -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):