Skip to content

Commit

Permalink
Merge branch 'dev' into TPT-3085-add-authorized-users-to-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai authored Nov 25, 2024
2 parents f2d2511 + f26d3a5 commit 9ca1dc0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: setup python 3
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: '3.10'

- name: install dependencies
run: make deps
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install: build
ansible-galaxy collection install *.tar.gz --force -p $(COLLECTIONS_PATH)

deps:
pip install -r requirements.txt -r requirements-dev.txt --upgrade
pip install -r requirements.txt -r requirements-dev.txt --force

lint:
pylint plugins
Expand Down
3 changes: 1 addition & 2 deletions plugins/module_utils/linode_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import polling
from ansible_collections.linode.cloud.plugins.module_utils.linode_helper import (
format_api_error,
format_generic_error,
)

Expand Down Expand Up @@ -159,7 +158,7 @@ def __init__(
res = self.exec_module(**self.module.params)
except ApiError as err:
# We don't want to return a stack trace for an API error
self.fail(msg=format_api_error(err))
self.fail(msg=f"Error from Linode API: {str(err)}")
except polling.TimeoutException as err:
self.fail(
msg="failed to wait for condition: timeout period expired"
Expand Down
7 changes: 0 additions & 7 deletions plugins/module_utils/linode_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import linode_api4
import polling
from linode_api4 import (
ApiError,
LinodeClient,
LKENodePool,
LKENodePoolNode,
Expand Down Expand Up @@ -329,12 +328,6 @@ def get_all_paginated(
return result


def format_api_error(err: ApiError) -> str:
"""Formats an API error into a readable string"""

return f"Error from Linode API: [{err.status}] {';'.join(err.errors)}"


def format_generic_error(err: Exception) -> str:
"""Formats a generic error into a readable string"""

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
linode-api4>=5.22.0
linode-api4>=5.24.0
polling==0.3.2
ansible-specdoc>=0.0.15
24 changes: 24 additions & 0 deletions tests/integration/targets/api_error/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: api_error
block:
- name: Attempt to create an instance with validation errors
linode.cloud.instance:
region: fake-region
type: g6-fake-plan
state: present
register: failing_request
failed_when: '"msg" not in failing_request'

- name: Ensure the error message is formatted as expected
assert:
that:
- failing_request.changed == False
- 'failing_request.msg.startswith("Error from Linode API: POST /v4beta/linode/instances: [400]")'
- '"type: A valid plan type by that ID was not found" in failing_request.msg'
- '"region: region is not valid" in failing_request.msg'

environment:
LINODE_UA_PREFIX: '{{ ua_prefix }}'
LINODE_API_TOKEN: '{{ api_token }}'
LINODE_API_URL: '{{ api_url }}'
LINODE_API_VERSION: '{{ api_version }}'
LINODE_CA: '{{ ca_file or "" }}'

0 comments on commit 9ca1dc0

Please sign in to comment.