summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-01-15 05:27:20 +0000
committerGerrit Code Review <review@openstack.org>2016-01-15 05:27:21 +0000
commit0b7a6d2379981c1c0e08797ab44aa7272590d340 (patch)
tree212c7f9ff5a045fdca3524acca0f8b088e55be83
parent2db882c41cef8f26a6e788163027df34513a6bd6 (diff)
parentcea67763c9f8037f47844e3e057166d6874d801d (diff)
downloadpython-glanceclient-0b7a6d2379981c1c0e08797ab44aa7272590d340.tar.gz
Merge "Remove location check from V2 client"
-rw-r--r--glanceclient/tests/unit/v2/test_images.py21
-rw-r--r--glanceclient/v2/images.py6
2 files changed, 8 insertions, 19 deletions
diff --git a/glanceclient/tests/unit/v2/test_images.py b/glanceclient/tests/unit/v2/test_images.py
index ca64e55..8ed1bb3 100644
--- a/glanceclient/tests/unit/v2/test_images.py
+++ b/glanceclient/tests/unit/v2/test_images.py
@@ -1014,18 +1014,14 @@ class TestController(testtools.TestCase):
def test_location_ops_when_server_disabled_location_ops(self):
# Location operations should not be allowed if server has not
- # enabled location related operations
+ # enabled location related operations. There is no need to check it
+ # when do location add, because the check would be done in server side.
image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
estr = 'The administrator has disabled API access to image locations'
url = 'http://bar.com/'
meta = {'bar': 'barmeta'}
e = self.assertRaises(exc.HTTPBadRequest,
- self.controller.add_location,
- image_id, url, meta)
- self.assertIn(estr, str(e))
-
- e = self.assertRaises(exc.HTTPBadRequest,
self.controller.delete_locations,
image_id, set([url]))
self.assertIn(estr, str(e))
@@ -1052,20 +1048,19 @@ class TestController(testtools.TestCase):
add_patch = {'path': '/locations/-', 'value': new_loc, 'op': 'add'}
self.controller.add_location(image_id, **new_loc)
self.assertEqual(self.api.calls, [
- self._empty_get(image_id),
self._patch_req(image_id, [add_patch]),
self._empty_get(image_id)
])
- def test_add_duplicate_location(self):
+ @mock.patch.object(images.Controller, '_send_image_update_request',
+ side_effect=exc.HTTPBadRequest)
+ def test_add_duplicate_location(self, mock_request):
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
new_loc = {'url': 'http://foo.com/', 'metadata': {'foo': 'newfoo'}}
- err_str = 'A location entry at %s already exists' % new_loc['url']
- err = self.assertRaises(exc.HTTPConflict,
- self.controller.add_location,
- image_id, **new_loc)
- self.assertIn(err_str, str(err))
+ self.assertRaises(exc.HTTPBadRequest,
+ self.controller.add_location,
+ image_id, **new_loc)
def test_remove_location(self):
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py
index 5aa3e76..0dd9c0d 100644
--- a/glanceclient/v2/images.py
+++ b/glanceclient/v2/images.py
@@ -306,12 +306,6 @@ class Controller(object):
:param metadata: Metadata associated with the location.
:returns: The updated image
"""
- image = self._get_image_with_locations_or_fail(image_id)
- url_list = [l['url'] for l in image.locations]
- if url in url_list:
- err_str = 'A location entry at %s already exists' % url
- raise exc.HTTPConflict(err_str)
-
add_patch = [{'op': 'add', 'path': '/locations/-',
'value': {'url': url, 'metadata': metadata}}]
self._send_image_update_request(image_id, add_patch)