Skip to content

Commit

Permalink
licensing: Fix error log when deleting reservation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristi1324 authored and Dany9966 committed Jul 17, 2024
1 parent 6869302 commit 2058634
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions coriolis/licensing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit 2058634

Please sign in to comment.