From 704880468b2cc495bb00266ff00bbea4fb0f28e6 Mon Sep 17 00:00:00 2001 From: Takashi NATSUME Date: Mon, 4 Mar 2019 15:34:19 +0900 Subject: [PATCH] Fix wrong consumer type in logging In the 'delete_allocation_for_instance' method, a consumer UUID is output in the log. The consumer UUID is UUID of a server or UUID of a migration. However the consumer UUID is described as UUID of a server in the log. Fix the description in the log. Change-Id: I1dea4472b232d6c054879ebda2536658d9769053 Closes-Bug: #1818252 --- nova/compute/manager.py | 2 +- nova/scheduler/client/report.py | 23 ++++++++++++++------- nova/tests/unit/compute/test_compute_mgr.py | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index f207c18b51ad..5192573da2b2 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -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 ' diff --git a/nova/scheduler/client/report.py b/nova/scheduler/client/report.py index debb01cf3cf8..1e45cfcb0596 100644 --- a/nova/scheduler/client/report.py +++ b/nova/scheduler/client/report.py @@ -1952,12 +1952,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 @@ -1980,9 +1983,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, @@ -2000,12 +2004,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, diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 915c5bfecd67..319f4b69d539 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -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."""