Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit backoff on wait_for_tenant just for 404 errors. #126

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions threescale_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ def wait_for_tenant(self) -> bool:
# ultimate readiness check. There might be duplicates though, so
# worth to review it one day
try:
return self.account_plans.exists() \
return self.account_plans.exists(throws=True) \
and len(self.account_plans.fetch()["plans"]) >= 1 \
and len(self.account_plans.list()) >= 1 \
and self.accounts.exists() \
and self.accounts.exists(throws=True) \
and len(self.accounts.list()) >= 1 \
and self.services.exists() \
and self.services.exists(throws=True) \
and len(self.services.list()) >= 1
except errors.ApiClientError as err:
if err.code in (404, 503):
log.info("wait_for_tenant failed: %s", err)
return False
raise err
except Exception as err:
log.info("wait_for_tenant failed: %s", err)
return False
Expand Down
4 changes: 2 additions & 2 deletions threescale_api/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def delete(self, entity_id: int = None, **kwargs) -> bool:
response = self.rest.delete(url=url, **kwargs)
return response.ok

def exists(self, entity_id=None, **kwargs) -> bool:
def exists(self, entity_id=None, throws=False, **kwargs) -> bool:
"""Check whether the resource exists
Args:
entity_id(int): Entity id
Expand All @@ -101,7 +101,7 @@ def exists(self, entity_id=None, **kwargs) -> bool:
"""
log.info(self._log_message("[EXIST] Resource exist ", entity_id=entity_id, args=kwargs))
url = self._entity_url(entity_id=entity_id)
response = self.rest.get(url=url, throws=False, **kwargs)
response = self.rest.get(url=url, throws=throws, **kwargs)
return response.ok

def update(self, entity_id=None, params: dict = None, **kwargs) -> 'DefaultResource':
Expand Down