Merge "Embed validation data when adding location"
This commit is contained in:
commit
8b9dc5635e
@ -1518,18 +1518,25 @@ class ShellV2Test(testtools.TestCase):
|
|||||||
|
|
||||||
def test_do_location_add(self):
|
def test_do_location_add(self):
|
||||||
gc = self.gc
|
gc = self.gc
|
||||||
loc = {'url': 'http://foo.com/', 'metadata': {'foo': 'bar'}}
|
loc = {'url': 'http://foo.com/',
|
||||||
args = self._make_args({'id': 'pass',
|
'metadata': {'foo': 'bar'},
|
||||||
'url': loc['url'],
|
'validation_data': {'checksum': 'csum',
|
||||||
'metadata': json.dumps(loc['metadata'])})
|
'os_hash_algo': 'algo',
|
||||||
|
'os_hash_value': 'value'}}
|
||||||
|
args = {'id': 'pass',
|
||||||
|
'url': loc['url'],
|
||||||
|
'metadata': json.dumps(loc['metadata']),
|
||||||
|
'checksum': 'csum',
|
||||||
|
'hash_algo': 'algo',
|
||||||
|
'hash_value': 'value'}
|
||||||
with mock.patch.object(gc.images, 'add_location') as mocked_addloc:
|
with mock.patch.object(gc.images, 'add_location') as mocked_addloc:
|
||||||
expect_image = {'id': 'pass', 'locations': [loc]}
|
expect_image = {'id': 'pass', 'locations': [loc]}
|
||||||
mocked_addloc.return_value = expect_image
|
mocked_addloc.return_value = expect_image
|
||||||
|
|
||||||
test_shell.do_location_add(self.gc, args)
|
test_shell.do_location_add(self.gc, self._make_args(args))
|
||||||
mocked_addloc.assert_called_once_with('pass',
|
mocked_addloc.assert_called_once_with(
|
||||||
loc['url'],
|
'pass', loc['url'], loc['metadata'],
|
||||||
loc['metadata'])
|
validation_data=loc['validation_data'])
|
||||||
utils.print_dict.assert_called_once_with(expect_image)
|
utils.print_dict.assert_called_once_with(expect_image)
|
||||||
|
|
||||||
def test_do_location_delete(self):
|
def test_do_location_delete(self):
|
||||||
|
@ -432,7 +432,7 @@ class Controller(object):
|
|||||||
data=json.dumps(patch_body))
|
data=json.dumps(patch_body))
|
||||||
return (resp, body), resp
|
return (resp, body), resp
|
||||||
|
|
||||||
def add_location(self, image_id, url, metadata):
|
def add_location(self, image_id, url, metadata, validation_data=None):
|
||||||
"""Add a new location entry to an image's list of locations.
|
"""Add a new location entry to an image's list of locations.
|
||||||
|
|
||||||
It is an error to add a URL that is already present in the list of
|
It is an error to add a URL that is already present in the list of
|
||||||
@ -441,10 +441,13 @@ class Controller(object):
|
|||||||
:param image_id: ID of image to which the location is to be added.
|
:param image_id: ID of image to which the location is to be added.
|
||||||
:param url: URL of the location to add.
|
:param url: URL of the location to add.
|
||||||
:param metadata: Metadata associated with the location.
|
:param metadata: Metadata associated with the location.
|
||||||
|
:param validation_data: Validation data for the image.
|
||||||
:returns: The updated image
|
:returns: The updated image
|
||||||
"""
|
"""
|
||||||
add_patch = [{'op': 'add', 'path': '/locations/-',
|
add_patch = [{'op': 'add', 'path': '/locations/-',
|
||||||
'value': {'url': url, 'metadata': metadata}}]
|
'value': {'url': url, 'metadata': metadata}}]
|
||||||
|
if validation_data:
|
||||||
|
add_patch[0]['value']['validation_data'] = validation_data
|
||||||
response = self._send_image_update_request(image_id, add_patch)
|
response = self._send_image_update_request(image_id, add_patch)
|
||||||
# Get request id from the above update request and pass the same to
|
# Get request id from the above update request and pass the same to
|
||||||
# following get request
|
# following get request
|
||||||
|
@ -750,16 +750,30 @@ def do_image_tag_delete(gc, args):
|
|||||||
@utils.arg('--metadata', metavar='<STRING>', default='{}',
|
@utils.arg('--metadata', metavar='<STRING>', default='{}',
|
||||||
help=_('Metadata associated with the location. '
|
help=_('Metadata associated with the location. '
|
||||||
'Must be a valid JSON object (default: %(default)s)'))
|
'Must be a valid JSON object (default: %(default)s)'))
|
||||||
|
@utils.arg('--checksum', metavar='<STRING>',
|
||||||
|
help=_('md5 checksum of image contents'))
|
||||||
|
@utils.arg('--hash-algo', metavar='<STRING>',
|
||||||
|
help=_('Multihash algorithm'))
|
||||||
|
@utils.arg('--hash-value', metavar='<STRING>',
|
||||||
|
help=_('Multihash value'))
|
||||||
@utils.arg('id', metavar='<IMAGE_ID>',
|
@utils.arg('id', metavar='<IMAGE_ID>',
|
||||||
help=_('ID of image to which the location is to be added.'))
|
help=_('ID of image to which the location is to be added.'))
|
||||||
def do_location_add(gc, args):
|
def do_location_add(gc, args):
|
||||||
"""Add a location (and related metadata) to an image."""
|
"""Add a location (and related metadata) to an image."""
|
||||||
|
validation_data = {}
|
||||||
|
if args.checksum:
|
||||||
|
validation_data['checksum'] = args.checksum
|
||||||
|
if args.hash_algo:
|
||||||
|
validation_data['os_hash_algo'] = args.hash_algo
|
||||||
|
if args.hash_value:
|
||||||
|
validation_data['os_hash_value'] = args.hash_value
|
||||||
try:
|
try:
|
||||||
metadata = json.loads(args.metadata)
|
metadata = json.loads(args.metadata)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
utils.exit('Metadata is not a valid JSON object.')
|
utils.exit('Metadata is not a valid JSON object.')
|
||||||
else:
|
else:
|
||||||
image = gc.images.add_location(args.id, args.url, metadata)
|
image = gc.images.add_location(args.id, args.url, metadata,
|
||||||
|
validation_data=validation_data)
|
||||||
utils.print_dict(image)
|
utils.print_dict(image)
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Support for embedding validation data (checksum and multihash) when adding
|
||||||
|
a location to an image. Requires the Stein release server-side.
|
||||||
|
|
||||||
|
The ``glance.images.add_location()`` method now accepts an optional
|
||||||
|
argument ``validation_data``, in the form of a dictionary containing
|
||||||
|
``checksum``, ``os_hash_algo`` and ``os_hash_value``.
|
||||||
|
|
||||||
|
The ``location-add`` command now accepts optional arguments ``--checksum``,
|
||||||
|
``--hash-algo`` and ``--hash-value``.
|
Loading…
Reference in New Issue
Block a user