Merge "Add options to "server list" command"

This commit is contained in:
Jenkins 2017-01-26 06:38:27 +00:00 committed by Gerrit Code Review
commit d189e807fd
4 changed files with 88 additions and 0 deletions

View File

@ -253,6 +253,8 @@ List servers
[--long]
[--marker <server>]
[--limit <limit>]
[--deleted]
[--changes-since <changes-since>]
.. option:: --reservation-id <reservation-id>
@ -327,6 +329,15 @@ List servers
be displayed. If limit is greater than 'osapi_max_limit' option of Nova
API, 'osapi_max_limit' will be used instead.
.. option:: --deleted
Only display deleted servers (Admin only).
.. option:: --changes-since <changes-since>
List only servers changed after a certain point of time. The provided time
should be an ISO 8061 formatted time. ex 2016-03-04T06:27:59Z.
server lock
-----------

View File

@ -26,6 +26,7 @@ from osc_lib.cli import parseractions
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
from oslo_utils import timeutils
import six
try:
@ -805,6 +806,20 @@ class ListServer(command.Lister):
" 'osapi_max_limit' option of Nova API,"
" 'osapi_max_limit' will be used instead."),
)
parser.add_argument(
'--deleted',
action="store_true",
default=False,
help=_('Only display deleted servers (Admin only).')
)
parser.add_argument(
'--changes-since',
metavar='<changes-since>',
default=None,
help=_("List only servers changed after a certain point of time."
" The provided time should be an ISO 8061 formatted time."
" ex 2016-03-04T06:27:59Z .")
)
return parser
def take_action(self, parsed_args):
@ -856,9 +871,19 @@ class ListServer(command.Lister):
'tenant_id': project_id,
'all_tenants': parsed_args.all_projects,
'user_id': user_id,
'deleted': parsed_args.deleted,
'changes_since': parsed_args.changes_since,
}
LOG.debug('search options: %s', search_opts)
if search_opts['changes_since']:
try:
timeutils.parse_isotime(search_opts['changes_since'])
except ValueError:
raise exceptions.CommandError(_('Invalid changes-since value:'
' %s') % search_opts['changes'
'_since'])
if parsed_args.long:
columns = (
'ID',

View File

@ -19,6 +19,7 @@ from mock import call
from osc_lib import exceptions
from osc_lib import utils as common_utils
from oslo_utils import timeutils
from openstackclient.compute.v2 import server
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@ -831,6 +832,8 @@ class TestServerList(TestServer):
'tenant_id': None,
'all_tenants': False,
'user_id': None,
'deleted': False,
'changes_since': None,
}
# Default params of the core function of the command in the case of no
@ -907,6 +910,7 @@ class TestServerList(TestServer):
verifylist = [
('all_projects', False),
('long', False),
('deleted', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -972,6 +976,48 @@ class TestServerList(TestServer):
self.assertEqual(self.columns, columns)
self.assertEqual(tuple(self.data), tuple(data))
def test_server_list_with_changes_since(self):
arglist = [
'--changes-since', '2016-03-04T06:27:59Z',
'--deleted'
]
verifylist = [
('changes_since', '2016-03-04T06:27:59Z'),
('deleted', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.search_opts['changes_since'] = '2016-03-04T06:27:59Z'
self.search_opts['deleted'] = True
self.servers_mock.list.assert_called_with(**self.kwargs)
self.assertEqual(self.columns, columns)
self.assertEqual(tuple(self.data), tuple(data))
@mock.patch.object(timeutils, 'parse_isotime', side_effect=ValueError)
def test_server_list_with_invalid_changes_since(self, mock_parse_isotime):
arglist = [
'--changes-since', 'Invalid time value',
]
verifylist = [
('changes_since', 'Invalid time value'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
try:
self.cmd.take_action(parsed_args)
self.fail('CommandError should be raised.')
except exceptions.CommandError as e:
self.assertEqual('Invalid changes-since value: Invalid time '
'value', str(e))
mock_parse_isotime.assert_called_once_with(
'Invalid time value'
)
class TestServerLock(TestServer):

View File

@ -0,0 +1,6 @@
---
features:
- |
Add ``--deleted`` and ``--changes-since`` options to ``server list``
command.
[Bug `1647242 <https://bugs.launchpad.net/bugs/1647272>`_]