diff options
author | Rajesh Tailor <rajesh.tailor@nttdata.com> | 2014-09-26 07:59:40 -0700 |
---|---|---|
committer | Nikhil Komawar <nikhilskomawar@gmail.com> | 2014-10-09 09:41:53 -0400 |
commit | ad34b836fb6d8e2ba067e8c14512abc4ec0b4969 (patch) | |
tree | 137527b6f9422b38772142f40d6b30c42712c3e3 | |
parent | 9eff67b8fff812acdbf787f2dc119761f3cf3153 (diff) | |
download | glance-ad34b836fb6d8e2ba067e8c14512abc4ec0b4969.tar.gz |
Fix for Adopt glance.store library in Glance
The store module is removed from glance project and new glance_store
module is created, but the glance project code was not updated
properly for the required changes.
The exception (UnknownScheme) was moved to glance_store, but in
glance image-create api (v1), it still refers to
exception.UnknownScheme in get_store_or_400 method.
Change-Id: I09e78b92d2d44a659412361b4f03b4a988714bf5
Closes-Bug: 1373454
-rw-r--r-- | glance/api/v1/images.py | 4 | ||||
-rw-r--r-- | glance/tests/unit/v1/test_api.py | 34 |
2 files changed, 36 insertions, 2 deletions
diff --git a/glance/api/v1/images.py b/glance/api/v1/images.py index 7ec3bfc59..ea511fd4b 100644 --- a/glance/api/v1/images.py +++ b/glance/api/v1/images.py @@ -1091,11 +1091,11 @@ class Controller(controller.BaseController): :param request: The WSGI/Webob Request object :param scheme: The backend store scheme - :raises HTTPNotFound if store does not exist + :raises HTTPBadRequest if store does not exist """ try: return store.get_store_from_scheme(scheme) - except exception.UnknownScheme: + except store.UnknownScheme: msg = "Store for scheme %s not found" % scheme LOG.debug(msg) raise HTTPBadRequest(explanation=msg, diff --git a/glance/tests/unit/v1/test_api.py b/glance/tests/unit/v1/test_api.py index f5c59a1fc..d5a47ec36 100644 --- a/glance/tests/unit/v1/test_api.py +++ b/glance/tests/unit/v1/test_api.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +import contextlib import copy import datetime import hashlib @@ -370,6 +371,39 @@ class TestGlanceAPI(base.IsolatedUnitTest): self.assertEqual(res.status_int, 400) self.assertIn('Required store bad is invalid', res.body) + def test_create_with_location_get_store_or_400_raises_exception(self): + location = 'bad+scheme://localhost:0/image.qcow2' + scheme = 'bad+scheme' + fixture_headers = { + 'x-image-meta-name': 'bogus', + 'x-image-meta-location': location, + 'x-image-meta-disk-format': 'qcow2', + 'x-image-meta-container-format': 'bare', + } + + req = webob.Request.blank("/images") + req.method = 'POST' + for k, v in six.iteritems(fixture_headers): + req.headers[k] = v + + ctlr = glance.api.v1.images.Controller + + with contextlib.nested( + mock.patch.object(ctlr, '_external_source', + return_value=location), + mock.patch.object(store, + 'get_store_from_location', + return_value=scheme) + ) as ( + mock_external_source, + mock_get_store_from_location + ): + res = req.get_response(self.api) + self.assertEqual(400, res.status_int) + self.assertEqual(1, mock_external_source.call_count) + self.assertEqual(1, mock_get_store_from_location.call_count) + self.assertIn('Store for scheme %s not found' % scheme, res.body) + def test_create_with_location_unknown_scheme(self): fixture_headers = { 'x-image-meta-store': 'bad', |