1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-02-03 13:47:14 +03:00

Added missing cache for list_snapshots

This commit is contained in:
Adolfo Gómez García 2024-03-10 02:25:20 +01:00
parent db77332c17
commit 934c43636e
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23

View File

@ -239,7 +239,9 @@ class OpenstackClient: # pylint: disable=too-many-public-methods
for i, endpoint in enumerate(found_endpoints):
try:
logger.debug('Requesting from endpoint: %s and path %s using %s: %s', endpoint, path, type, data)
logger.debug(
'Requesting from endpoint: %s and path %s using %s: %s', endpoint, path, type, data
)
r = self._session.request(
type,
endpoint + path,
@ -247,11 +249,9 @@ class OpenstackClient: # pylint: disable=too-many-public-methods
headers=self._get_request_headers(),
timeout=self._timeout,
)
if not expects_json:
return r
OpenstackClient._ensure_valid_response(r, error_message)
logger.debug('Result: %s', r.json())
OpenstackClient._ensure_valid_response(r, error_message, expects_json=expects_json)
logger.debug('Result: %s', r.content)
return r
except Exception as e:
if i == len(found_endpoints) - 1:
@ -446,6 +446,7 @@ class OpenstackClient: # pylint: disable=too-many-public-methods
)
]
@decorators.cached(prefix='snps', timeout=consts.cache.SHORT_CACHE_TIMEOUT, key_helper=cache_key_helper)
def list_volume_snapshots(
self, volume_id: typing.Optional[dict[str, typing.Any]] = None
) -> list[openstack_types.VolumeSnapshotInfo]:
@ -859,15 +860,15 @@ class OpenstackClient: # pylint: disable=too-many-public-methods
path = endpoint + path
@staticmethod
def _ensure_valid_response(response: 'requests.Response', errMsg: typing.Optional[str] = None) -> None:
def _ensure_valid_response(
response: 'requests.Response', errMsg: typing.Optional[str] = None, expects_json: bool = True
) -> None:
if response.ok is False:
if not expects_json:
return # If not expecting json, simply return
try:
(
_,
err,
) = (
response.json().popitem()
) # Extract any key, in case of error is expected to have only one top key so this will work
# Extract any key, in case of error is expected to have only one top key so this will work
_, err = response.json().popitem()
msg = ': {message}'.format(**err)
errMsg = errMsg + msg if errMsg else msg
except (