Merge "Fix wrong consumer type in logging"

This commit is contained in:
Zuul 2019-03-05 11:34:18 +00:00 committed by Gerrit Code Review
commit 047f8c71c2
3 changed files with 17 additions and 10 deletions

View File

@ -3992,7 +3992,7 @@ class ComputeManager(manager.Manager):
# NOTE(danms): We're finishing on the source node, so try
# to delete the allocation based on the migration uuid
self.reportclient.delete_allocation_for_instance(
context, migration.uuid)
context, migration.uuid, consumer_type='migration')
except exception.AllocationDeleteFailed:
LOG.error('Deleting allocation in placement for migration '
'%(migration_uuid)s failed. The instance '

View File

@ -1964,12 +1964,15 @@ class SchedulerReportClient(object):
return r.status_code == 204
@safe_connect
def delete_allocation_for_instance(self, context, uuid):
def delete_allocation_for_instance(self, context, uuid,
consumer_type='instance'):
"""Delete the instance allocation from placement
:param context: The security context
:param uuid: the instance UUID which will be used as the consumer UUID
towards placement
:param uuid: the instance or migration UUID which will be used
as the consumer UUID towards placement
:param consumer_type: The type of the consumer specified by uuid.
'instance' or 'migration' (Default: instance)
:return: Returns True if the allocation is successfully deleted by this
call. Returns False if the allocation does not exist.
:raises AllocationDeleteFailed: If the allocation cannot be read from
@ -1992,9 +1995,10 @@ class SchedulerReportClient(object):
if not r:
# at the moment there is no way placement returns a failure so we
# could even delete this code
LOG.warning('Unable to delete allocation for instance '
LOG.warning('Unable to delete allocation for %(consumer_type)s '
'%(uuid)s: (%(code)i %(text)s)',
{'uuid': uuid,
{'consumer_type': consumer_type,
'uuid': uuid,
'code': r.status_code,
'text': r.text})
raise exception.AllocationDeleteFailed(consumer_uuid=uuid,
@ -2012,12 +2016,15 @@ class SchedulerReportClient(object):
r = self.put(url, allocations, global_request_id=context.global_id,
version=CONSUMER_GENERATION_VERSION)
if r.status_code == 204:
LOG.info('Deleted allocation for instance %s', uuid)
LOG.info('Deleted allocation for %(consumer_type)s %(uuid)s',
{'consumer_type': consumer_type,
'uuid': uuid})
return True
else:
LOG.warning('Unable to delete allocation for instance '
LOG.warning('Unable to delete allocation for %(consumer_type)s '
'%(uuid)s: (%(code)i %(text)s)',
{'uuid': uuid,
{'consumer_type': consumer_type,
'uuid': uuid,
'code': r.status_code,
'text': r.text})
raise exception.AllocationDeleteFailed(consumer_uuid=uuid,

View File

@ -7090,7 +7090,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase,
self.instance,
self.migration)
mock_report.delete_allocation_for_instance.assert_called_once_with(
self.context, self.migration.uuid)
self.context, self.migration.uuid, consumer_type='migration')
def test_revert_allocation(self):
"""New-style migration-based allocation revert."""