Ensure resource class cache when listing usages

In rare circumstances it is possible to list usages in a new placement
process that has not yet instantiated the _RC_CACHE but for which
there are inventories and allocations in the database (added by
other processes running against the same db). Before this change
that would cause a 500 error (AttributeError) when the Usage objects
in the UsageList were instantiated.

The fix is to added _ensure_rc_cache to the two list methods. The
addition is done there rather than in the _from_db_object as the
latter would cause a lot of redundant checks.

While we could probably devise a test for this, it's perhaps good
enough to evaluate the change by inspection. If not, suggestions
welcome.

This, the ocata version, has only half the changes provided by
commits in newer versions because in ocata, get_all_by_project_user
is not yet available.

Change-Id: I00f7dee26f031366dbc0d3d6a03abe89afeb85fd
Closes-Bug: #1775308
(cherry picked from commit 724d440122)
(cherry picked from commit 79a1a11377)
(cherry picked from commit 6e1dd287f1)
This commit is contained in:
Chris Dent 2018-06-05 18:07:05 -07:00
parent 7af016cd02
commit 4bd2a8d9d9
1 changed files with 1 additions and 0 deletions

View File

@ -1258,6 +1258,7 @@ class UsageList(base.ObjectListBase, base.NovaObject):
@classmethod
def get_all_by_resource_provider_uuid(cls, context, rp_uuid):
_ensure_rc_cache(context)
usage_list = cls._get_all_by_resource_provider_uuid(context, rp_uuid)
return base.obj_make_list(context, cls(context), Usage, usage_list)