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

dep: Bump linode_api4 -> v5.5.0 and remove legacy request retry helper #365

Merged
merged 7 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion plugins/module_utils/linode_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def client(self) -> LinodeClient:
api_token,
base_url="https://api.linode.com/{0}".format(api_version),
user_agent=user_agent,
retry_rate_limit_interval=10,
retry_rate_limit_interval=10.0,
)

return self._client
36 changes: 0 additions & 36 deletions plugins/module_utils/linode_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module contains helper functions for various Linode modules."""
import math
import time
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, cast

import linode_api4
Expand Down Expand Up @@ -205,41 +204,6 @@ def validate_required(required_fields: Set[str], params: Dict[str, Any]):
raise Exception("missing fields: {}".format(", ".join(missing_fields)))


def request_retry(
request_func: Callable,
retry_statuses=None,
retry_interval=RETRY_INTERVAL_SECONDS,
max_retries=MAX_RETRIES,
) -> any:
"""Retries requests if the response status code matches the retry_statuses set."""
# Default value for set
if retry_statuses is None:
retry_statuses = RETRY_STATUSES

number_attempts = 0

while number_attempts < max_retries:
number_attempts += 1

try:
response = request_func()
except ApiError as exception:
if exception.status not in retry_statuses:
raise exception

time.sleep(retry_interval)

continue
except Exception as exception:
raise exception

return response

raise Exception(
"exceeded maximum number of retries: {0}".format(max_retries)
)


def filter_null_values_recursive(obj: Any) -> Any:
"""Recursively removes null values and keys from a structure."""
if isinstance(obj, dict):
Expand Down
5 changes: 1 addition & 4 deletions plugins/modules/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
filter_null_values_recursive,
paginated_list_to_json,
parse_linode_types,
request_retry,
)
from ansible_specdoc.objects import (
FieldType,
Expand Down Expand Up @@ -579,9 +578,7 @@ def _create_instance(self) -> dict:
result = {"instance": None, "root_pass": ""}

# We want to retry on 408s
response = request_retry(
lambda: self.client.linode.instance_create(ltype, region, **params)
)
response = self.client.linode.instance_create(ltype, region, **params)

# Weird variable return type
if isinstance(response, tuple):
Expand Down
11 changes: 3 additions & 8 deletions plugins/modules/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
from ansible_collections.linode.cloud.plugins.module_utils.linode_event_poller import (
EventPoller,
)
from ansible_collections.linode.cloud.plugins.module_utils.linode_helper import (
request_retry,
)
from ansible_specdoc.objects import (
FieldType,
SpecDocMeta,
Expand Down Expand Up @@ -216,11 +213,9 @@ def _clone_volume(self) -> Volume:
)

# Perform the clone operation
vol = request_retry(
lambda: self.client.post(
"/volumes/{}/clone".format(source_id),
data={"label": params.get("label")},
)
vol = self.client.post(
"/volumes/{}/clone".format(source_id),
data={"label": params.get("label")},
)

cloned_volume = Volume(self.client, vol.get("id"))
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
linode-api4==5.4.0
polling==0.3.2
types-requests==2.30.0.0
ansible-specdoc==0.0.13
linode-api4>=5.5.0
polling>=0.3.2
types-requests>=2.30.0.0
ansible-specdoc>=0.0.13
4 changes: 2 additions & 2 deletions tests/integration/targets/firewall_basic/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
label: 'ansible-test-{{ r }}'
region: us-southeast
type: g6-standard-1
image: linode/alpine3.13
image: linode/alpine3.17
state: present
register: create_instance

Expand All @@ -16,7 +16,7 @@
label: 'ansible-test-{{ r }}-2'
region: us-southeast
type: g6-standard-1
image: linode/alpine3.13
image: linode/alpine3.17
state: present
register: create_instance_2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
label: 'ansible-test-{{ r }}'
region: us-southeast
type: g6-standard-1
image: linode/alpine3.13
image: linode/alpine3.17
state: present
register: inst

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
label: '{{ create.instance.label }}'
region: us-east
type: g6-standard-1
image: linode/alpine3.13
image: linode/alpine3.17
booted: false
disks:
- label: test-disk
Expand All @@ -179,7 +179,7 @@

- label: boot-disk
size: 4096
image: linode/alpine3.13
image: linode/alpine3.17

configs:
- label: boot-config
Expand Down