Incorrect use of os.path.join() in nova/api/openstack/common.py

Bug #1489627 reported by Ed Leafe
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Undecided
Ed Leafe

Bug Description

Three of the link manipulation methods in nova/api/openstack/common.py rejoin the URL parts by using os.path.join(). This is incorrect, as it is OS-dependent, and can result in invalid URLs under Windows. Generally the urlparse module would be the best choice, but since these URL fragments aren't created with urlparse.urlparse() or urlparse.urlsplit(), the equivalent reconstruction methods in that module won't work. It is simpler and cleaner to just use "/".join().

Additionally, there are no unit tests for these methods, so tests will have to be added first before we can fix the methods, so that we have some assurance that we are not breaking anything.

Ed Leafe (ed-leafe)
Changed in nova:
assignee: nobody → Ed Leafe (ed-leafe)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

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

Changed in nova:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

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

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

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

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

Reviewed: https://review.openstack.org/218307
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=6b4e210c643d917d300252fa78474058a393e012
Submitter: Jenkins
Branch: master

commit 6b4e210c643d917d300252fa78474058a393e012
Author: EdLeafe <email address hidden>
Date: Thu Aug 27 21:39:21 2015 +0000

    Adds unit tests to test_common.py

    The test coverage of nova/api/openstack/common.py skipped several
    methods involving link manipulation. This patch adds more tests to
    better cover the code.

    Partial-Bug: 1489627
    Change-Id: Ie73a391ba2f3bc10bb5d89761ebba9e1b23018dc

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

Reviewed: https://review.openstack.org/218308
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=d9bfe041fb4cd79c87fc40578561ebc792c47aaf
Submitter: Jenkins
Branch: master

commit d9bfe041fb4cd79c87fc40578561ebc792c47aaf
Author: EdLeafe <email address hidden>
Date: Thu Aug 27 21:50:52 2015 +0000

    Rename tests so that they are run

    Several tests in test_common.py weren't given names starting with
    'test_', so testr won't find them. This patch simply adds the 'test_'
    prefix to these tests.

    Partial-Bug: 1489627
    Change-Id: I2eec1da9c39da82252521c2b2bca8a3b6c3c15d6

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

Reviewed: https://review.openstack.org/218309
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=7a09f727f3027e4f0d54d99f1579f6595720d094
Submitter: Jenkins
Branch: master

commit 7a09f727f3027e4f0d54d99f1579f6595720d094
Author: EdLeafe <email address hidden>
Date: Thu Aug 27 21:54:12 2015 +0000

    Replace os.path.join() for URLs

    Since os.path.join() is OS-dependent, it should not be used for creating
    URLs. This patch replaces the use of os.path.join() in
    nova/api/openstack with common.url_join(), which uses the more correct
    "/".join(), while preserving the behavior of removing duplicate slashes
    inside the URL and adding a trailing slash with an empty final element.
    It also adds some tests to ensure that the generate_href() method in
    nova/api/openstack/compute/views/versions.py works after the refactoring
    to use common.url_join()

    Closes-Bug: 1489627
    Change-Id: I32948dd1fcf0839b34e446d9e4b08f9c39d17c8f

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
Thierry Carrez (ttx) wrote : Fix included in openstack/nova 13.0.0.0b2

This issue was fixed in the openstack/nova 13.0.0.0b2 development milestone.

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.