From 20586347e86817393a9e5f9d9f26f17262029094 Mon Sep 17 00:00:00 2001 From: Cristian Matiut Date: Tue, 16 Jul 2024 12:34:18 +0300 Subject: [PATCH] licensing: Fix error log when deleting reservation --- coriolis/licensing/client.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/coriolis/licensing/client.py b/coriolis/licensing/client.py index 8f45165a8..da291d632 100644 --- a/coriolis/licensing/client.py +++ b/coriolis/licensing/client.py @@ -69,6 +69,22 @@ def _get_url_for_appliance_resource(self, resource): return "%s/appliances/%s/%s" % ( self._base_url, self._appliance_id, resource.strip('/')) + def _raise_response_error(self, resp): + error = None + try: + error = resp.json().get('error', {}) + except (Exception, KeyboardInterrupt): + LOG.debug( + "Exception occured during error extraction from licensing " + "response: '%s'\nException:\n%s", + resp.text, utils.get_exception_details()) + if error and all([x in error for x in ['code', 'message']]): + raise exception.Conflict( + message=error['message'], + code=int(error['code'])) + else: + resp.raise_for_status() + @utils.retry_on_error() def _do_req( self, method_name, resource, body=None, @@ -98,21 +114,7 @@ def _do_req( return resp if not resp.ok: - # try to extract error from licensing server: - error = None - try: - error = resp.json().get('error', {}) - except (Exception, KeyboardInterrupt): - LOG.debug( - "Exception occured during error extraction from licensing " - "response: '%s'\nException:\n%s", - resp.text, utils.get_exception_details()) - if error and all([x in error for x in ['code', 'message']]): - raise exception.Conflict( - message=error['message'], - code=int(error['code'])) - else: - resp.raise_for_status() + self._raise_response_error(resp) resp_data = resp.json() if response_key: @@ -221,8 +223,8 @@ def delete_reservation(self, reservation_id, raise_on_404=False): if not resp.ok: if resp.status_code == 404: if raise_on_404: - resp.raise_for_status() + self._raise_response_error(resp) LOG.warn( "Got 404 when deleting reservation '%s'", reservation_id) else: - resp.raise_for_status() + self._raise_response_error(resp)