Beispiel #1
0
    def synchronize_router(self, context, neutron_router_data, lrouter=None):
        """Synchronize a neutron router with its NVP counterpart."""
        if not lrouter:
            # Try to get router from nvp
            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'])
                lrouter = routerlib.get_lrouter(self._cluster, nsx_router_id)
            except exceptions.NotFound:
                # NOTE(salv-orlando): We should be catching
                # NvpApiClient.ResourceNotFound here
                # The logical router was not found
                LOG.warning(
                    _("Logical router for neutron router %s not "
                      "found on NVP."), neutron_router_data['id'])
                lrouter = None
            else:
                # Update the cache
                self._nvp_cache.update_lrouter(lrouter)

        # Note(salv-orlando): It might worth adding a check to verify neutron
        # resource tag in nvp 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
        self._update_neutron_object(context, neutron_router_data, status)
Beispiel #2
0
    def synchronize_router(self, context, neutron_router_data,
                           lrouter=None):
        """Synchronize a neutron router with its NVP counterpart."""
        if not lrouter:
            # Try to get router from nvp
            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'])
                lrouter = routerlib.get_lrouter(
                    self._cluster, nsx_router_id)
            except exceptions.NotFound:
                # NOTE(salv-orlando): We should be catching
                # NvpApiClient.ResourceNotFound here
                # The logical router was not found
                LOG.warning(_("Logical router for neutron router %s not "
                              "found on NVP."), neutron_router_data['id'])
                lrouter = None
            else:
                # Update the cache
                self._nvp_cache.update_lrouter(lrouter)

        # Note(salv-orlando): It might worth adding a check to verify neutron
        # resource tag in nvp 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
        self._update_neutron_object(context, neutron_router_data, status)
Beispiel #3
0
 def _create_lrouter(self, version, neutron_id=None, distributed=None):
     with mock.patch.object(
         self.fake_cluster.api_client, 'get_nvp_version',
         return_value=NvpApiClient.NVPVersion(version)):
         if not neutron_id:
             neutron_id = uuidutils.generate_uuid()
         lrouter = routerlib.create_lrouter(
             self.fake_cluster, neutron_id, 'pippo',
             'fake-lrouter', '10.0.0.1', distributed=distributed)
         return routerlib.get_lrouter(self.fake_cluster,
                                      lrouter['uuid'])
Beispiel #4
0
 def _create_lrouter(self, version, neutron_id=None, distributed=None):
     with mock.patch.object(
         self.fake_cluster.api_client, 'get_nvp_version',
         return_value=api_client.NVPVersion(version)):
         if not neutron_id:
             neutron_id = uuidutils.generate_uuid()
         lrouter = routerlib.create_lrouter(
             self.fake_cluster, neutron_id, 'pippo',
             'fake-lrouter', '10.0.0.1', distributed=distributed)
         return routerlib.get_lrouter(self.fake_cluster,
                                      lrouter['uuid'])
Beispiel #5
0
 def test_create_and_get_lrouter_name_exceeds_40chars(self):
     neutron_id = uuidutils.generate_uuid()
     display_name = '*' * 50
     lrouter = routerlib.create_lrouter(self.fake_cluster, neutron_id,
                                        'pippo', display_name, '10.0.0.1')
     res_lrouter = routerlib.get_lrouter(self.fake_cluster, lrouter['uuid'])
     self._verify_lrouter(res_lrouter,
                          lrouter['uuid'],
                          '*' * 40,
                          '10.0.0.1',
                          'pippo',
                          expected_neutron_id=neutron_id)
Beispiel #6
0
 def test_create_and_get_lrouter_name_exceeds_40chars(self):
     neutron_id = uuidutils.generate_uuid()
     display_name = '*' * 50
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        neutron_id,
                                        'pippo',
                                        display_name,
                                        '10.0.0.1')
     res_lrouter = routerlib.get_lrouter(self.fake_cluster,
                                         lrouter['uuid'])
     self._verify_lrouter(res_lrouter, lrouter['uuid'],
                          '*' * 40, '10.0.0.1', 'pippo',
                          expected_neutron_id=neutron_id)
Beispiel #7
0
 def test_update_lrouter(self):
     neutron_id = uuidutils.generate_uuid()
     lrouter = routerlib.create_lrouter(self.fake_cluster, neutron_id,
                                        'pippo', 'fake-lrouter', '10.0.0.1')
     lrouter = routerlib.update_lrouter(self.fake_cluster, lrouter['uuid'],
                                        'new_name', '192.168.0.1')
     res_lrouter = routerlib.get_lrouter(self.fake_cluster, lrouter['uuid'])
     self._verify_lrouter(res_lrouter,
                          lrouter['uuid'],
                          'new_name',
                          '192.168.0.1',
                          'pippo',
                          expected_neutron_id=neutron_id)
Beispiel #8
0
 def test_update_lrouter(self):
     neutron_id = uuidutils.generate_uuid()
     lrouter = routerlib.create_lrouter(self.fake_cluster,
                                        neutron_id,
                                        'pippo',
                                        'fake-lrouter',
                                        '10.0.0.1')
     lrouter = routerlib.update_lrouter(self.fake_cluster,
                                        lrouter['uuid'],
                                        'new_name',
                                        '192.168.0.1')
     res_lrouter = routerlib.get_lrouter(self.fake_cluster,
                                         lrouter['uuid'])
     self._verify_lrouter(res_lrouter, lrouter['uuid'],
                          'new_name', '192.168.0.1', 'pippo',
                          expected_neutron_id=neutron_id)
Beispiel #9
0
    def test_get_lrouter(self):
        tenant_id = 'fake_tenant_id'
        router_name = 'fake_router_name'
        router_id = 'fake_router_id'
        relations = {
            'LogicalRouterStatus':
            {'_href': '/ws.v1/lrouter/%s/status' % router_id,
             'lport_admin_up_count': 1,
             '_schema': '/ws.v1/schema/LogicalRouterStatus',
             'lport_count': 1,
             'fabric_status': True,
             'type': 'LogicalRouterStatus',
             'lport_link_up_count': 0, }, }

        with mock.patch.object(routerlib, 'do_request',
                               return_value=self._get_lrouter(tenant_id,
                                                              router_name,
                                                              router_id,
                                                              relations)):
            lrouter = routerlib.get_lrouter(self.fake_cluster, router_id)
            self.assertTrue(
                lrouter['_relations']['LogicalRouterStatus']['fabric_status'])
Beispiel #10
0
    def test_get_lrouter(self):
        tenant_id = 'fake_tenant_id'
        router_name = 'fake_router_name'
        router_id = 'fake_router_id'
        relations = {
            'LogicalRouterStatus':
            {'_href': '/ws.v1/lrouter/%s/status' % router_id,
             'lport_admin_up_count': 1,
             '_schema': '/ws.v1/schema/LogicalRouterStatus',
             'lport_count': 1,
             'fabric_status': True,
             'type': 'LogicalRouterStatus',
             'lport_link_up_count': 0, }, }

        with mock.patch.object(routerlib, 'do_request',
                               return_value=self._get_lrouter(tenant_id,
                                                              router_name,
                                                              router_id,
                                                              relations)):
            lrouter = routerlib.get_lrouter(self.fake_cluster, router_id)
            self.assertTrue(
                lrouter['_relations']['LogicalRouterStatus']['fabric_status'])