diff --git a/glance/registry/db/models.py b/glance/registry/db/models.py index df83af80de..fc256b7f48 100644 --- a/glance/registry/db/models.py +++ b/glance/registry/db/models.py @@ -103,7 +103,7 @@ class Image(BASE, ModelBase): @validates('type') def validate_type(self, key, type): - if not type in ('machine', 'kernel', 'ramdisk', 'raw'): + if not type in ('machine', 'kernel', 'ramdisk', 'raw', 'vhd'): raise exception.Invalid( "Invalid image type '%s' for image." % type) return type diff --git a/glance/server.py b/glance/server.py index ecc6fe2b20..3b3b99e57f 100644 --- a/glance/server.py +++ b/glance/server.py @@ -341,7 +341,13 @@ def create(self, req): location = req.headers['x-image-meta-location'] self._activate(req, image_meta, location) - return dict(image=image_meta) + # APP states we should return a Location: header with the edit + # URI of the resource newly-created. + res = Response(request=req, body=json.dumps(dict(image=image_meta)), + content_type="text/plain") + res.headers.add('Location', "/images/%s" % image_meta['id']) + + return req.get_response(res) def update(self, req, id): """ diff --git a/tests/unit/test_api.py b/tests/unit/test_api.py index 857b72a0d5..51c7309fdd 100644 --- a/tests/unit/test_api.py +++ b/tests/unit/test_api.py @@ -288,6 +288,14 @@ def test_add_image_basic_file_store(self): self.assertEquals(res_body['location'], 'file:///tmp/glance-tests/3') + # Test that the Location: header is set to the URI to + # edit the newly-created image, as required by APP. + # See LP Bug #719825 + self.assertTrue('location' in res.headers, + "'location' not in response headers.\n" + "res.headerlist = %r" % res.headerlist) + self.assertTrue('/images/3' in res.headers['location']) + def test_image_meta(self): """Test for HEAD /images/""" expected_headers = {'x-image-meta-id': 2,