summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-06-15 18:11:27 +0000
committerGerrit Code Review <review@openstack.org>2015-06-15 18:11:27 +0000
commit0d22e821f9df4247e16a115f8b486d9bdd68eea1 (patch)
tree45f8aa6eb5a0815e18c5e7c87b4be7d0a193c0c1
parente863cb3f94d3c9841a9ea5506a2fdfd795e348d1 (diff)
parent116fac8ae81a154f64be8e3b9629cedf7d4eaad1 (diff)
downloadpython-glanceclient-0d22e821f9df4247e16a115f8b486d9bdd68eea1.tar.gz
Merge "Add parameter 'changes-since' for image-list of v1"
-rw-r--r--glanceclient/tests/unit/v1/test_shell.py57
-rw-r--r--glanceclient/v1/shell.py8
2 files changed, 64 insertions, 1 deletions
diff --git a/glanceclient/tests/unit/v1/test_shell.py b/glanceclient/tests/unit/v1/test_shell.py
index 4c74ca0..963c560 100644
--- a/glanceclient/tests/unit/v1/test_shell.py
+++ b/glanceclient/tests/unit/v1/test_shell.py
@@ -233,6 +233,24 @@ class ShellInvalidEndpointandParameterTest(utils.TestCase):
self.shell = shell.OpenStackImagesShell()
+ self.gc = self._mock_glance_client()
+
+ def _make_args(self, args):
+ #NOTE(venkatesh): this conversion from a dict to an object
+ # is required because the test_shell.do_xxx(gc, args) methods
+ # expects the args to be attributes of an object. If passed as
+ # dict directly, it throws an AttributeError.
+ class Args():
+ def __init__(self, entries):
+ self.__dict__.update(entries)
+
+ return Args(args)
+
+ def _mock_glance_client(self):
+ my_mocked_gc = mock.Mock()
+ my_mocked_gc.get.return_value = {}
+ return my_mocked_gc
+
def tearDown(self):
super(ShellInvalidEndpointandParameterTest, self).tearDown()
os.environ = self.old_environment
@@ -335,6 +353,45 @@ class ShellInvalidEndpointandParameterTest(utils.TestCase):
SystemExit,
self.run_command, 'image-list --size-max 10gb')
+ def test_do_image_list_with_changes_since(self):
+ input = {
+ 'name': None,
+ 'limit': None,
+ 'status': None,
+ 'container_format': 'bare',
+ 'size_min': None,
+ 'size_max': None,
+ 'is_public': True,
+ 'disk_format': 'raw',
+ 'page_size': 20,
+ 'visibility': True,
+ 'member_status': 'Fake',
+ 'owner': 'test',
+ 'checksum': 'fake_checksum',
+ 'tag': 'fake tag',
+ 'properties': [],
+ 'sort_key': None,
+ 'sort_dir': None,
+ 'all_tenants': False,
+ 'human_readable': True,
+ 'changes_since': '2011-1-1'
+ }
+ args = self._make_args(input)
+ with mock.patch.object(self.gc.images, 'list') as mocked_list:
+ mocked_list.return_value = {}
+
+ v1shell.do_image_list(self.gc, args)
+
+ exp_img_filters = {'container_format': 'bare',
+ 'changes-since': '2011-1-1',
+ 'disk_format': 'raw',
+ 'is_public': True}
+ mocked_list.assert_called_once_with(sort_dir=None,
+ sort_key=None,
+ owner='test',
+ page_size=20,
+ filters=exp_img_filters)
+
class ShellStdinHandlingTests(testtools.TestCase):
diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py
index 692f9bc..83b8576 100644
--- a/glanceclient/v1/shell.py
+++ b/glanceclient/v1/shell.py
@@ -40,6 +40,9 @@ _bool_strict = functools.partial(strutils.bool_from_string, strict=True)
help='Filter images to those that have this name.')
@utils.arg('--status', metavar='<STATUS>',
help='Filter images to those that have this status.')
+@utils.arg('--changes-since', metavar='<CHANGES_SINCE>',
+ help='Filter images to those that changed since the given time'
+ ', which will include the deleted images.')
@utils.arg('--container-format', metavar='<CONTAINER_FORMAT>',
help='Filter images to those that have this container format. '
+ CONTAINER_FORMATS)
@@ -80,10 +83,13 @@ _bool_strict = functools.partial(strutils.bool_from_string, strict=True)
def do_image_list(gc, args):
"""List images you can access."""
filter_keys = ['name', 'status', 'container_format', 'disk_format',
- 'size_min', 'size_max', 'is_public']
+ 'size_min', 'size_max', 'is_public', 'changes_since']
filter_items = [(key, getattr(args, key)) for key in filter_keys]
filters = dict([item for item in filter_items if item[1] is not None])
+ if 'changes_since' in filters:
+ filters['changes-since'] = filters.pop('changes_since')
+
if args.properties:
property_filter_items = [p.split('=', 1) for p in args.properties]
if any(len(pair) != 2 for pair in property_filter_items):