Support query user message by timestamp

add created_since and created_before to message-list API.

Depends-On: I3d94bac4304c236f275abe7ce31432b0e2384247
Change-Id: I91d00888d71aa3bc4a8c9aaa4d2a3e9d23d19286
Partially-Implements: blueprint query-user-message-by-timestamp
This commit is contained in:
haixin 2020-02-20 14:35:27 +08:00
parent 3beec44af2
commit 4c87b940d9
4 changed files with 44 additions and 1 deletions

View File

@ -27,7 +27,7 @@ from manilaclient import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
MAX_VERSION = '2.51' MAX_VERSION = '2.52'
MIN_VERSION = '2.0' MIN_VERSION = '2.0'
DEPRECATED_VERSION = '1.0' DEPRECATED_VERSION = '1.0'
_VERSIONED_METHOD_MAP = {} _VERSIONED_METHOD_MAP = {}

View File

@ -3354,6 +3354,22 @@ class ShellTest(test_utils.TestCase):
'Action ID', 'User Message', 'Detail ID', 'Action ID', 'User Message', 'Detail ID',
'Created At'], sortby_index=None) '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()) @mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_message_list_select_column(self): def test_message_list_select_column(self):
self.run_command('message-list --columns id,resource_type') self.run_command('message-list --columns id,resource_type')

View File

@ -5601,6 +5601,20 @@ def do_share_replica_resync(cs, args):
default=None, default=None,
help='Comma separated list of columns to be displayed ' help='Comma separated list of columns to be displayed '
'example --columns "resource_id,user_message".') 'example --columns "resource_id,user_message".')
@cliutils.arg(
'--since',
metavar='<since>',
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='<before>',
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): def do_message_list(cs, args):
"""Lists all messages.""" """Lists all messages."""
if args.columns is not None: if args.columns is not None:
@ -5619,6 +5633,15 @@ def do_message_list(cs, args):
'detail_id': args.detail_id, 'detail_id': args.detail_id,
'message_level': args.level '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( messages = cs.messages.list(
search_opts=search_opts, sort_key=args.sort_key, search_opts=search_opts, sort_key=args.sort_key,
sort_dir=args.sort_dir) sort_dir=args.sort_dir)

View File

@ -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.