Beispiel #1
0
 def _create_lrouter(self, version, neutron_id=None, distributed=None):
     with mock.patch.object(
         self.fake_cluster.api_client, 'get_version',
         return_value=ver_module.Version(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 #2
0
 def _create_lrouter(self, version, neutron_id=None, distributed=None):
     with mock.patch.object(
         self.fake_cluster.api_client, 'get_version',
         return_value=ver_module.Version(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 #3
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 #4
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 #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 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 #7
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 #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(nsxlib, '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(nsxlib, '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'])