Don't heal allocations for deleted servers

InstanceList.get_by_filters by default returns deleted
servers, which we don't want to heal, so this adds the
missing filter along with a functional test to show
this working as expected.

Change-Id: Ic18b3ea5c7db5a0535488498b4e330803e0635b5
Closes-Bug: #1776743
This commit is contained in:
Matt Riedemann 2018-06-13 16:23:17 -04:00
parent 343c2bee23
commit c8d5a71da6
2 changed files with 17 additions and 2 deletions

View File

@ -1789,8 +1789,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))
@ -1852,7 +1853,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())