Log quota legacy method warning only if counting from placement

The log warning message is being emitted unconditionally and should be
limited to only when CONF.quota.count_usage_from_placement = True.

This fixes the issue and adds missing unit test coverage that would
have caught it.

Closes-Bug: #1833130

Change-Id: I00ee0bd99c4f31a2b73fc69373fefb56740f5425
This commit is contained in:
melanie witt 2019-06-17 21:21:27 +00:00
parent ea7293c7be
commit 818c31f96e
2 changed files with 4 additions and 2 deletions

View File

@ -1312,8 +1312,8 @@ def _instances_cores_ram_count(context, project_id, user_id=None):
return _instances_cores_ram_count_api_db_placement(context,
project_id,
user_id=user_id)
LOG.warning('Falling back to legacy quota counting method for instances, '
'cores, and ram')
LOG.warning('Falling back to legacy quota counting method for '
'instances, cores, and ram')
return _instances_cores_ram_count_legacy(context, project_id,
user_id=user_id)

View File

@ -2057,6 +2057,8 @@ class QuotaCountTestCase(test.NoDBTestCase):
# We only log the message if someone has opted in to counting
# from placement.
mock_warn_log.assert_called_once()
else:
mock_warn_log.assert_not_called()
# We should not have called the API DB and placement counting
# method.
mock_api_db_placement_count.assert_not_called()