v2 'help' behaviour depends on (a) credentials/local environment

Bug #1490457 reported by Stuart McLaren
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Fix Released
Medium
Flavio Percoco

Bug Description

This works fine if no credentials are set:

$ glance --debug --os-image-api-version 2 help image-create
usage: glance image-create [--architecture <ARCHITECTURE>]
                           [--protected [True|False]] [--name <NAME>]
                           [--instance-uuid <INSTANCE_UUID>]
                           [--min-disk <MIN_DISK>] [--visibility <VISIBILITY>]
                           [--kernel-id <KERNEL_ID>]
                           [--tags <TAGS> [<TAGS> ...]]
                           [--os-version <OS_VERSION>]
                           [--disk-format <DISK_FORMAT>] [--self <SELF>]
                           [--os-distro <OS_DISTRO>] [--id <ID>]
                           [--owner <OWNER>] [--ramdisk-id <RAMDISK_ID>]
                           [--min-ram <MIN_RAM>]
                           [--container-format <CONTAINER_FORMAT>]
                           [--property <key=value>] [--file <FILE>]
                           [--progress]

Optional arguments:
  --architecture <ARCHITECTURE>
                        Operating system architecture as specified in
                        http://docs.openstack.org/trunk/openstack-
                        compute/admin/content/adding-images.html
  --protected [True|False]
                        If true, image will not be deletable.
  --name <NAME> Descriptive name for the image

but if any arguments are set the v1 help is shown, even though the user clearly wants the v2 help:

$ OS_AUTH_URL=blah glance --debug --os-image-api-version 2 help image-create
WARNING: The client is falling back to v1 because the accessing to v2 failed. This behavior will be removed in future versions
usage: glance image-create [--id <IMAGE_ID>] [--name <NAME>] [--store <STORE>]
                           [--disk-format <DISK_FORMAT>]
                           [--container-format <CONTAINER_FORMAT>]
                           [--owner <TENANT_ID>] [--size <SIZE>]
                           [--min-disk <DISK_GB>] [--min-ram <DISK_RAM>]
                           [--location <IMAGE_URL>] [--file <FILE>]
                           [--checksum <CHECKSUM>] [--copy-from <IMAGE_URL>]
                           [--is-public {True,False}]
                           [--is-protected {True,False}]
                           [--property <key=value>] [--human-readable]
                           [--progress]

Optional arguments:
  --id <IMAGE_ID> ID of image to reserve.
  --name <NAME> Name of image.
  --store <STORE> Store to upload image to.
  --disk-format <DISK_FORMAT>
                        Disk format of image. Acceptable formats: ami, ari,
                        aki, vhd, vmdk, raw, qcow2, vdi, and iso.

If they have a full set of valid credentials then either:

1) the v2 help will be displayed if the glance service is up
2) the v1 help will be displayed if the glance service happens to be offline

It should never be necessary to authenticate with the server in order to display the help page.

summary: - Cannot display v2 help cloud is offline
+ v2 'help' behaviour depends on (a) credentials/local environment and (b)
+ current state of server
tags: added: 1.0.0-potential
summary: - v2 'help' behaviour depends on (a) credentials/local environment and (b)
- current state of server
+ v2 'help' behaviour depends on (a) credentials/local environment
Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

It looks like the behaviour just depends on having all the usual credentials set -- there's no attempt to contact the server.

I'd guess the:

 force_auth=True

below is what's causing _cache_schema to fail, which causes us to revert to v1.

    def _cache_schemas(self, options, home_dir='~/.glanceclient'):
        homedir = os.path.expanduser(home_dir)
        path_prefix = homedir
        if options.os_auth_url:
            hash_host = hashlib.sha1(options.os_auth_url.encode('utf-8'))
            path_prefix = os.path.join(path_prefix, hash_host.hexdigest())
        if not os.path.exists(path_prefix):
            try:
                os.makedirs(path_prefix)
            except OSError as e:
                # This avoids glanceclient to crash if it can't write to
                # ~/.glanceclient, which may happen on some env (for me,
                # it happens in Jenkins, as Glanceclient can't write to
                # /var/lib/jenkins).
                msg = '%s' % e
                print(encodeutils.safe_decode(msg), file=sys.stderr)
        resources = ['image', 'metadefs/namespace', 'metadefs/resource_type']
        schema_file_paths = [os.path.join(path_prefix, x + '_schema.json')
                             for x in ['image', 'namespace', 'resource_type']]

        client = None
        failed_download_schema = 0
        for resource, schema_file_path in zip(resources, schema_file_paths):
            if (not os.path.exists(schema_file_path)) or options.get_schema:
                try:
                    if not client:
                        client = self._get_versioned_client('2', options,
                                                            force_auth=True)

Changed in python-glanceclient:
assignee: nobody → Stuart McLaren (stuart-mclaren)
Revision history for this message
Stuart McLaren (stuart-mclaren) wrote :

Flavio,

If you're going to look at this, I'm wondering if the following behaviour makes sense:

1) displaying the help shouldn't depend on what OS_XXX variables you have set, and shouldn't try to contact the server
2) "glance/glance -h/glance --help/glance help" should all display v2 help
3) "glance --os-image-api-version 1/glance --os-image-api-version 1 -h/glance --os-image-api-version 1 --help/glance --os-image-api-version 1 help" should all display v1 help
4) maybe at the end of the v2 help we should suggest 'run glance --os-image-api-version 1 help' for v1 help?

Changed in python-glanceclient:
assignee: Stuart McLaren (stuart-mclaren) → nobody
assignee: nobody → Flavio Percoco (flaper87)
Revision history for this message
Flavio Percoco (flaper87) wrote :

I fully agree with that and you just described the patch I worked on yday! I kinda moved things around to also avoid doing version checks for `glance -h/help`

Changed in python-glanceclient:
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
Flavio Percoco (flaper87) wrote :
Changed in python-glanceclient:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-glanceclient (master)

Reviewed: https://review.openstack.org/220096
Committed: https://git.openstack.org/cgit/openstack/python-glanceclient/commit/?id=5026774bd1b8cdd079256a21cbbb74ba687267a9
Submitter: Jenkins
Branch: master

commit 5026774bd1b8cdd079256a21cbbb74ba687267a9
Author: Flavio Percoco <email address hidden>
Date: Thu Sep 3 13:48:28 2015 +0200

    Don't make `help` require auth parameters

    The `help` command was behaving a bit funky. This patch re-orders the
    code a bit so that the `help` command will be parsed at the very
    beginning before running other commands and checks.

    It also allows to get help without downloading/checking schemas and
    without requiring auth credentials (previously required by the schema
    operations).

    Change-Id: Ib7b10d4d80f15e6b75bb8644d7d916bef09413d6
    Closes-bug: #1490457

Changed in python-glanceclient:
status: In Progress → Fix Committed
Changed in python-glanceclient:
milestone: none → 1.1.0
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.