encode_headers which has NoneType value would raise exception

Bug #1415935 reported by hougangliu
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Glance Client
Fix Released
Medium
Ian Cordasco
oslo.utils
Won't Fix
Undecided
Unassigned

Bug Description

glanceclient version:
python-glanceclient-0.15.0-4

refer to https://review.openstack.org/#/c/129289/

 if you're using Nova but don't have Nova configured with
auth_strategy='keystone' (see nova.image.glance._create_glance_client for details),
and when you resize(or other operation need call glance) an VM, it may call
glanceclient, and code may go to the logic like:
/usr/lib/python2.7/site-packages/glanceclient/v1/client.py(36)__init__()
-> self.http_client = http.HTTPClient(endpoint, *args, **kwargs)
> /usr/lib/python2.7/site-packages/glanceclient/common/http.py(57)__init__()

and in /usr/lib/python2.7/site-packages/glanceclient/common/http.py(57)__init__()
 self.identity_headers = kwargs.get('identity_headers') <<<<<<<<<<
 self.auth_token = kwargs.get('token')
and the self.identity_headers may be like:
{'X-Service-Catalog': '[]', 'X-Auth-Token': None, 'X-Roles': u'admin', 'X-Tenant-Id': None, 'X-User-Id': None, 'X-Identity-Status': 'Confirmed'}

and for https://review.openstack.org/#/c/136326/,
for the code:
        if self.identity_headers:
            for k, v in six.iteritems(self.identity_headers):
                headers.setdefault(k, v)

headers would be like: {'X-Service-Catalog': '[]', 'X-Auth-Token': None, 'X-Roles': u'admin', 'X-Tenant-Id': None, 'X-User-Id': None, 'X-Identity-Status': 'Confirmed', ....}

so "headers = self.encode_headers(headers)" in /usr/lib/python2.7/site-packages/glanceclient/common/http.py(1957)__request()
would raise TypeError("NoneType can't be encoded"), thus resize(or other operation need call glance) would fail.

Revision history for this message
hougangliu (liuhoug) wrote :

this defect is similar with the one fixed by https://review.openstack.org/#/c/129289/

Revision history for this message
Ian Cordasco (icordasc) wrote :

What version of glanceclient are you using?

affects: glance → python-glanceclient
Changed in python-glanceclient:
status: New → Incomplete
Joe Cropper (jwcroppe)
description: updated
Changed in python-glanceclient:
status: Incomplete → New
Revision history for this message
hougangliu (liuhoug) wrote :

[root@rhel8249 ~]# glance --version
0.15.0

Revision history for this message
hougangliu (liuhoug) wrote :

If I revert changes of https://review.openstack.org/#/c/136326/, everything is OK

Ian Cordasco (icordasc)
Changed in python-glanceclient:
assignee: nobody → Ian Cordasco (icordasc)
importance: Undecided → Medium
status: New → Confirmed
milestone: none → v0.16.0
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-glanceclient (master)

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

Changed in python-glanceclient:
status: Confirmed → In Progress
Revision history for this message
Ian Cordasco (icordasc) wrote :

As Matt commented [1] this is a bug that encodeutils could probably help us handle appropriately. I'm unsure if handling None is something we wish to do though, so I'm leaving this as New until there's further information.

[1]: https://review.openstack.org/#/c/152159/2/glanceclient/common/http.py

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-glanceclient (master)

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

commit db743e363544d2064107cbaedcf2f5fda4683b8a
Author: Ian Cordasco <email address hidden>
Date: Mon Feb 2 09:39:15 2015 -0600

    Ignore NoneType when encoding headers

    Some generated header values may in fact be None. Trying to encode None
    causes the client to fail with an exception and cannot be worked around
    by the user.

    Change-Id: I638b1fba0ef9a07d726445d8c2cdd774140f5b83
    Closes-bug: 1415935

Changed in python-glanceclient:
status: In Progress → Fix Committed
Changed in python-glanceclient:
status: Fix Committed → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote :

I think in this case the behavior of the encoder is correct and the caller needs to clean the data before passing it in.

Changed in oslo.utils:
status: New → Won't Fix
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.