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
This commit is contained in:
committed by
Flavio Percoco
parent
c58b4cc984
commit
8b6dbb2065
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user