Skip to content

Commit ae7e844

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "image: Add hashing-related fields"
2 parents 81db99b + a736984 commit ae7e844

File tree

4 files changed

+64
-21
lines changed

4 files changed

+64
-21
lines changed

openstackclient/image/v2/image.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def _format_image(image, human_readable=False):
9898
'virtual_size',
9999
'min_ram',
100100
'schema',
101+
'is_hidden',
102+
'hash_algo',
103+
'hash_value',
101104
]
102105

103106
# TODO(gtema/anybody): actually it should be possible to drop this method,
@@ -903,6 +906,8 @@ def take_action(self, parsed_args):
903906
'visibility',
904907
'is_protected',
905908
'owner_id',
909+
'hash_algo',
910+
'hash_value',
906911
'tags',
907912
)
908913
column_headers: tuple[str, ...] = (
@@ -916,6 +921,8 @@ def take_action(self, parsed_args):
916921
'Visibility',
917922
'Protected',
918923
'Project',
924+
'Hash Algorithm',
925+
'Hash Value',
919926
'Tags',
920927
)
921928
else:

openstackclient/tests/functional/image/v2/test_image.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,39 @@ def test_image_members(self):
218218
'image remove project ' + self.name + ' ' + my_project_id
219219
)
220220

221-
# else:
222-
# # Test not shared
223-
# self.assertRaises(
224-
# image_exceptions.HTTPForbidden,
225-
# self.openstack,
226-
# 'image add project ' +
227-
# self.name + ' ' +
228-
# my_project_id
229-
# )
230-
# self.openstack(
231-
# 'image set ' +
232-
# '--share ' +
233-
# self.name
234-
# )
221+
def test_image_hidden(self):
222+
# Test image is shown in list
223+
output = self.openstack(
224+
'image list',
225+
parse_output=True,
226+
)
227+
self.assertIn(
228+
self.name,
229+
[img['Name'] for img in output],
230+
)
231+
232+
# Hide the image and test image not show in the list
233+
self.openstack('image set ' + '--hidden ' + self.name)
234+
output = self.openstack(
235+
'image list',
236+
parse_output=True,
237+
)
238+
self.assertNotIn(self.name, [img['Name'] for img in output])
239+
240+
# Test image show in the list with flag
241+
output = self.openstack(
242+
'image list',
243+
parse_output=True,
244+
)
245+
self.assertNotIn(self.name, [img['Name'] for img in output])
246+
247+
# Unhide the image and test image is again visible in regular list
248+
self.openstack('image set ' + '--unhidden ' + self.name)
249+
output = self.openstack(
250+
'image list',
251+
parse_output=True,
252+
)
253+
self.assertIn(
254+
self.name,
255+
[img['Name'] for img in output],
256+
)

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,8 @@ def test_image_list_long_option(self):
822822
'Visibility',
823823
'Protected',
824824
'Project',
825+
'Hash Algorithm',
826+
'Hash Value',
825827
'Tags',
826828
)
827829

@@ -830,14 +832,16 @@ def test_image_list_long_option(self):
830832
(
831833
self._image.id,
832834
self._image.name,
833-
None,
834-
None,
835-
None,
836-
None,
837-
None,
835+
self._image.disk_format,
836+
self._image.container_format,
837+
self._image.size,
838+
self._image.checksum,
839+
self._image.status,
838840
self._image.visibility,
839841
self._image.is_protected,
840842
self._image.owner_id,
843+
self._image.hash_algo,
844+
self._image.hash_value,
841845
format_columns.ListColumn(self._image.tags),
842846
),
843847
)
@@ -1356,15 +1360,17 @@ def test_image_set_with_unexist_project(self):
13561360
exceptions.CommandError, self.cmd.take_action, parsed_args
13571361
)
13581362

1359-
def test_image_set_bools1(self):
1363+
def test_image_set_bools_true(self):
13601364
arglist = [
13611365
'--protected',
13621366
'--private',
1367+
'--hidden',
13631368
'graven',
13641369
]
13651370
verifylist = [
13661371
('is_protected', True),
13671372
('visibility', 'private'),
1373+
('is_hidden', True),
13681374
('image', 'graven'),
13691375
]
13701376
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -1374,22 +1380,25 @@ def test_image_set_bools1(self):
13741380
kwargs = {
13751381
'is_protected': True,
13761382
'visibility': 'private',
1383+
'is_hidden': True,
13771384
}
13781385
# ImageManager.update(image, **kwargs)
13791386
self.image_client.update_image.assert_called_with(
13801387
self._image.id, **kwargs
13811388
)
13821389
self.assertIsNone(result)
13831390

1384-
def test_image_set_bools2(self):
1391+
def test_image_set_bools_false(self):
13851392
arglist = [
13861393
'--unprotected',
13871394
'--public',
1395+
'--unhidden',
13881396
'graven',
13891397
]
13901398
verifylist = [
13911399
('is_protected', False),
13921400
('visibility', 'public'),
1401+
('is_hidden', False),
13931402
('image', 'graven'),
13941403
]
13951404
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -1399,6 +1408,7 @@ def test_image_set_bools2(self):
13991408
kwargs = {
14001409
'is_protected': False,
14011410
'visibility': 'public',
1411+
'is_hidden': False,
14021412
}
14031413
# ImageManager.update(image, **kwargs)
14041414
self.image_client.update_image.assert_called_with(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- The ``os_hash_algo`` and ``os_hash_value image`` attributes are now shown
4+
in the ``image list --long`` output.

0 commit comments

Comments
 (0)