Python keystoneauth1.exceptions.EndpointNotFound() Examples

The following are 12 code examples of keystoneauth1.exceptions.EndpointNotFound(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module keystoneauth1.exceptions , or try the search function .
Example #1
Source File: promenade_client.py    From drydock with Apache License 2.0 6 votes vote down vote up
def _get_prom_url(self):
        # Get promenade url from Keystone session object

        ks_session = self._get_ks_session()

        try:
            prom_endpoint = ks_session.get_endpoint(
                interface='internal', service_type='kubernetesprovisioner')
        except exc.EndpointNotFound:
            self.logger.error("Could not find an internal interface"
                              " defined in Keystone for Promenade")

            raise errors.DriverError("Could not find an internal interface"
                                     " defined in Keystone for Promenade")

        prom_url = urlparse(prom_endpoint)

        return prom_url 
Example #2
Source File: service_endpoints.py    From shipyard with Apache License 2.0 6 votes vote down vote up
def get_endpoint(endpoint):
    """
    Wraps calls to keystone for lookup of an endpoint by service type
    :param Endpoints endpoint: The endpoint to look up
    :returns: The url string of the endpoint
    :rtype: str
    :raises AppError: if the endpoint cannot be resolved
    """
    service_type = _get_service_type(endpoint)
    try:
        return _get_ks_session().get_endpoint(
            interface='internal',
            service_type=service_type)
    except exc.EndpointNotFound:
        LOG.error('Could not find an internal interface for %s',
                  endpoint.name)
        raise AppError(
            title='Can not access service endpoint',
            description=(
                'Keystone catalog has no internal endpoint for service type: '
                '{}'.format(service_type)
            ),
            status=falcon.HTTP_500,
            retry=False) 
Example #3
Source File: test_report.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_ensure_resource_provider_create_no_placement(
            self, get_rpt_mock, refresh_mock, create_rp_mock):
        create_rp_mock.side_effect = ks_exc.EndpointNotFound('test')
        # No resource provider exists in the client's cache, and
        # _create_resource_provider raise because
        # Placement isn't running yet. Ensure we don't populate the resource
        # provider cache.
        get_rpt_mock.return_value = []

        self.assertRaises(
            exception.ResourceProviderCreationFailed,
            self.client._ensure_resource_provider, self.context,
            uuids.compute_node)

        get_rpt_mock.assert_called_once_with(self.context, uuids.compute_node)
        create_rp_mock.assert_called_once_with(
            self.context, uuids.compute_node, uuids.compute_node,
            parent_provider_uuid=None)
        self.assertFalse(self.client._provider_tree.exists(uuids.compute_node))
        refresh_mock.assert_not_called()
        self.assertRaises(
            ValueError,
            self.client._provider_tree.in_aggregates, uuids.compute_node, [])
        self.assertRaises(
            ValueError,
            self.client._provider_tree.has_traits, uuids.compute_node, []) 
Example #4
Source File: test_report.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_get_providers_in_tree_ksa_exc(self):
        self.ks_adap_mock.get.side_effect = ks_exc.EndpointNotFound()
        self.assertRaises(
            ks_exc.ClientException,
            self.client.get_providers_in_tree, self.context, uuids.whatever) 
Example #5
Source File: test_report.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_get_provider_traits_placement_comm_error(self):
        """ksa ClientException raises through."""
        uuid = uuids.compute_node
        self.ks_adap_mock.get.side_effect = ks_exc.EndpointNotFound()
        self.assertRaises(ks_exc.ClientException,
                          self.client.get_provider_traits, self.context, uuid)
        expected_url = '/resource_providers/' + uuid + '/traits'
        self.ks_adap_mock.get.assert_called_once_with(
            expected_url,
            endpoint_filter=mock.ANY,
            logger=mock.ANY,
            headers={'X-Openstack-Request-Id': self.context.global_id},
            **self.trait_api_kwargs) 
Example #6
Source File: test_report.py    From zun with Apache License 2.0 5 votes vote down vote up
def test_remove_res_from_alloc_failed_to_get_alloc(
            self, mock_get):
        mock_get.side_effect = ks_exc.EndpointNotFound()
        resources_to_remove = {
            uuids.rp1: {
                'NET_BW_EGR_KILOBIT_PER_SEC': 200,
                'NET_BW_IGR_KILOBIT_PER_SEC': 200,
            }
        }

        self.assertRaises(
            ks_exc.ClientException,
            self.client.remove_resources_from_container_allocation,
            self.context, uuids.consumer_uuid, resources_to_remove) 
Example #7
Source File: client.py    From eclcli with Apache License 2.0 5 votes vote down vote up
def _get_alarm_client(**ceilo_kwargs):
        """Get client for alarm manager that redirect to aodh."""
        # NOTE(sileht): the auth_plugin/keystone session cannot be copied
        # because they rely on threading module.
        auth_plugin = ceilo_kwargs.pop('auth_plugin', None)
        session = ceilo_kwargs.pop('session', None)

        kwargs = copy.deepcopy(ceilo_kwargs)
        kwargs["service_type"] = "alarming"
        aodh_endpoint = ceilo_kwargs.get('aodh_endpoint')

        if session:
            # keystone session can be shared between client
            ceilo_kwargs['session'] = kwargs['session'] = session
            if aodh_endpoint:
                kwargs['endpoint_override'] = aodh_endpoint
        elif auth_plugin and kwargs.get('auth_url'):
            ceilo_kwargs['auth_plugin'] = auth_plugin
            kwargs.pop('endpoint', None)
            kwargs['auth_plugin'] = monitoringclient.get_auth_plugin(
                aodh_endpoint, **kwargs)
        else:
            # Users may just provide ceilometer endpoint and token, and no
            # auth_url, in this case, we need 'aodh_endpoint' also to be
            # provided, otherwise we cannot get aodh endpoint from
            # keystone, and assume aodh is unavailable.
            return None

        try:
            # NOTE(sileht): try to use aodh

            c = monitoringclient._construct_http_client(**kwargs)
            c.get("/")
            return c
        except ka_exc.EndpointNotFound:
            return None
        except requests.exceptions.ConnectionError:
            return None 
Example #8
Source File: test_client_connectivity.py    From python-barbicanclient with Apache License 2.0 5 votes vote down vote up
def assert_client_cannot_get_endpoint(self, client):
        self.assertRaises(ks_exceptions.EndpointNotFound,
                          client.containers.list)
        self.assertRaises(ks_exceptions.EndpointNotFound,
                          client.orders.list)
        self.assertRaises(ks_exceptions.EndpointNotFound,
                          client.secrets.list) 
Example #9
Source File: query.py    From zun with Apache License 2.0 4 votes vote down vote up
def select_destinations(self, context, containers, extra_specs):
        LOG.debug("Starting to schedule for containers: %s",
                  [c.uuid for c in containers])

        if not self.traits_ensured:
            self.placement_client._ensure_traits(context, consts.CUSTOM_TRAITS)
            self.traits_ensured = True

        alloc_reqs_by_rp_uuid, provider_summaries, allocation_request_version \
            = None, None, None
        request_filter.process_reqspec(context, extra_specs)
        resources = utils.resources_from_request_spec(
            context, containers[0], extra_specs)

        try:
            res = self.placement_client.get_allocation_candidates(context,
                                                                  resources)
            (alloc_reqs, provider_summaries, allocation_request_version) = res
        except (ks_exc.EndpointNotFound,
                ks_exc.MissingAuthPlugin,
                ks_exc.Unauthorized,
                ks_exc.DiscoveryFailure,
                ks_exc.ConnectFailure):
            # We have to handle the case that we failed to connect to the
            # Placement service.
            alloc_reqs, provider_summaries, allocation_request_version = (
                None, None, None)
        if not alloc_reqs:
            LOG.info("Got no allocation candidates from the Placement "
                     "API. This could be due to insufficient resources "
                     "or a temporary occurrence as compute nodes start "
                     "up.")
            raise exception.NoValidHost(reason="")
        else:
            # Build a dict of lists of allocation requests, keyed by
            # provider UUID, so that when we attempt to claim resources for
            # a host, we can grab an allocation request easily
            alloc_reqs_by_rp_uuid = collections.defaultdict(list)
            for ar in alloc_reqs:
                for rp_uuid in ar['allocations']:
                    alloc_reqs_by_rp_uuid[rp_uuid].append(ar)

        selections = self.driver.select_destinations(
            context, containers, extra_specs, alloc_reqs_by_rp_uuid,
            provider_summaries, allocation_request_version)
        return selections 
Example #10
Source File: keystone.py    From designate with Apache License 2.0 4 votes vote down vote up
def verify_project_id(context, project_id):
    """verify that a project_id exists.

    This attempts to verify that a project id exists. If it does not,
    an HTTPBadRequest is emitted.

    """
    session = ksa_loading.load_session_from_conf_options(
        CONF, 'keystone', auth=context.get_auth_plugin())
    adap = ksa_loading.load_adapter_from_conf_options(
        CONF, 'keystone',
        session=session, min_version=(3, 0), max_version=(3, 'latest'))
    try:
        resp = adap.get('/projects/%s' % project_id, raise_exc=False)
    except kse.EndpointNotFound:
        LOG.error(
            "Keystone identity service version 3.0 was not found. This might "
            "be because your endpoint points to the v2.0 versioned endpoint "
            "which is not supported. Please fix this.")
        raise exceptions.KeystoneCommunicationFailure(
            _("KeystoneV3 endpoint not found"))
    except kse.ClientException:
        # something is wrong, like there isn't a keystone v3 endpoint,
        # or nova isn't configured for the interface to talk to it;
        # we'll take the pass and default to everything being ok.
        LOG.info("Unable to contact keystone to verify project_id")
        return True

    if resp:
        # All is good with this 20x status
        return True
    elif resp.status_code == 404:
        # we got access, and we know this project is not there
        raise exceptions.InvalidProject(
            _("%s is not a valid project ID.") % project_id)

    elif resp.status_code == 403:
        # we don't have enough permission to verify this, so default
        # to "it's ok".
        LOG.info(
            "Insufficient permissions for user %(user)s to verify "
            "existence of project_id %(pid)s",
            {"user": context.user_id, "pid": project_id})
        return True
    else:
        LOG.warning(
            "Unexpected response from keystone trying to "
            "verify project_id %(pid)s - resp: %(code)s %(content)s",
            {"pid": project_id,
             "code": resp.status_code,
             "content": resp.content})
        # realize we did something wrong, but move on with a warning
        return True 
Example #11
Source File: cinder.py    From glance_store with Apache License 2.0 4 votes vote down vote up
def get_cinderclient(self, context=None):
        if self.backend_group:
            glance_store = getattr(self.conf, self.backend_group)
        else:
            glance_store = self.conf.glance_store

        user_overriden = self.is_user_overriden()
        if user_overriden:
            username = glance_store.cinder_store_user_name
            password = glance_store.cinder_store_password
            project = glance_store.cinder_store_project_name
            url = glance_store.cinder_store_auth_address
        else:
            username = context.user
            password = context.auth_token
            project = context.tenant

            if glance_store.cinder_endpoint_template:
                url = glance_store.cinder_endpoint_template % context.to_dict()
            else:
                info = glance_store.cinder_catalog_info
                service_type, service_name, interface = info.split(':')
                try:
                    catalog = keystone_sc.ServiceCatalogV2(
                        context.service_catalog)
                    url = catalog.url_for(
                        region_name=glance_store.cinder_os_region_name,
                        service_type=service_type,
                        service_name=service_name,
                        interface=interface)
                except keystone_exc.EndpointNotFound:
                    reason = _("Failed to find Cinder from a service catalog.")
                    raise exceptions.BadStoreConfiguration(store_name="cinder",
                                                           reason=reason)

        c = cinderclient.Client(
            username, password, project, auth_url=url,
            region_name=glance_store.cinder_os_region_name,
            insecure=glance_store.cinder_api_insecure,
            retries=glance_store.cinder_http_retries,
            cacert=glance_store.cinder_ca_certificates_file)

        LOG.debug(
            'Cinderclient connection created for user %(user)s using URL: '
            '%(url)s.', {'user': username, 'url': url})

        # noauth extracts user_id:project_id from auth_token
        if not user_overriden:
            c.client.auth_token = context.auth_token or '%s:%s' % (username,
                                                                   project)
        c.client.management_url = url
        return c 
Example #12
Source File: utils.py    From cyborg with Apache License 2.0 4 votes vote down vote up
def get_endpoint(ksa_adapter):
    """Get the endpoint URL represented by a keystoneauth1 Adapter.

    This method is equivalent to what

        ksa_adapter.get_endpoint()

    should do, if it weren't for a panoply of bugs.

    :param ksa_adapter: keystoneauth1.adapter.Adapter, appropriately set up
                        with an endpoint_override; or service_type, interface
                        (list) and auth/service_catalog.
    :return: String endpoint URL.
    :raise EndpointNotFound: If endpoint discovery fails.
    """
    # TODO(efried): This will be unnecessary once bug #1707993 is fixed.
    # (At least for the non-image case, until 1707995 is fixed.)
    if ksa_adapter.endpoint_override:
        return ksa_adapter.endpoint_override
    # TODO(efried): Remove this once bug #1707995 is fixed.
    if ksa_adapter.service_type == 'image':
        try:
            # LOG.warning(ksa_adapter.__dict__)
            return ksa_adapter.get_endpoint_data().catalog_url
        except AttributeError:
            # ksa_adapter.auth is a _ContextAuthPlugin, which doesn't have
            # get_endpoint_data.  Fall through to using get_endpoint().
            pass
    # TODO(efried): The remainder of this method reduces to
    # TODO(efried):     return ksa_adapter.get_endpoint()
    # TODO(efried): once bug #1709118 is fixed.
    # NOTE(efried): Id9bd19cca68206fc64d23b0eaa95aa3e5b01b676 may also do the
    #               trick, once it's in a ksa release.
    # The EndpointNotFound exception happens when _ContextAuthPlugin is in play
    # because its get_endpoint() method isn't yet set up to handle interface as
    # a list.  (It could also happen with a real auth if the endpoint isn't
    # there; but that's covered below.)
    try:
        return ksa_adapter.get_endpoint()
    except ks_exc.EndpointNotFound:
        pass

    interfaces = list(ksa_adapter.interface)
    for interface in interfaces:
        ksa_adapter.interface = interface
        try:
            return ksa_adapter.get_endpoint()
        except ks_exc.EndpointNotFound:
            pass
    raise ks_exc.EndpointNotFound(
        "Could not find requested endpoint for any of the following "
        "interfaces: %s" % interfaces)