Avoid UnhashableKeyWarning in api.nova.extension_supported

In python3, novaclient ListExtResource is not hashable.
An error message on UnhashableKeyWarning is emitted repeatedly
and this can pollute error log with unuseful messages.

A tuple of extension names are now passed to the memoized
decorator so that the decorator can hash it.

Change-Id: I7f200ee6ece36767586207dc26aed1325b909226
Closes-Bug: #1790930
This commit is contained in:
Akihiro Motoki 2018-09-05 19:08:33 +00:00
parent 0afe450101
commit f9bb10b945
1 changed files with 11 additions and 4 deletions

View File

@ -1072,16 +1072,23 @@ def list_extensions(nova_api):
)
# NOTE(amotoki): In Python 3, a tuple of the Extension classes
# is not hashable. The return value must be a known premitive.
# This converts the return value to a tuple of a string.
def _list_extensions_wrap(request):
return tuple(e.name for e in list_extensions(request))
@profiler.trace
@memoized_with_request(list_extensions, 1)
def extension_supported(extension_name, extensions):
@memoized_with_request(_list_extensions_wrap, 1)
def extension_supported(extension_name, supported_ext_names):
"""Determine if nova supports a given extension name.
Example values for the extension_name include AdminActions, ConsoleOutput,
etc.
"""
for extension in extensions:
if extension.name == extension_name:
for ext in supported_ext_names:
if ext == extension_name:
return True
return False