diff options
author | Andrew Laski <andrew.laski@rackspace.com> | 2014-03-26 15:11:18 -0400 |
---|---|---|
committer | Andrew Laski <andrew.laski@rackspace.com> | 2014-03-26 15:11:18 -0400 |
commit | 42edf020e263e0410a4f1db98db71658b801960a (patch) | |
tree | 6746cccadcb1ed40d6292314096bac87e0675758 /nova | |
parent | ec4d88c2985834b3c96b3e18381ae67f210390e8 (diff) | |
download | nova-42edf020e263e0410a4f1db98db71658b801960a.tar.gz |
Use osapi_glance_link_prefix for image location header
When an image is created the location header returned is generated based
on the request url that nova-api receives. If SSL termination happens
upstream the request url is an http request, and the location header is
wrongly generated with that. The osapi_glance_link_prefix config option
is available for almost precisely this purpose, so let's use it.
Change-Id: I24e46ed8fc0763f9ddeec65e0d79590dd7b86bef
Closes-bug: 1298005
Diffstat (limited to 'nova')
-rw-r--r-- | nova/api/openstack/compute/servers.py | 4 | ||||
-rw-r--r-- | nova/tests/api/openstack/compute/test_server_actions.py | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index c96b908190..52764e54cb 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -1466,7 +1466,9 @@ class Controller(wsgi.Controller): # build location of newly-created image entity image_id = str(image['id']) - image_ref = os.path.join(req.application_url, + url_prefix = self._view_builder._update_glance_link_prefix( + req.application_url) + image_ref = os.path.join(url_prefix, context.project_id, 'images', image_id) diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py index f26739ba55..3fedb1ef72 100644 --- a/nova/tests/api/openstack/compute/test_server_actions.py +++ b/nova/tests/api/openstack/compute/test_server_actions.py @@ -981,6 +981,20 @@ class ServerActionsControllerTest(test.TestCase): location = response.headers['Location'] self.assertEqual('http://localhost/v2/fake/images/123', location) + def test_create_image_glance_link_prefix(self): + self.flags(osapi_glance_link_prefix='https://glancehost') + body = { + 'createImage': { + 'name': 'Snapshot 1', + }, + } + + req = fakes.HTTPRequest.blank(self.url) + response = self.controller._action_create_image(req, FAKE_UUID, body) + + location = response.headers['Location'] + self.assertEqual('https://glancehost/v2/fake/images/123', location) + def test_create_image_name_too_long(self): long_name = 'a' * 260 body = { |