From 5cc6fc2b88296035f687f72d92efe4a3cea78fc7 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Wed, 5 May 2021 16:59:14 +0300 Subject: [PATCH] Allow to filter multiple tags for image list Currently in case of passing `--tag` several times, only last one will be picked up for the filtering. In the meanwhile Glance allow option to be repeated multiple times to filter based on the multiple tags. Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/789827 Change-Id: I7379d0b0014f0e3d13b02ee5ec6b642a7a5aa7d1 --- openstackclient/image/v2/image.py | 6 ++++-- openstackclient/tests/functional/image/v2/test_image.py | 8 +++++++- openstackclient/tests/unit/image/v2/test_image.py | 5 +++-- .../notes/image-list-multiple-tags-a394799c7807f031.yaml | 5 +++++ 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/image-list-multiple-tags-a394799c7807f031.yaml diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 31a5bc4e2..117d7a89a 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -613,8 +613,10 @@ class ListImage(command.Lister): parser.add_argument( '--tag', metavar='', - default=None, - help=_('Filter images based on tag.'), + action='append', + default=[], + help=_('Filter images based on tag. ' + '(repeat option to filter on multiple tags)'), ) parser.add_argument( '--hidden', diff --git a/openstackclient/tests/functional/image/v2/test_image.py b/openstackclient/tests/functional/image/v2/test_image.py index 0a3a73602..5b0747009 100644 --- a/openstackclient/tests/functional/image/v2/test_image.py +++ b/openstackclient/tests/functional/image/v2/test_image.py @@ -26,6 +26,7 @@ class ImageTests(base.BaseImageTests): self.name = uuid.uuid4().hex self.image_tag = 'my_tag' + self.image_tag1 = 'random' json_output = json.loads(self.openstack( '--os-image-api-version 2 ' 'image create -f json --tag {tag} {name}'.format( @@ -78,13 +79,18 @@ class ImageTests(base.BaseImageTests): def test_image_list_with_tag_filter(self): json_output = json.loads(self.openstack( - 'image list --tag ' + self.image_tag + ' --long -f json' + 'image list --tag ' + self.image_tag + ' --tag ' + + self.image_tag1 + ' --long -f json' )) for taglist in [img['Tags'] for img in json_output]: self.assertIn( self.image_tag, taglist ) + self.assertIn( + self.image_tag1, + taglist + ) def test_image_attributes(self): """Test set, unset, show on attributes, tags and properties""" diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index 7ccc9f0fb..d563bf504 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -835,15 +835,16 @@ class TestImageList(TestImage): def test_image_list_tag_option(self): arglist = [ '--tag', 'abc', + '--tag', 'cba' ] verifylist = [ - ('tag', 'abc'), + ('tag', ['abc', 'cba']), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) self.client.images.assert_called_with( - tag='abc' + tag=['abc', 'cba'] ) diff --git a/releasenotes/notes/image-list-multiple-tags-a394799c7807f031.yaml b/releasenotes/notes/image-list-multiple-tags-a394799c7807f031.yaml new file mode 100644 index 000000000..82c966b46 --- /dev/null +++ b/releasenotes/notes/image-list-multiple-tags-a394799c7807f031.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The ``image list`` now accepts multiple ``--tag`` options, allowing you to + filter images on more than one tag.