From 8b6dbb2065c5e12d150f15572df3dc0e269e7a81 Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Mon, 15 Feb 2016 16:39:03 +1300 Subject: [PATCH] Fix location update After commit Ieb03aaba887492819f9c58aa67f7acfcea81720e, the command location-update is totally broken now. This patch removes the updating for an image from non-empty to empty since it's not supported now. And also removing the default value of metadata for location-update cli command because now the only purpose of location-update is updating the location's metadata, so it doesn't make sense to give it a default value which may update existing metadata by mistake. Closes-Bug: #1537626 Change-Id: I9ce98e6c63996bbfdbc56761055e37a871f9d3e2 --- glanceclient/tests/unit/v2/test_images.py | 2 -- glanceclient/v2/images.py | 11 ++++------- glanceclient/v2/shell.py | 4 ++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/glanceclient/tests/unit/v2/test_images.py b/glanceclient/tests/unit/v2/test_images.py index 8ed1bb30..8a2c78d5 100644 --- a/glanceclient/tests/unit/v2/test_images.py +++ b/glanceclient/tests/unit/v2/test_images.py @@ -1091,8 +1091,6 @@ class TestController(testtools.TestCase): loc_map = dict([(l['url'], l) for l in orig_locations]) loc_map[new_loc['url']] = new_loc mod_patch = [{'path': '/locations', 'op': 'replace', - 'value': []}, - {'path': '/locations', 'op': 'replace', 'value': list(loc_map.values())}] self.controller.update_location(image_id, **new_loc) self.assertEqual(self.api.calls, [ diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index ed6a001d..2f2527c7 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -348,20 +348,17 @@ class Controller(object): image = self._get_image_with_locations_or_fail(image_id) url_map = dict([(l['url'], l) for l in image.locations]) if url not in url_map: - raise exc.HTTPNotFound('Unknown URL: %s' % url) + raise exc.HTTPNotFound('Unknown URL: %s, the URL must be one of' + ' existing locations of current image' % + url) if url_map[url]['metadata'] == metadata: return image - # NOTE: The server (as of now) doesn't support modifying individual - # location entries. So we must: - # 1. Empty existing list of locations. - # 2. Send another request to set 'locations' to the new list - # of locations. url_map[url]['metadata'] = metadata patches = [{'op': 'replace', 'path': '/locations', - 'value': p} for p in ([], list(url_map.values()))] + 'value': list(url_map.values())}] self._send_image_update_request(image_id, patches) return self.get(image_id) diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 821febf5..3250c508 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -421,6 +421,10 @@ def do_location_update(gc, args): """Update metadata of an image's location.""" try: metadata = json.loads(args.metadata) + + if metadata == {}: + print("WARNING -- The location's metadata will be updated to " + "an empty JSON object.") except ValueError: utils.exit('Metadata is not a valid JSON object.') else: