Merge "Fix for Adopt glance.store library in Glance"
This commit is contained in:
commit
639e7e1688
@ -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,
|
||||
|
@ -15,6 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import contextlib
|
||||
import copy
|
||||
import datetime
|
||||
import hashlib
|
||||
@ -369,6 +370,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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user