Merge "Implements hide image"
This commit is contained in:
commit
930ca85dcf
@ -615,6 +615,12 @@ class ListImage(command.Lister):
|
||||
default=None,
|
||||
help=_('Filter images based on tag.'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--hidden',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_('List hidden images'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
action='store_true',
|
||||
@ -686,6 +692,8 @@ class ListImage(command.Lister):
|
||||
parsed_args.project_domain,
|
||||
).id
|
||||
kwargs['owner'] = project_id
|
||||
if parsed_args.hidden:
|
||||
kwargs['is_hidden'] = True
|
||||
if parsed_args.long:
|
||||
columns = (
|
||||
'ID',
|
||||
@ -1016,6 +1024,22 @@ class SetImage(command.Command):
|
||||
action="store_true",
|
||||
help=_("Reset the image membership to 'pending'"),
|
||||
)
|
||||
|
||||
hidden_group = parser.add_mutually_exclusive_group()
|
||||
hidden_group.add_argument(
|
||||
"--hidden",
|
||||
dest='hidden',
|
||||
default=None,
|
||||
action="store_true",
|
||||
help=_("Hide the image"),
|
||||
)
|
||||
hidden_group.add_argument(
|
||||
"--unhidden",
|
||||
dest='hidden',
|
||||
default=None,
|
||||
action="store_false",
|
||||
help=_("Unhide the image"),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -1106,6 +1130,9 @@ class SetImage(command.Command):
|
||||
# Tags should be extended, but duplicates removed
|
||||
kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags)))
|
||||
|
||||
if parsed_args.hidden is not None:
|
||||
kwargs['is_hidden'] = parsed_args.hidden
|
||||
|
||||
try:
|
||||
image = image_client.update_image(image.id, **kwargs)
|
||||
except Exception:
|
||||
|
@ -837,6 +837,20 @@ class TestImageList(TestImage):
|
||||
status='active'
|
||||
)
|
||||
|
||||
def test_image_list_hidden_option(self):
|
||||
arglist = [
|
||||
'--hidden',
|
||||
]
|
||||
verifylist = [
|
||||
('hidden', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.client.images.assert_called_with(
|
||||
is_hidden=True
|
||||
)
|
||||
|
||||
def test_image_list_tag_option(self):
|
||||
arglist = [
|
||||
'--tag', 'abc',
|
||||
@ -1439,6 +1453,60 @@ class TestImageSet(TestImage):
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_image_set_hidden(self):
|
||||
arglist = [
|
||||
'--hidden',
|
||||
'--public',
|
||||
image_fakes.image_name,
|
||||
]
|
||||
verifylist = [
|
||||
('hidden', True),
|
||||
('public', True),
|
||||
('private', False),
|
||||
('image', image_fakes.image_name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
kwargs = {
|
||||
'is_hidden': True,
|
||||
'visibility': 'public',
|
||||
}
|
||||
# ImageManager.update(image, **kwargs)
|
||||
self.client.update_image.assert_called_with(
|
||||
self._image.id,
|
||||
**kwargs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_image_set_unhidden(self):
|
||||
arglist = [
|
||||
'--unhidden',
|
||||
'--public',
|
||||
image_fakes.image_name,
|
||||
]
|
||||
verifylist = [
|
||||
('hidden', False),
|
||||
('public', True),
|
||||
('private', False),
|
||||
('image', image_fakes.image_name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
kwargs = {
|
||||
'is_hidden': False,
|
||||
'visibility': 'public',
|
||||
}
|
||||
# ImageManager.update(image, **kwargs)
|
||||
self.client.update_image.assert_called_with(
|
||||
self._image.id,
|
||||
**kwargs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestImageShow(TestImage):
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add mutually exclusive options ``--hidden`` and ``--unhidden`` to
|
||||
``image set`` command to hide or unhide an image (``is_hidden``
|
||||
attribute).
|
||||
- |
|
||||
Add option ``--hidden`` to ``image list`` command to list hidden images.
|
Loading…
x
Reference in New Issue
Block a user