keystoneauth raises error when application name is empty string

Bug #1611426 reported by Matt Mulsow
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
keystoneauth
Fix Released
High
Matt Mulsow

Bug Description

If the application name, sys.argv[0], is an empty string, like when called from the Ansible os_network module, then keystoneauth (with the new requests 2.11.0) will raise an exception saying:

Invalid return character or leading space in header: User-Agent

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to keystoneauth (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/352985

Changed in keystoneauth:
assignee: nobody → Matt Mulsow (mamulsow)
status: New → In Progress
Changed in keystoneauth:
assignee: Matt Mulsow (mamulsow) → Brant Knudson (blk-u)
Brant Knudson (blk-u)
Changed in keystoneauth:
assignee: Brant Knudson (blk-u) → Matt Mulsow (mamulsow)
importance: Undecided → Critical
importance: Critical → High
Revision history for this message
Brant Knudson (blk-u) wrote :

I opened a bug against the requests library to check if this change in behavior is intentional. Was closed saying working as designed: https://github.com/kennethreitz/requests/issues/3488

Revision history for this message
Brant Knudson (blk-u) wrote :

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(repr(sys.argv[0]))
''

Revision history for this message
Sean Perry (sean-perry-a) wrote :

Fun. This is on me. I made the code in question.

I have been working on a different design based on jamie lennox's feedback but it is not quite ready yet.

Revision history for this message
Sean Perry (sean-perry-a) wrote :

The long term goal is to require the user of keystoneauth to provide a name so this heuristic code can be removed.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to keystoneauth (master)

Reviewed: https://review.openstack.org/352985
Committed: https://git.openstack.org/cgit/openstack/keystoneauth/commit/?id=c9ae7067bdc41bdc3ac757a3412d1e17f6c1796a
Submitter: Jenkins
Branch: master

commit c9ae7067bdc41bdc3ac757a3412d1e17f6c1796a
Author: Brant Knudson <email address hidden>
Date: Tue Aug 9 10:43:16 2016 -0500

    Add tests for user-agent with odd sys.argv

    There was no test that verified that when sys.argv is an empty
    list or when sys.argv[0] is an empty string that the default
    user-agent value is constructed as expected.

    Change-Id: Iacf1557b6dbf48bf6bfb59d7cfbfec14e4fa8e56
    Related-Bug: 1611426

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

Reviewed: https://review.openstack.org/352673
Committed: https://git.openstack.org/cgit/openstack/keystoneauth/commit/?id=4a0ac4583b5e896d5b1af033ca2347f9fcc9daab
Submitter: Jenkins
Branch: master

commit 4a0ac4583b5e896d5b1af033ca2347f9fcc9daab
Author: Matt Mulsow <email address hidden>
Date: Mon Aug 8 21:26:01 2016 -0500

    User-agent header shouldn't start with a space

    If the application name, sys.argv[0], is an empty string, like when
    called from the Ansible os_network module, then keystoneauth (with
    the new requests 2.11.0) will raise an exception saying:

    Invalid return character or leading space in header: User-Agent

    This comes from keystoneauth trying to prepend the empty module
    name to the default user agent, which leads to it sending a
    User-Agent header that starts with a blank space. This was fine
    until the new requests 2.11.0 was released which errors if header
    values start with a leading space.

    With this change, if sys.argv[0] is an empty string we'll just use
    the DEFAULT_USER_AGENT and not try to prepend a calling module.

    Closes-Bug: #1611426

    Change-Id: I56d3e352dce7628add0479b3333a880700844ebc
    Signed-off-by: Matt Mulsow <email address hidden>

Changed in keystoneauth:
status: In Progress → Fix Released
Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote : Fix included in openstack/keystoneauth 2.11.1

This issue was fixed in the openstack/keystoneauth 2.11.1 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.