summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-24 21:34:18 +0000
committerGerrit Code Review <review@openstack.org>2018-07-24 21:34:18 +0000
commita97d4194efb764696c3932f1758268bee1bbf4a4 (patch)
treef035f243e73ef8fb1054d618e9b04311804cb5fb
parentc159b5ccbc6f4d98f94cd96ad200ac317a8269ad (diff)
parent1f1a8176cec9f21faf7a3184798ba749b3dfbebf (diff)
downloadpython-glanceclient-a97d4194efb764696c3932f1758268bee1bbf4a4.tar.gz
Merge "Add support for multihash"
-rw-r--r--glanceclient/tests/unit/v2/test_shell_v2.py76
-rw-r--r--glanceclient/v2/image_schema.py13
-rw-r--r--glanceclient/v2/shell.py9
3 files changed, 95 insertions, 3 deletions
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py
index f2f30e0..535d006 100644
--- a/glanceclient/tests/unit/v2/test_shell_v2.py
+++ b/glanceclient/tests/unit/v2/test_shell_v2.py
@@ -400,6 +400,82 @@ class ShellV2Test(testtools.TestCase):
'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd',
'container_format': 'bare'})
+ @mock.patch('sys.stdin', autospec=True)
+ def test_do_image_create_for_none_multi_hash(self, mock_stdin):
+ args = self._make_args({'name': 'IMG-01', 'disk_format': 'vhd',
+ 'container_format': 'bare',
+ 'file': None})
+ with mock.patch.object(self.gc.images, 'create') as mocked_create:
+ ignore_fields = ['self', 'access', 'file', 'schema']
+ expect_image = dict([(field, field) for field in ignore_fields])
+ expect_image['id'] = 'pass'
+ expect_image['name'] = 'IMG-01'
+ expect_image['disk_format'] = 'vhd'
+ expect_image['container_format'] = 'bare'
+ expect_image['os_hash_algo'] = None
+ expect_image['os_hash_value'] = None
+ mocked_create.return_value = expect_image
+
+ # Ensure that the test stdin is not considered
+ # to be supplying image data
+ mock_stdin.isatty = lambda: True
+ test_shell.do_image_create(self.gc, args)
+
+ mocked_create.assert_called_once_with(name='IMG-01',
+ disk_format='vhd',
+ container_format='bare')
+ utils.print_dict.assert_called_once_with({
+ 'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd',
+ 'container_format': 'bare', 'os_hash_algo': None,
+ 'os_hash_value': None})
+
+ def test_do_image_create_with_multihash(self):
+ self.mock_get_data_file.return_value = six.StringIO()
+ try:
+ with open(tempfile.mktemp(), 'w+') as f:
+ f.write('Some data here')
+ f.flush()
+ f.seek(0)
+ file_name = f.name
+ temp_args = {'name': 'IMG-01',
+ 'disk_format': 'vhd',
+ 'container_format': 'bare',
+ 'file': file_name,
+ 'progress': False}
+ args = self._make_args(temp_args)
+ with mock.patch.object(self.gc.images, 'create') as mocked_create:
+ with mock.patch.object(self.gc.images, 'get') as mocked_get:
+
+ ignore_fields = ['self', 'access', 'schema']
+ expect_image = dict([(field, field) for field in
+ ignore_fields])
+ expect_image['id'] = 'pass'
+ expect_image['name'] = 'IMG-01'
+ expect_image['disk_format'] = 'vhd'
+ expect_image['container_format'] = 'bare'
+ expect_image['checksum'] = 'fake-checksum'
+ expect_image['os_hash_algo'] = 'fake-hash_algo'
+ expect_image['os_hash_value'] = 'fake-hash_value'
+ mocked_create.return_value = expect_image
+ mocked_get.return_value = expect_image
+
+ test_shell.do_image_create(self.gc, args)
+
+ temp_args.pop('file', None)
+ mocked_create.assert_called_once_with(**temp_args)
+ mocked_get.assert_called_once_with('pass')
+ utils.print_dict.assert_called_once_with({
+ 'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd',
+ 'container_format': 'bare',
+ 'checksum': 'fake-checksum',
+ 'os_hash_algo': 'fake-hash_algo',
+ 'os_hash_value': 'fake-hash_value'})
+ finally:
+ try:
+ os.remove(f.name)
+ except Exception:
+ pass
+
def test_do_image_create_with_file(self):
self.mock_get_data_file.return_value = six.StringIO()
try:
diff --git a/glanceclient/v2/image_schema.py b/glanceclient/v2/image_schema.py
index 1ff20bc..247faf8 100644
--- a/glanceclient/v2/image_schema.py
+++ b/glanceclient/v2/image_schema.py
@@ -191,6 +191,19 @@ _BASE_SCHEMA = {
"description": "md5 hash of image contents.",
"maxLength": 32
},
+ "os_hash_algo": {
+ "readOnly": True,
+ "type": ["null", "string"],
+ "description": "Algorithm to calculate os_hash_value",
+ "maxLength": 32
+ },
+ "os_hash_value": {
+ "readOnly": True,
+ "type": ["null", "string"],
+ "description": "Hexdigest of the image contents using the "
+ "algorithm specified by the os_hash_algo",
+ "maxLength": 32
+ },
"created_at": {
"readOnly": True,
"type": "string",
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py
index 6771c96..c03648a 100644
--- a/glanceclient/v2/shell.py
+++ b/glanceclient/v2/shell.py
@@ -49,7 +49,8 @@ def get_image_schema():
@utils.schema_args(get_image_schema, omit=['created_at', 'updated_at', 'file',
'checksum', 'virtual_size', 'size',
'status', 'schema', 'direct_url',
- 'locations', 'self'])
+ 'locations', 'self',
+ 'os_hash_value', 'os_hash_algo'])
@utils.arg('--property', metavar="<key=value>", action='append',
default=[], help=_('Arbitrary property to associate with image.'
' May be used multiple times.'))
@@ -92,7 +93,8 @@ def do_image_create(gc, args):
@utils.schema_args(get_image_schema, omit=['created_at', 'updated_at', 'file',
'checksum', 'virtual_size', 'size',
'status', 'schema', 'direct_url',
- 'locations', 'self'])
+ 'locations', 'self',
+ 'os_hash_value', 'os_hash_algo'])
@utils.arg('--property', metavar="<key=value>", action='append',
default=[], help=_('Arbitrary property to associate with image.'
' May be used multiple times.'))
@@ -206,7 +208,8 @@ def do_image_create_via_import(gc, args):
'updated_at', 'file', 'checksum',
'virtual_size', 'size', 'status',
'schema', 'direct_url', 'tags',
- 'self'])
+ 'self', 'os_hash_value',
+ 'os_hash_algo'])
@utils.arg('--property', metavar="<key=value>", action='append',
default=[], help=_('Arbitrary property to associate with image.'
' May be used multiple times.'))