Add ability to filter image list by tag
Change-Id: I2e222d3e69df9d8d7cd472663caaee31bedd848c
This commit is contained in:
parent
9766eb23e7
commit
9edbab8c90
@ -209,6 +209,7 @@ List available images
|
|||||||
[--property <key=value>]
|
[--property <key=value>]
|
||||||
[--name <name>]
|
[--name <name>]
|
||||||
[--status <status>]
|
[--status <status>]
|
||||||
|
[--tag <tag>]
|
||||||
[--long]
|
[--long]
|
||||||
[--sort <key>[:<direction>]]
|
[--sort <key>[:<direction>]]
|
||||||
[--limit <num-images>]
|
[--limit <num-images>]
|
||||||
@ -244,6 +245,12 @@ List available images
|
|||||||
|
|
||||||
*Image version 2 only*
|
*Image version 2 only*
|
||||||
|
|
||||||
|
.. option:: --tag <tag>
|
||||||
|
|
||||||
|
Filter images based on tag
|
||||||
|
|
||||||
|
*Image version 2 only*
|
||||||
|
|
||||||
.. option:: --long
|
.. option:: --long
|
||||||
|
|
||||||
List additional fields in output
|
List additional fields in output
|
||||||
|
@ -464,6 +464,12 @@ class ListImage(command.Lister):
|
|||||||
default=None,
|
default=None,
|
||||||
help=_("Filter images based on status.")
|
help=_("Filter images based on status.")
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--tag',
|
||||||
|
metavar='<tag>',
|
||||||
|
default=None,
|
||||||
|
help=_('Filter images based on tag.'),
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--long',
|
'--long',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -521,6 +527,8 @@ class ListImage(command.Lister):
|
|||||||
kwargs['name'] = parsed_args.name
|
kwargs['name'] = parsed_args.name
|
||||||
if parsed_args.status:
|
if parsed_args.status:
|
||||||
kwargs['status'] = parsed_args.status
|
kwargs['status'] = parsed_args.status
|
||||||
|
if parsed_args.tag:
|
||||||
|
kwargs['tag'] = parsed_args.tag
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
|
@ -28,10 +28,11 @@ class ImageTests(base.TestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(ImageTests, cls).setUpClass()
|
super(ImageTests, cls).setUpClass()
|
||||||
|
cls.image_tag = 'my_tag'
|
||||||
json_output = json.loads(cls.openstack(
|
json_output = json.loads(cls.openstack(
|
||||||
'--os-image-api-version 2 '
|
'--os-image-api-version 2 '
|
||||||
'image create -f json ' +
|
'image create -f json --tag {tag} {name}'.format(
|
||||||
cls.NAME
|
tag=cls.image_tag, name=cls.NAME)
|
||||||
))
|
))
|
||||||
cls.image_id = json_output["id"]
|
cls.image_id = json_output["id"]
|
||||||
cls.assertOutput(cls.NAME, json_output['name'])
|
cls.assertOutput(cls.NAME, json_output['name'])
|
||||||
@ -81,6 +82,16 @@ class ImageTests(base.TestCase):
|
|||||||
[img['Status'] for img in json_output]
|
[img['Status'] for img in json_output]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_image_list_with_tag_filter(self):
|
||||||
|
json_output = json.loads(self.openstack(
|
||||||
|
'image list --tag ' + self.image_tag + ' --long -f json'
|
||||||
|
))
|
||||||
|
for taglist in [img['Tags'].split(', ') for img in json_output]:
|
||||||
|
self.assertIn(
|
||||||
|
self.image_tag,
|
||||||
|
taglist
|
||||||
|
)
|
||||||
|
|
||||||
def test_image_attributes(self):
|
def test_image_attributes(self):
|
||||||
"""Test set, unset, show on attributes, tags and properties"""
|
"""Test set, unset, show on attributes, tags and properties"""
|
||||||
|
|
||||||
@ -142,6 +153,10 @@ class ImageTests(base.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Test tags
|
# Test tags
|
||||||
|
self.assertNotIn(
|
||||||
|
'01',
|
||||||
|
json_output["tags"].split(', ')
|
||||||
|
)
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image set ' +
|
'image set ' +
|
||||||
'--tag 01 ' +
|
'--tag 01 ' +
|
||||||
@ -151,9 +166,9 @@ class ImageTests(base.TestCase):
|
|||||||
'image show -f json ' +
|
'image show -f json ' +
|
||||||
self.NAME
|
self.NAME
|
||||||
))
|
))
|
||||||
self.assertEqual(
|
self.assertIn(
|
||||||
'01',
|
'01',
|
||||||
json_output["tags"],
|
json_output["tags"].split(', ')
|
||||||
)
|
)
|
||||||
|
|
||||||
self.openstack(
|
self.openstack(
|
||||||
@ -165,9 +180,9 @@ class ImageTests(base.TestCase):
|
|||||||
'image show -f json ' +
|
'image show -f json ' +
|
||||||
self.NAME
|
self.NAME
|
||||||
))
|
))
|
||||||
self.assertEqual(
|
self.assertNotIn(
|
||||||
'',
|
'01',
|
||||||
json_output["tags"],
|
json_output["tags"].split(', ')
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image_set_rename(self):
|
def test_image_set_rename(self):
|
||||||
|
@ -779,6 +779,20 @@ class TestImageList(TestImage):
|
|||||||
status='active', marker=self._image.id
|
status='active', marker=self._image.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_image_list_tag_option(self):
|
||||||
|
arglist = [
|
||||||
|
'--tag', 'abc',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('tag', 'abc'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.api_mock.image_list.assert_called_with(
|
||||||
|
tag='abc', marker=self._image.id
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestListImageProjects(TestImage):
|
class TestListImageProjects(TestImage):
|
||||||
|
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--tag`` option to ``image list`` command to filter by tag.
|
Loading…
Reference in New Issue
Block a user