diff --git a/manilaclient/api_versions.py b/manilaclient/api_versions.py index 4f16fb57b..5a66a159f 100644 --- a/manilaclient/api_versions.py +++ b/manilaclient/api_versions.py @@ -27,7 +27,7 @@ from manilaclient import utils LOG = logging.getLogger(__name__) -MAX_VERSION = '2.51' +MAX_VERSION = '2.52' MIN_VERSION = '2.0' DEPRECATED_VERSION = '1.0' _VERSIONED_METHOD_MAP = {} diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index d42cc4f8d..677a3fe6f 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -3354,6 +3354,22 @@ class ShellTest(test_utils.TestCase): 'Action ID', 'User Message', 'Detail ID', 'Created At'], sortby_index=None) + @mock.patch.object(cliutils, 'print_list', mock.Mock()) + def test_share_message_list_created_before_aliases(self): + self.run_command('message-list --before 2001-01-01') + self.assert_called( + 'GET', + '/messages?created_before=2001-01-01', + ) + + @mock.patch.object(cliutils, 'print_list', mock.Mock()) + def test_share_message_list_created_since_aliases(self): + self.run_command('message-list --since 2001-01-01') + self.assert_called( + 'GET', + '/messages?created_since=2001-01-01', + ) + @mock.patch.object(cliutils, 'print_list', mock.Mock()) def test_message_list_select_column(self): self.run_command('message-list --columns id,resource_type') diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index dc5e023ea..9238b4590 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -5601,6 +5601,20 @@ def do_share_replica_resync(cs, args): default=None, help='Comma separated list of columns to be displayed ' 'example --columns "resource_id,user_message".') +@cliutils.arg( + '--since', + metavar='', + default=None, + help='Return only user messages created since given date. ' + 'The date format must be conforming to ISO8601. ' + 'Available only for microversion >= 2.52.') +@cliutils.arg( + '--before', + metavar='', + default=None, + help='Return only user messages created before given date. ' + 'The date format must be conforming to ISO8601. ' + 'Available only for microversion >= 2.52.') def do_message_list(cs, args): """Lists all messages.""" if args.columns is not None: @@ -5619,6 +5633,15 @@ def do_message_list(cs, args): 'detail_id': args.detail_id, 'message_level': args.level } + if cs.api_version < api_versions.APIVersion("2.52"): + msg = ("Filtering messages by 'since' and 'before' is possible only " + "with Manila API version >=2.52") + if getattr(args, 'since') or getattr(args, 'before'): + raise exceptions.CommandError(msg) + else: + search_opts['created_since'] = args.since + search_opts['created_before'] = args.before + messages = cs.messages.list( search_opts=search_opts, sort_key=args.sort_key, sort_dir=args.sort_dir) diff --git a/releasenotes/notes/bp-support-query-user-messages-by-timestamp-34b70bba2d1b4d13.yaml b/releasenotes/notes/bp-support-query-user-messages-by-timestamp-34b70bba2d1b4d13.yaml new file mode 100644 index 000000000..ec3b1f6b3 --- /dev/null +++ b/releasenotes/notes/bp-support-query-user-messages-by-timestamp-34b70bba2d1b4d13.yaml @@ -0,0 +1,4 @@ +--- +features: + - Added ``since`` and ``before`` to messages list API. User messages can be + queried by stimestamp with API version ``2.52`` and beyond. \ No newline at end of file