← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1379302] Re: Some stale references to BadStoreUri

 

Actually, you can get a BadStoreUri, you just need to go deep into the stack


def get_size_from_backend(uri, context=None):
    """Retrieves image size from backend specified by uri."""

    loc = location.get_location_from_uri(uri, conf=CONF)
    store = get_store_from_uri(uri)

    return store.get_size(loc, context=context)




def get_store_from_uri(uri):
    """
    Given a URI, return the store object that would handle
    operations on the URI.

    :param uri: URI to analyze
    """
    scheme = uri[0:uri.find('/') - 1]
    return get_store_from_scheme(scheme)



def get_store_from_scheme(scheme):
    """
    Given a scheme, return the appropriate store object
    for handling that scheme.
    """
    if scheme not in location.SCHEME_TO_CLS_MAP:
        raise exceptions.UnknownScheme(scheme=scheme)
    scheme_info = location.SCHEME_TO_CLS_MAP[scheme]
    return scheme_info['store']


def get_location_from_uri(uri, conf=CONF):
    """
    Given a URI, return a Location object that has had an appropriate
    store parse the URI.

    :param uri: A URI that could come from the end-user in the Location
                attribute/header.
    :param conf: The global configuration.

    Example URIs:
        https://user:pass@xxxxxxxxxxx:80/images/some-id
        http://images.oracle.com/123456
        swift://example.com/container/obj-id
        swift://user:account:pass@xxxxxxxxxxx/container/obj-id
        swift+http://user:account:pass@xxxxxxxxxxx/container/obj-id
        s3://accesskey:secretkey@xxxxxxxxxxxxxxxx/bucket/key-id
        s3+https://accesskey:secretkey@xxxxxxxxxxxxxxxx/bucket/key-id
        file:///var/lib/glance/images/1
        cinder://volume-id
    """
    pieces = urlparse.urlparse(uri)
    if pieces.scheme not in SCHEME_TO_CLS_MAP.keys():
        raise exceptions.UnknownScheme(scheme=pieces.scheme)
    scheme_info = SCHEME_TO_CLS_MAP[pieces.scheme]
    return Location(pieces.scheme, scheme_info['location_class'],
                    conf, uri=uri)







class Location(object):

    """
    Class describing the location of an image that Glance knows about
    """

    def __init__(self, store_name, store_location_class, conf,
                 uri=None, image_id=None, store_specs=None):
        """
        Create a new Location object.

        :param store_name: The string identifier/scheme of the storage backend
        :param store_location_class: The store location class to use
                                     for this location instance.
        :param image_id: The identifier of the image in whatever storage
                         backend is used.
        :param uri: Optional URI to construct location from
        :param store_specs: Dictionary of information about the location
                            of the image that is dependent on the backend
                            store
        """
        self.store_name = store_name
        self.image_id = image_id
        self.store_specs = store_specs or {}
        self.conf = conf
        self.store_location = store_location_class(self.store_specs, conf)
        if uri:
            self.store_location.parse_uri(uri) <<<<<

    def get_store_uri(self):
        """
        Returns the Glance image URI, which is the host:port of the API server
        along with /images/<IMAGE_ID>
        """
        return self.store_location.get_uri()

    def get_uri(self):
        return None


in swift/store.py

    def parse_uri(self, uri):
        """
        Parse URLs. This method fixes an issue where credentials specified
        in the URL are interpreted differently in Python 2.6.1+ than prior
        versions of Python. It also deals with the peculiarity that new-style
        Swift URIs have where a username can contain a ':', like so:

            swift://account:user:pass@xxxxxxxxxxx/container/obj
            and for system created locations with account reference
            swift+config://account_reference/container/obj
        """
        # Make sure that URIs that contain multiple schemes, such as:
        # swift://user:pass@http://authurl.com/v1/container/obj
        # are immediately rejected.
        if uri.count('://') != 1:
            reason = _("URI cannot contain more than one occurrence "
                       "of a scheme. If you have specified a URI like "
                       "swift://user:pass@http://authurl.com/v1/container/obj";
                       ", you need to change it to use the "
                       "swift+http:// scheme, like so: "
                       "swift+http://user:pass@xxxxxxxxxxx/v1/container/obj";)
            LOG.info(_LI("Invalid store URI: %(reason)s"), {'reason': reason})
            raise exceptions.BadStoreUri(message=reason) <<<


** Changed in: glance
       Status: New => Invalid

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to Glance.
https://bugs.launchpad.net/bugs/1379302

Title:
  Some stale references to BadStoreUri

Status in OpenStack Image Registry and Delivery Service (Glance):
  Invalid

Bug description:
  In glance/api/v1/images.py

  there are some cases where a store.BadStoreUri are being caught, but
  that exception will not be raised. The potential exception seems to be
  store.UnknownScheme

To manage notifications about this bug go to:
https://bugs.launchpad.net/glance/+bug/1379302/+subscriptions


References