Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:linode/linode-cli into new/ips-list-…
Browse files Browse the repository at this point in the history
…override
  • Loading branch information
lgarber-akamai committed Aug 18, 2023
2 parents 0d3900c + de14732 commit a3c40c6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions linodecli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from .cli import CLI
from .completion import bake_completions, get_completions
from .configuration import ENV_TOKEN_NAME
from .helpers import handle_url_overrides
from .output import OutputMode

Expand Down
12 changes: 4 additions & 8 deletions linodecli/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ def do_request(
if ctx.debug_request:
_print_response_debug_info(result)

if _check_retry(result) and ctx.no_retry and ctx.retry_count < 3:
while _check_retry(result) and not ctx.no_retry and ctx.retry_count < 3:
time.sleep(_get_retry_after(result.headers))
ctx.retry_count += 1
do_request(ctx, operation, args, filter_header, skip_error_handling)
result = method(url, headers=headers, data=body, verify=API_CA_PATH)

_attempt_warn_old_version(ctx, result)

Expand Down Expand Up @@ -376,16 +376,12 @@ def _check_retry(response):
# request timed out or rate limit exceeded
return True

if (
return (
response.headers
and response.status_code == 400
and response.headers.get("Server") == "nginx"
and response.headers.get("Content-Type") == "text/html"
):
# nginx html response
return True

return False
)


def _get_retry_after(headers):
Expand Down
3 changes: 2 additions & 1 deletion linodecli/baked/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,15 @@ def __init__(self, response):
)
else:
self.attrs = _parse_response_model(response.schema)
self.rows = response.schema.extensions.get("linode-cli-rows")
self.rows = response.extensions.get("linode-cli-rows")
self.nested_list = response.extensions.get("linode-cli-nested-list")
self.subtables = response.extensions.get("linode-cli-subtables")

def fix_json(self, json):
"""
Formats JSON from the API into a list of rows
"""

if self.rows:
return self._fix_json_rows(json)
if self.nested_list:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def json_func():
output = stderr_buf.getvalue()
assert "" == output

def test_do_request_recursion(self, mock_cli, list_operation):
def test_do_request_retry(self, mock_cli, list_operation):
mock_response = Mock(status_code=408)
with patch(
"linodecli.api_request.requests.get", return_value=mock_response
Expand Down

0 comments on commit a3c40c6

Please sign in to comment.