Merge "Add changes-before attribute to server list"
This commit is contained in:
commit
86d7490f77
@ -1143,13 +1143,22 @@ class ListServer(command.Lister):
|
|||||||
default=False,
|
default=False,
|
||||||
help=_('Only display deleted servers (Admin only).')
|
help=_('Only display deleted servers (Admin only).')
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--changes-before',
|
||||||
|
metavar='<changes-before>',
|
||||||
|
default=None,
|
||||||
|
help=_("List only servers changed before a certain point of time. "
|
||||||
|
"The provided time should be an ISO 8061 formatted time "
|
||||||
|
"(e.g., 2016-03-05T06:27:59Z). "
|
||||||
|
"(Supported by API versions '2.66' - '2.latest')")
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--changes-since',
|
'--changes-since',
|
||||||
metavar='<changes-since>',
|
metavar='<changes-since>',
|
||||||
default=None,
|
default=None,
|
||||||
help=_("List only servers changed after a certain point of time."
|
help=_("List only servers changed after a certain point of time."
|
||||||
" The provided time should be an ISO 8061 formatted time."
|
" The provided time should be an ISO 8061 formatted time"
|
||||||
" ex 2016-03-04T06:27:59Z .")
|
" (e.g., 2016-03-04T06:27:59Z).")
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -1203,10 +1212,24 @@ class ListServer(command.Lister):
|
|||||||
'all_tenants': parsed_args.all_projects,
|
'all_tenants': parsed_args.all_projects,
|
||||||
'user_id': user_id,
|
'user_id': user_id,
|
||||||
'deleted': parsed_args.deleted,
|
'deleted': parsed_args.deleted,
|
||||||
|
'changes-before': parsed_args.changes_before,
|
||||||
'changes-since': parsed_args.changes_since,
|
'changes-since': parsed_args.changes_since,
|
||||||
}
|
}
|
||||||
LOG.debug('search options: %s', search_opts)
|
LOG.debug('search options: %s', search_opts)
|
||||||
|
|
||||||
|
if search_opts['changes-before']:
|
||||||
|
if compute_client.api_version < api_versions.APIVersion('2.66'):
|
||||||
|
msg = _('--os-compute-api-version 2.66 or later is required')
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
try:
|
||||||
|
timeutils.parse_isotime(search_opts['changes-before'])
|
||||||
|
except ValueError:
|
||||||
|
raise exceptions.CommandError(
|
||||||
|
_('Invalid changes-before value: %s') %
|
||||||
|
search_opts['changes-before']
|
||||||
|
)
|
||||||
|
|
||||||
if search_opts['changes-since']:
|
if search_opts['changes-since']:
|
||||||
try:
|
try:
|
||||||
timeutils.parse_isotime(search_opts['changes-since'])
|
timeutils.parse_isotime(search_opts['changes-since'])
|
||||||
|
@ -63,6 +63,84 @@ class ServerTests(common.ComputeTestCase):
|
|||||||
self.assertNotIn(name1, col_name)
|
self.assertNotIn(name1, col_name)
|
||||||
self.assertIn(name2, col_name)
|
self.assertIn(name2, col_name)
|
||||||
|
|
||||||
|
def test_server_list_with_changes_before(self):
|
||||||
|
"""Test server list.
|
||||||
|
|
||||||
|
Getting the servers list with updated_at time equal or
|
||||||
|
before than changes-before.
|
||||||
|
"""
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name1 = cmd_output['name']
|
||||||
|
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name2 = cmd_output['name']
|
||||||
|
updated_at2 = cmd_output['updated']
|
||||||
|
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name3 = cmd_output['name']
|
||||||
|
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'--os-compute-api-version 2.66 ' +
|
||||||
|
'server list -f json '
|
||||||
|
'--changes-before ' + updated_at2
|
||||||
|
))
|
||||||
|
|
||||||
|
col_updated = [server["Name"] for server in cmd_output]
|
||||||
|
self.assertIn(server_name1, col_updated)
|
||||||
|
self.assertIn(server_name2, col_updated)
|
||||||
|
self.assertNotIn(server_name3, col_updated)
|
||||||
|
|
||||||
|
def test_server_list_with_changes_since(self):
|
||||||
|
"""Test server list.
|
||||||
|
|
||||||
|
Getting the servers list with updated_at time equal or
|
||||||
|
later than changes-since.
|
||||||
|
"""
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name1 = cmd_output['name']
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name2 = cmd_output['name']
|
||||||
|
updated_at2 = cmd_output['updated']
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name3 = cmd_output['name']
|
||||||
|
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'server list -f json '
|
||||||
|
'--changes-since ' + updated_at2
|
||||||
|
))
|
||||||
|
|
||||||
|
col_updated = [server["Name"] for server in cmd_output]
|
||||||
|
self.assertNotIn(server_name1, col_updated)
|
||||||
|
self.assertIn(server_name2, col_updated)
|
||||||
|
self.assertIn(server_name3, col_updated)
|
||||||
|
|
||||||
|
def test_server_list_with_changes_before_and_changes_since(self):
|
||||||
|
"""Test server list.
|
||||||
|
|
||||||
|
Getting the servers list with updated_at time equal or before than
|
||||||
|
changes-before and equal or later than changes-since.
|
||||||
|
"""
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name1 = cmd_output['name']
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name2 = cmd_output['name']
|
||||||
|
updated_at2 = cmd_output['updated']
|
||||||
|
cmd_output = self.server_create()
|
||||||
|
server_name3 = cmd_output['name']
|
||||||
|
updated_at3 = cmd_output['updated']
|
||||||
|
|
||||||
|
cmd_output = json.loads(self.openstack(
|
||||||
|
'--os-compute-api-version 2.66 ' +
|
||||||
|
'server list -f json ' +
|
||||||
|
'--changes-since ' + updated_at2 +
|
||||||
|
' --changes-before ' + updated_at3
|
||||||
|
))
|
||||||
|
|
||||||
|
col_updated = [server["Name"] for server in cmd_output]
|
||||||
|
self.assertNotIn(server_name1, col_updated)
|
||||||
|
self.assertIn(server_name2, col_updated)
|
||||||
|
self.assertIn(server_name3, col_updated)
|
||||||
|
|
||||||
def test_server_set(self):
|
def test_server_set(self):
|
||||||
"""Test server create, delete, set, show"""
|
"""Test server create, delete, set, show"""
|
||||||
cmd_output = self.server_create()
|
cmd_output = self.server_create()
|
||||||
|
@ -2075,6 +2075,7 @@ class TestServerList(TestServer):
|
|||||||
'user_id': None,
|
'user_id': None,
|
||||||
'deleted': False,
|
'deleted': False,
|
||||||
'changes-since': None,
|
'changes-since': None,
|
||||||
|
'changes-before': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Default params of the core function of the command in the case of no
|
# Default params of the core function of the command in the case of no
|
||||||
@ -2356,6 +2357,71 @@ class TestServerList(TestServer):
|
|||||||
'Invalid time value'
|
'Invalid time value'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_server_list_v266_with_changes_before(self):
|
||||||
|
self.app.client_manager.compute.api_version = (
|
||||||
|
api_versions.APIVersion('2.66'))
|
||||||
|
arglist = [
|
||||||
|
'--changes-before', '2016-03-05T06:27:59Z',
|
||||||
|
'--deleted'
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('changes_before', '2016-03-05T06: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-before'] = '2016-03-05T06: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_v266_with_invalid_changes_before(
|
||||||
|
self, mock_parse_isotime):
|
||||||
|
self.app.client_manager.compute.api_version = (
|
||||||
|
api_versions.APIVersion('2.66'))
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--changes-before', 'Invalid time value',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('changes_before', '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-before value: Invalid time '
|
||||||
|
'value', str(e))
|
||||||
|
mock_parse_isotime.assert_called_once_with(
|
||||||
|
'Invalid time value'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_server_with_changes_before_older_version(self):
|
||||||
|
self.app.client_manager.compute.api_version = (
|
||||||
|
api_versions.APIVersion('2.65'))
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--changes-before', '2016-03-05T06:27:59Z',
|
||||||
|
'--deleted'
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('changes_before', '2016-03-05T06:27:59Z'),
|
||||||
|
('deleted', True),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.assertRaises(exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
|
||||||
def test_server_list_v269_with_partial_constructs(self):
|
def test_server_list_v269_with_partial_constructs(self):
|
||||||
self.app.client_manager.compute.api_version = \
|
self.app.client_manager.compute.api_version = \
|
||||||
api_versions.APIVersion('2.69')
|
api_versions.APIVersion('2.69')
|
||||||
|
6
releasenotes/notes/bug-1827844-8f1de120087c6a22.yaml
Normal file
6
releasenotes/notes/bug-1827844-8f1de120087c6a22.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--changes-before`` option to the ``server list`` command.
|
||||||
|
This requires Compute API version '2.66' or later.
|
||||||
|
[:lpbug: `1827844`]
|
Loading…
Reference in New Issue
Block a user