コード例 #1
0
    def test_get_missing_service_catalog(self, mock_v3, mkreqctx):
        class FakeKeystone(fakes.FakeKeystoneClient):
            def __init__(self):
                super(FakeKeystone, self).__init__()
                self.client = self
                self.version = 'v3'

        self.stub_keystoneclient(fake_client=FakeKeystone())
        con = mock.Mock(auth_token="1234", trust_id=None)
        c = clients.Clients(con)
        con.clients = c

        con.auth_plugin = mock.Mock(name="auth_plugin")
        get_endpoint_side_effects = [
            keystone_exc.EmptyCatalog(), None, 'http://192.0.2.1/bar']
        con.auth_plugin.get_endpoint = mock.Mock(
            name="get_endpoint", side_effect=get_endpoint_side_effects)

        mock_token_obj = mock.Mock()
        mock_token_obj.get_auth_ref.return_value = {'catalog': 'foo'}
        mock_v3.return_value = mock_token_obj

        plugin = FooClientsPlugin(con)
        mock_cxt_dict = {'auth_token_info': {'token': {'catalog': 'baz'}}}
        plugin.context.to_dict.return_value = mock_cxt_dict

        mkreqctx.from_dict.return_value.auth_plugin = con.auth_plugin

        self.assertEqual('http://192.0.2.1/bar',
                         plugin.url_for(service_type='bar'))
コード例 #2
0
ファイル: test_clients.py プロジェクト: whitepages/heat
    def test_endpoint_not_found(self, mock_v3):
        class FakeKeystone(fakes.FakeKeystoneClient):
            def __init__(self):
                super(FakeKeystone, self).__init__()
                self.client = self
                self.version = 'v3'

        self.stub_keystoneclient(fake_client=FakeKeystone())
        con = mock.MagicMock(auth_token="1234", trust_id=None)
        c = clients.Clients(con)
        con.clients = c

        con.auth_plugin = mock.Mock(name="auth_plugin")
        get_endpoint_side_effects = [keystone_exc.EmptyCatalog(), None]
        con.auth_plugin.get_endpoint = mock.Mock(
            name="get_endpoint", side_effect=get_endpoint_side_effects)

        mock_token_obj = mock.Mock()
        mock_v3.return_value = mock_token_obj
        mock_token_obj.get_auth_ref.return_value = {'no_catalog': 'without'}

        plugin = FooClientsPlugin(con)

        self.assertRaises(keystone_exc.EndpointNotFound,
                          plugin.url_for,
                          service_type='nonexistent')
コード例 #3
0
    def url_for(self, attr=None, filter_value=None,
                service_type='identity', endpoint_type='publicURL'):
        """Fetch an endpoint from the service catalog.

        Fetch the specified endpoint from the service catalog for
        a particular endpoint attribute. If no attribute is given, return
        the first endpoint of the specified type.

        Valid endpoint types: `publicURL`, `internalURL`, `adminURL`

        See tests for a sample service catalog.
        """
        catalog = self.catalog.get('serviceCatalog', [])

        if not catalog:
            raise exceptions.EmptyCatalog('The service catalog is empty.')

        for service in catalog:
            if service['type'] != service_type:
                continue

            endpoints = service['endpoints']
            for endpoint in endpoints:
                if not filter_value or endpoint.get(attr) == filter_value:
                    return endpoint[endpoint_type]

        raise exceptions.EndpointNotFound('Endpoint not found.')
コード例 #4
0
    def url_for(self,
                attr=None,
                filter_value=None,
                service_type='identity',
                endpoint_type='public'):
        catalog = self.get_data()

        if not catalog:
            raise exceptions.EmptyCatalog('The service catalog is empty.')

        if endpoint_type:
            endpoint_type = endpoint_type.rstrip('URL')

        for service in catalog:
            if service['type'] != service_type:
                continue

            endpoints = service['endpoints']
            for endpoint in endpoints:
                if endpoint.get('interface') != endpoint_type:
                    continue
                if (self.region_name
                        and endpoint.get('region') != self.region_name):
                    continue
                if not filter_value or endpoint.get(attr) == filter_value:
                    return endpoint['url']

        raise exceptions.EndpointNotFound('%s endpoint for %s not found.' %
                                          (endpoint_type, service_type))
コード例 #5
0
    def url_for(self,
                attr=None,
                filter_value=None,
                service_type='identity',
                endpoint_type='publicURL'):
        catalog = self.catalog.get('serviceCatalog', [])

        if not catalog:
            raise exceptions.EmptyCatalog('The service catalog is empty.')

        if 'URL' not in endpoint_type:
            endpoint_type = endpoint_type + 'URL'

        for service in catalog:
            if service['type'] != service_type:
                continue

            endpoints = service['endpoints']
            for endpoint in endpoints:
                if (self.region_name
                        and endpoint.get('region') != self.region_name):
                    continue
                if not filter_value or endpoint.get(attr) == filter_value:
                    return endpoint[endpoint_type]

        raise exceptions.EndpointNotFound('%s endpoint for %s not found.' %
                                          (endpoint_type, service_type))
コード例 #6
0
    def url_for(self,
                attr=None,
                filter_value=None,
                service_type='identity',
                endpoint_type='publicURL',
                region_name=None,
                service_name=None):
        """Fetch an endpoint from the service catalog.

        Fetch the specified endpoint from the service catalog for
        a particular endpoint attribute. If no attribute is given, return
        the first endpoint of the specified type.

        Valid endpoint types: `public` or `publicURL`,
                              `internal` or `internalURL`,
                              `admin` or 'adminURL`

        :param string attr: Endpoint attribute name.
        :param string filter_value: Endpoint attribute value.
        :param string service_type: Service type of the endpoint.
        :param string endpoint_type: Type of endpoint.
        :param string region_name: Region of the endpoint.
        :param string service_name: The assigned name of the service.
        :
        """
        if not self.get_data():
            raise exceptions.EmptyCatalog('The service catalog is empty.')

        urls = self.get_urls(attr=attr,
                             filter_value=filter_value,
                             service_type=service_type,
                             endpoint_type=endpoint_type,
                             region_name=region_name,
                             service_name=service_name)

        try:
            return urls[0]
        except Exception:
            pass

        msg = '%s endpoint for %s service' % (endpoint_type, service_type)
        if service_name:
            msg += ' named %s' % service_name
        if region_name:
            msg += ' in %s region' % region_name
        msg += ' not found'
        raise exceptions.EndpointNotFound(msg)
コード例 #7
0
    def url_for(self,
                attr=None,
                filter_value=None,
                service_type='identity',
                endpoint_type='publicURL',
                region_name=None):
        """Fetch an endpoint from the service catalog.

        Fetch the specified endpoint from the service catalog for
        a particular endpoint attribute. If no attribute is given, return
        the first endpoint of the specified type.

        Valid endpoint types: `public` or `publicURL`,
                              `internal` or `internalURL`,
                              `admin` or 'adminURL`
        """
        if not self.get_data():
            raise exceptions.EmptyCatalog('The service catalog is empty.')

        urls = self.get_urls(attr=attr,
                             filter_value=filter_value,
                             service_type=service_type,
                             endpoint_type=endpoint_type,
                             region_name=region_name)

        try:
            return urls[0]
        except Exception:
            pass

        msg = '%(endpoint)s endpoint for %(service)s%(region)s not found'
        region = ' in %s region' % region_name if region_name else ''
        msg = msg % {
            'endpoint': endpoint_type,
            'service': service_type,
            'region': region
        }

        raise exceptions.EndpointNotFound(msg)
コード例 #8
0
    def url_for(self,
                attr=None,
                filter_value=None,
                service_type='identity',
                endpoint_type='publicURL',
                region_name=None,
                service_name=None):
        """Fetch an endpoint from the service catalog.

        Fetch the specified endpoint from the service catalog for
        a particular endpoint attribute. If no attribute is given, return
        the first endpoint of the specified type.

        Valid endpoint types: `public` or `publicURL`,
                              `internal` or `internalURL`,
                              `admin` or 'adminURL`

        :param string attr: Endpoint attribute name.
        :param string filter_value: Endpoint attribute value.
        :param string service_type: Service type of the endpoint.
        :param string endpoint_type: Type of endpoint.
        :param string region_name: Region of the endpoint.
        :param string service_name: The assigned name of the service.

        """
        if not self.get_data():
            raise exceptions.EmptyCatalog(_('The service catalog is empty.'))

        urls = self.get_urls(attr=attr,
                             filter_value=filter_value,
                             service_type=service_type,
                             endpoint_type=endpoint_type,
                             region_name=region_name,
                             service_name=service_name)

        try:
            return urls[0]
        except Exception:
            if service_name and region_name:
                msg = (_('%(endpoint_type)s endpoint for %(service_type)s '
                         'service named %(service_name)s in %(region_name)s '
                         'region not found') % {
                             'endpoint_type': endpoint_type,
                             'service_type': service_type,
                             'service_name': service_name,
                             'region_name': region_name
                         })
            elif service_name:
                msg = (_('%(endpoint_type)s endpoint for %(service_type)s '
                         'service named %(service_name)s not found') % {
                             'endpoint_type': endpoint_type,
                             'service_type': service_type,
                             'service_name': service_name
                         })
            elif region_name:
                msg = (_('%(endpoint_type)s endpoint for %(service_type)s '
                         'service in %(region_name)s region not found') % {
                             'endpoint_type': endpoint_type,
                             'service_type': service_type,
                             'region_name': region_name
                         })
            else:
                msg = (_('%(endpoint_type)s endpoint for %(service_type)s '
                         'service not found') % {
                             'endpoint_type': endpoint_type,
                             'service_type': service_type
                         })

            raise exceptions.EndpointNotFound(msg)