If client api version is passed as string, some comparisons do not work properly

Bug #1534378 reported by Eva Balycheva
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python client library for Zaqar
Fix Released
Medium
Feilong Wang

Bug Description

Take a look at this line: https://github.com/openstack/python-zaqarclient/blob/stable/liberty/zaqarclient/queues/v1/queues.py#L46

If self.client.api_version has string type, even if it has value "1", the condition will evaluate to True, which is wrong.

For example, when I run CLI command:

    $ openstack queue stats my-lovely-queue --os-queues-api-version=1 --debug

 self.client.api_version ends up having string type and the exception is wrongly raised:

(python-zaqarclient27)yell@yelly:~/Sync/Repos/python-zaqarclient$ openstack queue stats my-lovely-queue --os-queues-api-version=1 --debug
START with options: ['queue', 'stats', 'my-lovely-queue', '--os-queues-api-version=1', '--debug']
options: Namespace(access_token_endpoint='', auth_type='', auth_url='http://127.0.0.1:35357/v2.0', cacert='', client_id='', client_secret='***', cloud='', debug=True, default_domain='default', deferred_help=False, domain_id='', domain_name='', endpoint='', identity_provider='', identity_provider_url='', insecure=None, interface='', log_file=None, os_compute_api_version='', os_identity_api_version='', os_image_api_version='', os_network_api_version='', os_object_api_version='', os_project_id=None, os_project_name=None, os_queues_api_version='1', os_volume_api_version='', password='***', project_domain_id='', project_domain_name='', project_id='', project_name='admin', protocol='', region_name='', scope='', service_provider_endpoint='', timing=False, token='***', trust_id='', url='', user_domain_id='', user_domain_name='', user_id='', username='admin', verbose_level=3, verify=None)
defaults: {u'auth_type': 'password', u'compute_api_version': u'2', 'key': None, u'database_api_version': u'1.0', 'api_timeout': None, u'baremetal_api_version': u'1', 'cacert': None, u'image_api_use_tasks': False, u'floating_ip_source': u'neutron', u'orchestration_api_version': u'1', u'interface': None, u'network_api_version': u'2', u'image_format': u'qcow2', u'image_api_version': u'2', u'metering_api_version': u'2', 'verify': True, u'identity_api_version': u'2.0', u'volume_api_version': u'1', 'cert': None, u'secgroup_source': u'neutron', u'container_api_version': u'1', u'dns_api_version': u'2', u'object_store_api_version': u'1', u'disable_vendor_agent': {}}
cloud cfg: {'auth_type': 'password', u'compute_api_version': u'2', 'key': None, u'database_api_version': u'1.0', u'metering_api_version': u'2', u'network_api_version': u'2', u'image_format': u'qcow2', u'image_api_version': u'2', 'verify': True, u'dns_api_version': u'2', u'object_store_api_version': u'1', 'verbose_level': 3, 'region_name': '', 'api_timeout': None, u'baremetal_api_version': u'1', 'queues_api_version': '1', 'auth': {'username': 'admin', 'project_name': 'admin', 'password': '***', 'auth_url': 'http://127.0.0.1:35357/v2.0'}, 'default_domain': 'default', 'debug': True, u'image_api_use_tasks': False, u'floating_ip_source': u'neutron', u'orchestration_api_version': u'1', 'timing': False, 'cacert': None, 'deferred_help': False, u'identity_api_version': u'2.0', u'volume_api_version': u'1', 'cert': None, u'secgroup_source': u'neutron', u'container_api_version': u'1', u'interface': None, u'disable_vendor_agent': {}}
compute API version 2, cmd group openstack.compute.v2
network API version 2, cmd group openstack.network.v2
image API version 2, cmd group openstack.image.v2
volume API version 1, cmd group openstack.volume.v1
identity API version 2.0, cmd group openstack.identity.v2
object_store API version 1, cmd group openstack.object_store.v1
messaging API version 1, cmd group openstack.messaging.v1
command: queue stats -> zaqarclient.queues.v1.cli.GetQueueStats
Auth plugin password selected
auth_type: password
Using auth plugin: password
Using parameters {'username': 'admin', 'password': '***', 'project_name': 'admin', 'auth_url': 'http://127.0.0.1:35357/v2.0'}
Get auth_ref
REQ: curl -g -i -X GET http://127.0.0.1:35357/v2.0 -H "Accept: application/json" -H "User-Agent: python-openstackclient"
Starting new HTTP connection (1): 127.0.0.1
"GET /v2.0 HTTP/1.1" 200 336
RESP: [200] Content-Length: 336 Vary: X-Auth-Token Connection: keep-alive Date: Thu, 14 Jan 2016 23:25:21 GMT Content-Type: application/json X-Openstack-Request-Id: req-f5f06b65-97d9-458e-9540-38bc86201a8e
RESP BODY: {"version": {"status": "stable", "updated": "2014-04-17T00:00:00Z", "media-types": [{"base": "application/json", "type": "application/vnd.openstack.identity-v2.0+json"}], "id": "v2.0", "links": [{"href": "http://127.0.0.1:35357/v2.0/", "rel": "self"}, {"href": "http://docs.openstack.org/", "type": "text/html", "rel": "describedby"}]}}

Making authentication request to http://127.0.0.1:35357/v2.0/tokens
"POST /v2.0/tokens HTTP/1.1" 200 3342
take_action(Namespace(columns=[], formatter='table', max_width=0, noindent=False, prefix='', queue_name='my-lovely-queue', variables=[]))
Making authentication request to http://127.0.0.1:35357/v2.0/tokens
"POST /v2.0/tokens HTTP/1.1" 200 3342
Instantiating queues service client: <class 'zaqarclient.queues.v1.client.Client'>
Unavailable on versions >= 1.1
Traceback (most recent call last):
  File "/home/yell/Python/envs/python-zaqarclient27/local/lib/python2.7/site-packages/cliff/app.py", line 374, in run_subcommand
    result = cmd.run(parsed_args)
  File "/home/yell/Python/envs/python-zaqarclient27/local/lib/python2.7/site-packages/cliff/display.py", line 92, in run
    column_names, data = self.take_action(parsed_args)
  File "/home/yell/Sync/Repos/python-zaqarclient/zaqarclient/queues/v1/cli.py", line 205, in take_action
    if not queue.exists():
  File "/home/yell/Sync/Repos/python-zaqarclient/zaqarclient/queues/v1/queues.py", line 60, in exists
    raise errors.InvalidOperation("Unavailable on versions >= 1.1")
InvalidOperation: Unavailable on versions >= 1.1
clean_up GetQueueStats: Unavailable on versions >= 1.1
Traceback (most recent call last):
  File "/home/yell/Python/envs/python-zaqarclient27/local/lib/python2.7/site-packages/openstackclient/shell.py", line 113, in run
    ret_val = super(OpenStackShell, self).run(argv)
  File "/home/yell/Python/envs/python-zaqarclient27/local/lib/python2.7/site-packages/cliff/app.py", line 255, in run
    result = self.run_subcommand(remainder)
  File "/home/yell/Python/envs/python-zaqarclient27/local/lib/python2.7/site-packages/cliff/app.py", line 374, in run_subcommand
    result = cmd.run(parsed_args)
  File "/home/yell/Python/envs/python-zaqarclient27/local/lib/python2.7/site-packages/cliff/display.py", line 92, in run
    column_names, data = self.take_action(parsed_args)
  File "/home/yell/Sync/Repos/python-zaqarclient/zaqarclient/queues/v1/cli.py", line 205, in take_action
    if not queue.exists():
  File "/home/yell/Sync/Repos/python-zaqarclient/zaqarclient/queues/v1/queues.py", line 60, in exists
    raise errors.InvalidOperation("Unavailable on versions >= 1.1")
InvalidOperation: Unavailable on versions >= 1.1

END return value: 1
(python-zaqarclient27)yell@yelly:~/Sync/Repos/python-zaqarclient$

There are many places in the code like this. Either we fix them all by explicitly converting api_version to float or do such conversion on upper levels.

Eva Balycheva (ubershy)
summary: - If client api version is passed string, some comparisons do not work
+ If client api version is passed as string, some comparisons do not work
properly
Feilong Wang (flwang)
Changed in zaqar:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Fei Long Wang (flwang)
Feilong Wang (flwang)
affects: zaqar → python-zaqarclient
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-zaqarclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/267906

Changed in python-zaqarclient:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-zaqarclient (master)

Reviewed: https://review.openstack.org/267906
Committed: https://git.openstack.org/cgit/openstack/python-zaqarclient/commit/?id=0e2f625dd724923904dbfbece0baa69e33dbcb22
Submitter: Jenkins
Branch: master

commit 0e2f625dd724923904dbfbece0baa69e33dbcb22
Author: Fei Long Wang <email address hidden>
Date: Sat Jan 23 23:47:50 2016 +1300

    Fix wrong api version type

    The api version from openstack client is a string, not a number.
    So we need to convert it to the right type before comparing it
    with a version number.

    Closes-Bug: 1534378

    Change-Id: I55f149b90028f89bb7ff0878a7450df981524026

Changed in python-zaqarclient:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/python-zaqarclient 1.0.0

This issue was fixed in the openstack/python-zaqarclient 1.0.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

This issue was fixed in the openstack/python-zaqarclient 1.0.0 release.

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.