Merge "Fix openstack server list --deleted --marker option" into stable/stein

This commit is contained in:
Zuul 2020-08-07 19:41:01 +00:00 committed by Gerrit Code Review
commit b8ff69eaca
3 changed files with 87 additions and 3 deletions

View File

@ -1134,7 +1134,8 @@ class ListServer(command.Lister):
default=None,
help=_('The last server of the previous page. Display '
'list of servers after marker. Display all servers if not '
'specified. (name or ID)')
'specified. When used with ``--deleted``, the marker must '
'be an ID, otherwise a name or ID can be used.'),
)
parser.add_argument(
'--limit',
@ -1292,9 +1293,17 @@ class ListServer(command.Lister):
mixed_case_fields = []
marker_id = None
if parsed_args.marker:
marker_id = utils.find_resource(compute_client.servers,
parsed_args.marker).id
# Check if both "--marker" and "--deleted" are used.
# In that scenario a lookup is not needed as the marker
# needs to be an ID, because find_resource does not
# handle deleted resources
if parsed_args.deleted:
marker_id = parsed_args.marker
else:
marker_id = utils.find_resource(compute_client.servers,
parsed_args.marker).id
data = compute_client.servers.list(search_opts=search_opts,
marker=marker_id,

View File

@ -63,6 +63,73 @@ class ServerTests(common.ComputeTestCase):
self.assertNotIn(name1, col_name)
self.assertIn(name2, col_name)
def test_server_list_with_marker_and_deleted(self):
"""Test server list with deleted and marker"""
cmd_output = self.server_create(cleanup=False)
name1 = cmd_output['name']
cmd_output = self.server_create(cleanup=False)
name2 = cmd_output['name']
id2 = cmd_output['id']
self.wait_for_status(name1, "ACTIVE")
self.wait_for_status(name2, "ACTIVE")
# Test list --marker with ID
cmd_output = json.loads(self.openstack(
'server list -f json --marker ' + id2
))
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
# Test list --marker with Name
cmd_output = json.loads(self.openstack(
'server list -f json --marker ' + name2
))
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
self.openstack('server delete --wait ' + name1)
self.openstack('server delete --wait ' + name2)
# Test list --deleted --marker with ID
cmd_output = json.loads(self.openstack(
'server list -f json --deleted --marker ' + id2
))
col_name = [x["Name"] for x in cmd_output]
self.assertIn(name1, col_name)
# Test list --deleted --marker with Name
try:
cmd_output = json.loads(self.openstack(
'server list -f json --deleted --marker ' + name2
))
except exceptions.CommandFailed as e:
self.assertIn('marker [%s] not found (HTTP 400)' % (name2),
e.stderr.decode('utf-8'))
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_set(self):
"""Test server create, delete, set, show"""
cmd_output = self.server_create()

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Fixes the "No server with a name or ID of 'id' exists" error when running
``server list --deleted --marker``. The fix removes using a name for
the marker when both ``--deleted`` and ``--marker`` are used. In
this scenario an ID must be supplied for the marker.
[Story `2006761 <https://storyboard.openstack.org/#!/story/2006761>`_]