Merge "Don't heal allocations for deleted servers"

This commit is contained in:
Zuul 2018-06-20 09:25:48 +00:00 committed by Gerrit Code Review
commit b992b90d73
2 changed files with 17 additions and 2 deletions

View File

@ -1804,8 +1804,9 @@ class PlacementCommands(object):
# TODO(mriedem): Store a marker in system_metadata so we can
# automatically pick up where we left off without the user having
# to pass it in (if unlimited is False).
filters = {'deleted': False}
instances = objects.InstanceList.get_by_filters(
ctxt, filters={}, sort_key='created_at', sort_dir='asc',
ctxt, filters=filters, sort_key='created_at', sort_dir='asc',
limit=max_count, expected_attrs=['flavor'])
while instances:
output(_('Found %s candidate instances.') % len(instances))
@ -1867,7 +1868,7 @@ class PlacementCommands(object):
# Note that InstanceList doesn't support slice notation.
marker = instances[len(instances) - 1].uuid
instances = objects.InstanceList.get_by_filters(
ctxt, filters={}, sort_key='created_at', sort_dir='asc',
ctxt, filters=filters, sort_key='created_at', sort_dir='asc',
limit=max_count, marker=marker, expected_attrs=['flavor'])
return num_processed

View File

@ -571,3 +571,17 @@ class TestNovaManagePlacementHealAllocations(
# Assert something was logged for this instance when it was skipped.
self.assertIn('Instance %s is undergoing a task state transition: '
'pausing' % server['id'], self.output.getvalue())
def test_heal_allocations_ignore_deleted_server(self):
"""Creates two servers, deletes one, and then runs heal_allocations
to make sure deleted servers are filtered out.
"""
# Create a server that we'll leave alive
self._boot_and_assert_no_allocations(self.flavor, 'cell1')
# and another that we'll delete
server, _ = self._boot_and_assert_no_allocations(self.flavor, 'cell1')
self.api.delete_server(server['id'])
self._wait_until_deleted(server)
result = self.cli.heal_allocations(verbose=True)
self.assertEqual(0, result, self.output.getvalue())
self.assertIn('Processed 1 instances.', self.output.getvalue())