Skip to content

Commit

Permalink
Merge pull request #350 from linode/dev
Browse files Browse the repository at this point in the history
Release v0.15.2
  • Loading branch information
zliang-akamai authored May 2, 2023
2 parents 22593ac + 55ecfde commit 0b26f80
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 17 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/acctest_command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
steps:
- name: Generate App Installation Token
id: generate_token
uses: tibdex/github-app-token@f717b5ecd4534d3c4df4ce9b5c1c2214f0f7cd06 # pin@v1
with:
app_id: ${{ secrets.DX_ACCTEST_APP_ID }}
private_key: ${{ secrets.DX_ACCTEST_PRIV_KEY }}

- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@ace7a198016ae74cd286677c7e7f7e266eb18bc4 # pin@v1
env:
TOKEN: ${{ steps.generate_token.outputs.token }}
uses: peter-evans/slash-command-dispatch@v1.2.0
with:
token: ${{ env.TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
issue-type: pull-request
commands: acctest
named-args: true
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/integration-tests-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ jobs:
if:
github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.sha != '' &&
github.event.client_payload.slash_command.tests != '' &&
github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.sha

steps:
- uses: actions-ecosystem/action-regex-match@v2
id: validate-tests
id: disallowed-char-check
with:
text: ${{ github.event.client_payload.slash_command.tests }}
regex: '[^a-z0-9_]'
Expand Down Expand Up @@ -58,7 +57,7 @@ jobs:
run: rm -rf ~/.ansible/test && mkdir -p ~/.ansible/test && ssh-keygen -m PEM -q -t rsa -N '' -f ~/.ansible/test/id_rsa

- run: make deps && make TEST_ARGS="-v ${{ github.event.client_payload.slash_command.tests }}" test
if: ${{ steps.validate-tests.outputs.match == '' }}
if: ${{ steps.disallowed-char-check.outputs.match == '' }}
env:
LINODE_API_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions docs/modules/volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Manage a Linode Volume.
| `attached` | <center>`bool`</center> | <center>Optional</center> | If true, the volume will be attached to a Linode. Otherwise, the volume will be detached. **(Default: `True`; Updatable)** |
| `wait_timeout` | <center>`int`</center> | <center>Optional</center> | The amount of time, in seconds, to wait for a volume to have the active status. **(Default: `240`)** |
| `source_volume_id` | <center>`int`</center> | <center>Optional</center> | The volume id of the desired volume to clone. |
| `tags` | <center>`list`</center> | <center>Optional</center> | The tags to be attached to the volume. |

## Return Values

Expand Down
14 changes: 13 additions & 1 deletion plugins/modules/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

from __future__ import absolute_import, division, print_function

import ast
import contextlib

# pylint: disable=unused-import
import json
from typing import Any, Optional, Tuple
Expand Down Expand Up @@ -99,6 +102,15 @@ def __init__(self) -> None:
mutually_exclusive=[("body", "body_json")],
)

@staticmethod
def _parse_body_json(body_content: str) -> dict:
with contextlib.suppress(Exception):
# If this is a Python dict literal, parse and return
result = ast.literal_eval(body_content)
return result

return json.loads(body_content)

def do_request(
self, method: str, path: str, filters: dict = None, body: dict = None
) -> Tuple[int, Optional[dict]]:
Expand Down Expand Up @@ -138,7 +150,7 @@ def exec_module(self, **kwargs: Any) -> Optional[dict]:
if param_body is not None:
request_body = param_body
elif param_body_json is not None:
request_body = json.loads(param_body_json)
request_body = self._parse_body_json(param_body_json)

response_status, response_json = self.do_request(
param_method, param_path, filters=param_filter, body=request_body
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
required=False,
description=["The volume id of the desired volume to clone."],
),
tags=SpecField(
type=FieldType.list,
required=False,
description=["The tags to be attached to the volume."],
),
)

SPECDOC_META = SpecDocMeta(
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ botocore==1.20.23
pylint==2.15.5
ansible-doc-extractor==0.1.9
mypy==1.2.0
ansible==7.4.0
ansible==7.5.0
Jinja2==3.0.1
black>=23.1.0
isort>=5.12.0
Expand Down
48 changes: 48 additions & 0 deletions tests/integration/targets/api_request_extra/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# this test is to test a json_body with integer inside as a value of a key

- name: api_request_extra
block:
- set_fact:
r: "{{ 1000000000 | random }}"

- name: List all available Linode regions
linode.cloud.region_list:
register: regions

- name: Create a volume by the api_request module
linode.cloud.api_request:
path: "/volumes"
method: POST
body_json: >
{
"label": "ansible-test-{{ r }}",
"size": 10,
"region": "{{ regions.regions[0].id }}"
}
register: response

- name: Assert volume created
assert:
that:
- response.changed

always:
- ignore_errors: true
block:
- name: Delete the volume
linode.cloud.volume:
label: '{{ response.body.label }}'
state: absent
register: delete_volume
until: delete_volume.changed
retries: 5
delay: 10

- name: Assert the volume was deleted
assert:
that:
- delete_volume.changed

environment:
LINODE_UA_PREFIX: '{{ ua_prefix }}'
LINODE_API_TOKEN: '{{ api_token }}'

0 comments on commit 0b26f80

Please sign in to comment.