Skip to content

Commit

Permalink
Merge pull request #12915 from redpanda-data/cdt-handle-cloudv2-errors
Browse files Browse the repository at this point in the history
rptest: handle errors from cloudv2 and rethrow proper error messages
  • Loading branch information
savex authored Aug 23, 2023
2 parents 8908198 + e2c3218 commit c297f10
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions tests/rptest/services/redpanda_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def __init__(self, config, log):
self._config = config
self._token = None
self._logger = log
self.lasterror = None

def _handle_error(self, response):
try:
response.raise_for_status()
except requests.HTTPError as e:
self.lasterror = f'{e} {response.text}'
self._logger.error(self.lasterror)
return None
return response

def _get_token(self):
"""
Expand All @@ -45,11 +55,9 @@ def _get_token(self):
resp = requests.post(f'{self._config.oauth_url}',
headers=headers,
data=data)
try:
resp.raise_for_status()
except requests.HTTPError as e:
self._logger.error(f'{e} {resp.text}')
return None
_r = self._handle_error(resp)
if _r is None:
return _r
j = resp.json()
self._token = j['access_token']
return self._token
Expand All @@ -63,12 +71,8 @@ def _http_get(self, endpoint='', **kwargs):
resp = requests.get(f'{self._config.api_url}{endpoint}',
headers=headers,
**kwargs)
try:
resp.raise_for_status()
except requests.HTTPError as e:
self._logger.error(f'{e} {resp.text}')
return None
return resp.json()
_r = self._handle_error(resp)
return _r if _r is None else _r.json()

def _http_post(self, base_url=None, endpoint='', **kwargs):
token = self._get_token()
Expand All @@ -81,12 +85,8 @@ def _http_post(self, base_url=None, endpoint='', **kwargs):
resp = requests.post(f'{base_url}{endpoint}',
headers=headers,
**kwargs)
try:
resp.raise_for_status()
except requests.HTTPError as e:
self._logger.error(f'{e} {resp.text}')
return None
return resp.json()
_r = self._handle_error(resp)
return _r if _r is None else _r.json()

def _http_delete(self, endpoint='', **kwargs):
token = self._get_token()
Expand All @@ -97,12 +97,8 @@ def _http_delete(self, endpoint='', **kwargs):
resp = requests.delete(f'{self._config.api_url}{endpoint}',
headers=headers,
**kwargs)
try:
resp.raise_for_status()
except requests.HTTPError as e:
self._logger.error(f'{e} {resp.text}')
return None
return resp.json()
_r = self._handle_error(resp)
return _r if _r is None else _r.json()


@dataclass(kw_only=True)
Expand Down Expand Up @@ -468,6 +464,10 @@ def create(self,
r = self.cloudv2._http_post(
endpoint='/api/v1/workflows/network-cluster', json=_body)

# handle error on CloudV2 side
if r is None:
raise RuntimeError(self.cloudv2.lasterror)

self._logger.info(
f'waiting for creation of cluster {self.current.name} '
f'namespaceUuid {r["namespaceUuid"]}, checking every '
Expand Down

0 comments on commit c297f10

Please sign in to comment.