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
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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 = {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user