glanceclient/common/utils.py safe_header throws an exception on X-Auth-Token with None value

Bug #1491311 reported by David Edery
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Fix Released
High
David Edery

Bug Description

When using the glance-client with an internally generated admin context (e.g. using nova_context.get_admin_context) the log_curl_request fails due to safe_header trying to "value.encode('utf-8')" on a value that is None.

An example of a stack trace (coming from RH juno distro's nova.compute.manager but the potential problem exists in Kilo & Liberty):

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 364, in decorated_function
    *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 3021, in snapshot_instance
    task_states.IMAGE_SNAPSHOT)
  File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 3052, in _snapshot_instance
    update_task_state)
  File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 1701, in snapshot
    self._detach_sriov_ports(instance, virt_dom)
  File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 3239, in _detach_sriov_ports
    instance)
  File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 3189, in _prepare_args_for_get_config
    context, self._image_api, image_ref, instance)
  File "/usr/lib/python2.7/site-packages/nova/compute/utils.py", line 201, in get_image_metadata
    image = image_api.get(context, image_id_or_uri)
  File "/usr/lib/python2.7/site-packages/nova/image/api.py", line 89, in get
    include_locations=include_locations)
  File "/usr/lib/python2.7/site-packages/nova/image/glance.py", line 311, in show
    _reraise_translated_image_exception(image_id)
  File "/usr/lib/python2.7/site-packages/nova/image/glance.py", line 309, in show
    image = self._client.call(context, version, 'get', image_id)
  File "/usr/lib/python2.7/site-packages/nova/image/glance.py", line 232, in call
    return getattr(client.images, method)(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/glanceclient/v1/images.py", line 126, in get
    % urlparse.quote(str(image_id)))
  File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 250, in head
    return self._request('HEAD', url, **kwargs)
  File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 194, in _request
    self.log_curl_request(method, conn_url, headers, data, kwargs)
  File "/usr/lib/python2.7/site-packages/glanceclient/common/http.py", line 101, in log_curl_request
    header = '-H \'%s: %s\'' % safe_header(key, value)
  File "/usr/lib/python2.7/site-packages/glanceclient/common/utils.py", line 394, in safe_header
    v = value.encode('utf-8')
AttributeError: 'NoneType' object has no attribute 'encode'

Revision history for this message
David Edery (david-edery) wrote :

Adding a check for value is not None at the safe_header method solves the issue with no consequences on functionality (on the contrary, if anything, it causes the functionality to succeed due to no exception).

Changed in glance:
assignee: nobody → David Edery (david-edery)
Changed in neutron:
assignee: nobody → David Edery (david-edery)
no longer affects: neutron
Erno Kuvaja (jokke)
affects: glance → python-glanceclient
Changed in python-glanceclient:
status: New → Fix Committed
importance: Undecided → High
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.