Beispiel #1
0
    def synchronize_router(self, context, neutron_router_data,
                           lrouter=None):
        """Synchronize a neutron router with its NSX counterpart."""
        if not lrouter:
            # Try to get router from nsx
            try:
                # This query will return the logical router status too
                nsx_router_id = nsx_utils.get_nsx_router_id(
                    context.session, self._cluster, neutron_router_data['id'])
                if nsx_router_id:
                    lrouter = routerlib.get_lrouter(
                        self._cluster, nsx_router_id)
            except exceptions.NotFound:
                # NOTE(salv-orlando): We should be catching
                # api_exc.ResourceNotFound here
                # The logical router was not found
                LOG.warning(_LW("Logical router for neutron router %s not "
                                "found on NSX."), neutron_router_data['id'])
            if lrouter:
                # Update the cache
                self._nsx_cache.update_lrouter(lrouter)

        # Note(salv-orlando): It might worth adding a check to verify neutron
        # resource tag in nsx entity matches a Neutron id.
        # By default assume things go wrong
        status = constants.NET_STATUS_ERROR
        if lrouter:
            lr_status = (lrouter['_relations']
                         ['LogicalRouterStatus']
                         ['fabric_status'])
            status = (lr_status and
                      constants.NET_STATUS_ACTIVE
                      or constants.NET_STATUS_DOWN)
        # Update db object
        if status == neutron_router_data['status']:
            # do nothing
            return

        with context.session.begin(subtransactions=True):
            try:
                router = self._plugin._get_router(context,
                                                  neutron_router_data['id'])
            except l3.RouterNotFound:
                pass
            else:
                router.status = status
                LOG.debug("Updating status for neutron resource %(q_id)s to:"
                          " %(status)s",
                          {'q_id': neutron_router_data['id'],
                           'status': status})
Beispiel #2
0
 def _verify_get_nsx_router_id(self, exp_lr_uuid):
     # The nsxlib and db calls are  mocked, therefore the cluster
     # and the neutron_router_id parameters can be set to None
     lr_uuid = nsx_utils.get_nsx_router_id(db_api.get_session(), None, None)
     self.assertEqual(exp_lr_uuid, lr_uuid)
Beispiel #3
0
 def _verify_get_nsx_router_id(self, exp_lr_uuid):
     neutron_router_id = uuidutils.generate_uuid()
     lr_uuid = nsx_utils.get_nsx_router_id(db_api.get_session(), None,
                                           neutron_router_id)
     self.assertEqual(exp_lr_uuid, lr_uuid)