diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 3eeee195080e..551fc4dc0b30 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -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 diff --git a/nova/tests/functional/test_nova_manage.py b/nova/tests/functional/test_nova_manage.py index 1a8eec053bdb..c92f15e42aca 100644 --- a/nova/tests/functional/test_nova_manage.py +++ b/nova/tests/functional/test_nova_manage.py @@ -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())