python client crashes because of auth_token type

Bug #1254186 reported by Marc Solanas
30
This bug affects 6 people
Affects Status Importance Assigned to Milestone
python-ceilometerclient
Fix Released
Medium
Marc Solanas

Bug Description

When initializing a client object with the following lines:

import ceilometerclient.client as clients
client = clients.get_client('2',ceilometer_url="IP:PORT" ,os_auth_token= context.to_dict()['auth_token'])

this error is displayed when a query is performed:

File "/opt/stack/python-ceilometerclient/ceilometerclient/common/http.py", line 182, in json_request
resp, body_iter = self._http_request(url, method, **kwargs)
File "/opt/stack/python-ceilometerclient/ceilometerclient/common/http.py", line 132, in _http_request
auth_token = self.auth_token()
TypeError: 'unicode' object is not callable

Having a look at the get_client function in ceilometer/client.py, it can be seen that auth_token is changed to a lambda in the elif, but not in the if:

    if kwargs.get('os_auth_token') and kwargs.get('ceilometer_url'):
        token = kwargs.get('os_auth_token') """NOT CHANGED"""
        endpoint = kwargs.get('ceilometer_url')
    elif (kwargs.get('os_username') and
          kwargs.get('os_password') and
          kwargs.get('os_auth_url') and
          (kwargs.get('os_tenant_id') or kwargs.get('os_tenant_name'))):

        ks_kwargs = {
            'username': kwargs.get('os_username'),
            'password': kwargs.get('os_password'),
            'tenant_id': kwargs.get('os_tenant_id'),
            'tenant_name': kwargs.get('os_tenant_name'),
            'auth_url': kwargs.get('os_auth_url'),
            'region_name': kwargs.get('os_region_name'),
            'service_type': kwargs.get('os_service_type'),
            'endpoint_type': kwargs.get('os_endpoint_type'),
            'cacert': kwargs.get('os_cacert'),
            'insecure': kwargs.get('insecure'),
        }

        _ksclient = _get_ksclient(**ks_kwargs)
        token = ((lambda: kwargs.get('os_auth_token')) """CHANGED"""
                 if kwargs.get('os_auth_token')
                 else (lambda: _ksclient.auth_token))

so "token" could have different types depending on the case.

Marc Solanas (msolanas)
Changed in python-ceilometerclient:
assignee: nobody → Marc Solanas (msolanas)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-ceilometerclient (master)

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

gordon chung (chungg)
Changed in python-ceilometerclient:
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-ceilometerclient (master)

Reviewed: https://review.openstack.org/58051
Committed: https://git.openstack.org/cgit/openstack/python-ceilometerclient/commit/?id=69be3ff0e48e062e412c9e01c2c16995f6ecd3d8
Submitter: Jenkins
Branch: master

commit 69be3ff0e48e062e412c9e01c2c16995f6ecd3d8
Author: Marc Solanas <email address hidden>
Date: Thu Mar 13 23:09:50 2014 -0700

    Checking the type of auth_token, and fixing it if necessary

    When creating a new Client object by calling the get_client function,
    if the ceilometer_url is not passed as a parameter, but the token is
    passed, the auth_token is converted to a lambda function.
    However, when both the ceilometer_url and the auth_token are passed,
    this conversion does not take place.
    This fix checks if the auth_token is a lambda function or not.
    If it is not, it creates a new lambda function which returns the
    token.
    Without this check, if a token was passed as a string, the
    python client would throw and error, when trying to call
    self.auth_token() in ceilomenterclient/common/http.py.

    Change-Id: I3e564fcf17ce497546b75f0ab8c7ca0f6f2099df
    Closes-Bug: #1254186

Changed in python-ceilometerclient:
status: In Progress → Fix Committed
Revision history for this message
kexiaodong (kexiaodong) wrote :

I test the plugin in python 2.7.3, and found that the source in commited plugin has bug:
  token=kwargs.get('os_auth_token')
  token=lambda:token
the token will be a dead loop lambda, and can't use as "token()".

Revision history for this message
Marc Solanas (msolanas) wrote :

I am afraid I can't find these lines in this bug fix. Would you be kind enough to point me to them?

Revision history for this message
kexiaodong (kexiaodong) wrote :

It is line 65,
when os_auth_token is a real token, then six.callable return false, so it will be
 token=lambda:token

It will not work for "token()", result will not be input token but function address.
I have submit bug 1301877 for the new problem

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

Duplicates of this bug

Other bug subscribers

Remote bug watches

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