Skip to content

Commit

Permalink
Use module_defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Aug 20, 2024
1 parent 317a9d8 commit 0283c95
Show file tree
Hide file tree
Showing 23 changed files with 407 additions and 623 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ jobs:
working-directory: ansible_collections/ansible/eda

- name: Run integration tests
run: ansible-test integration project
run: ansible-test integration -v
working-directory: ansible_collections/ansible/eda
4 changes: 2 additions & 2 deletions plugins/modules/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def main() -> None:
argument_spec.update(AUTH_ARGSPEC)

required_if = [
("state", "present", ("name", "rulebook_name", "decision_environment_name"))
("state", "present", ("name", "rulebook_name", "decision_environment_name", "organization_name"))
]

module = AnsibleModule(
Expand All @@ -325,7 +325,7 @@ def main() -> None:

# Attempt to find rulebook activation based on the provided name
try:
activation = controller.get_exactly_one("activations", name=name)
activation = controller.get_one_or_many("activations", name=name)
except EDAError as e:
module.fail_json(msg=f"Failed to get rulebook activation: {e}")

Expand Down
9 changes: 2 additions & 7 deletions plugins/modules/project_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
# pylint: disable=relative-beyond-top-level
from ..module_utils.arguments import AUTH_ARGSPEC
from ..module_utils.client import Client
from ..module_utils.common import to_list_of_dict
from ..module_utils.controller import Controller
from ..module_utils.errors import EDAError

Expand All @@ -106,20 +107,14 @@ def main() -> None:

project_name = module.params.get("name")

ret: list[Any] = []

try:
result = controller.get_one_or_many(
project_endpoint, name=project_name, want_one=False
)
except EDAError as eda_err:
module.fail_json(msg=str(eda_err))

if result is None:
ret = []
if not isinstance(result, list):
ret = [result]
module.exit_json(projects=ret)
module.exit_json(projects=to_list_of_dict(result))


if __name__ == "__main__":
Expand Down
50 changes: 15 additions & 35 deletions tests/integration/targets/activation/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
---
- block:
- name: Set defaults for credentials
set_fact:
credential_defaults: &credential_defaults
controller_username: "{{ controller_username }}"
controller_password: "{{ controller_password }}"
controller_host: "{{ controller_host }}"
validate_certs: false
no_log: true

- name: Rulebook activation integration tests
module_defaults:
group/ansible.eda.eda:
controller_host: "{{ controller_host }}"
controller_username: "{{ controller_username }}"
controller_password: "{{ controller_password }}"
validate_certs: "{{ controller_verify_ssl }}"
block:
- name: Generate a random_string for the test
set_fact:
random_string: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
Expand All @@ -34,15 +32,13 @@

- name: Create an AWX controller token
ansible.eda.controller_token:
<<: *credential_defaults
name: "{{ awx_token_name }}"
description: "A test AWX controller token description"
token: "{{ token_value }}"
state: present

- name: Create a new credential type
ansible.eda.credential_type:
<<: *credential_defaults
name: "{{ credential_type_name }}"
state: present
description: "A test credential type"
Expand Down Expand Up @@ -90,7 +86,6 @@

- name: Create a new SCM credential
ansible.eda.credential:
<<: *credential_defaults
name: "{{ credential_name }}"
state: present
credential_type_name: Source Control
Expand All @@ -110,7 +105,6 @@

- name: Create a new project
ansible.eda.project:
<<: *credential_defaults
name: "{{ project_name }}"
description: "Test Project Description"
url: "{{ scm_url }}"
Expand All @@ -127,7 +121,6 @@

- name: Create a new decision environment
ansible.eda.decision_environment:
<<: *credential_defaults
name: "{{ decision_env_name }}"
description: "Test Decision Environment Description"
credential: "{{ credential_name }}"
Expand All @@ -137,7 +130,6 @@

- name: Create a new rulebook activation in check mode
ansible.eda.activation:
<<: *credential_defaults
name: "{{ activation_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -156,7 +148,6 @@

- name: Create a new rulebook activation
ansible.eda.activation:
<<: *credential_defaults
name: "{{ activation_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -174,7 +165,6 @@

- name: Create a new rulebook activation again
ansible.eda.activation:
<<: *credential_defaults
name: "{{ activation_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
Expand All @@ -193,16 +183,13 @@

- name: Get information about the rulebook activation
ansible.eda.activation_info:
<<: *credential_defaults
name: "{{ activation_name }}"

- name: List all the rulebook activations
ansible.eda.activation_info:
<<: *credential_defaults

- name: Delete project
ansible.eda.project:
<<: *credential_defaults
name: "{{ project_name }}"
state: absent
register: project_deletion
Expand All @@ -215,7 +202,6 @@

- name: Delete credential
ansible.eda.credential:
<<: *credential_defaults
name: "{{ credential_name }}"
state: absent
register: credential_deletion
Expand All @@ -228,49 +214,43 @@

- name: Delete rulebook activation
ansible.eda.activation:
<<: *credential_defaults
name: "{{ activation_name }}"
state: absent

always:
- name: Delete AWX token
ansible.eda.controller_token:
<<: *credential_defaults
name: "{{ awx_token_name }}"
state: absent
ignore_errors: true

- name: Delete project
ansible.eda.project:
<<: *credential_defaults
name: "{{ project_name }}"
state: absent
ignore_errors: true

- name: Delete decision environment
ansible.eda.decision_environment:
<<: *credential_defaults
name: "{{ decision_env_name }}"
state: absent
ignore_errors: true

- name: Delete credential
ansible.eda.credential:
<<: *credential_defaults
name: "{{ credential_name }}"
state: absent
ignore_errors: true

- name: Delete credential type
ansible.eda.credential_type:
<<: *credential_defaults
name: "{{ credential_type_name }}"
state: absent
ignore_errors: true

- name: Delete rulebook activation
ansible.eda.activation:
<<: *credential_defaults
name: "{{ activation_name }}"
state: absent
ignore_errors: true

- name: Delete decision environment
ansible.eda.decision_environment:
name: "{{ decision_env_name }}"
state: absent
ignore_errors: true

12 changes: 0 additions & 12 deletions tests/integration/targets/controller_token/tasks/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

- name: Create controller token in check mode
ansible.eda.controller_token:
controller_host: "{{ controller_host }}"
controller_username: "{{ controller_username }}"
controller_password: "{{ controller_password }}"
validate_certs: "{{ controller_verify_ssl }}"
name: "{{ controller_token_name }}"
description: "Example controller token description"
token: "TOKEN_VALUE"
Expand All @@ -23,10 +19,6 @@

- name: Create controller token
ansible.eda.controller_token:
controller_host: "{{ controller_host }}"
controller_username: "{{ controller_username }}"
controller_password: "{{ controller_password }}"
validate_certs: "{{ controller_verify_ssl }}"
name: "{{ controller_token_name }}"
description: "Example controller token description"
token: "TOKEN_VALUE"
Expand All @@ -42,10 +34,6 @@

- name: Create controller token again
ansible.eda.controller_token:
controller_host: "{{ controller_host }}"
controller_username: "{{ controller_username }}"
controller_password: "{{ controller_password }}"
validate_certs: "{{ controller_verify_ssl }}"
name: "{{ controller_token_name }}"
description: "Example controller token description"
token: "TOKEN_VALUE"
Expand Down
14 changes: 9 additions & 5 deletions tests/integration/targets/controller_token/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- block:
- name: Controller token integration tests
module_defaults:
group/ansible.eda.eda:
controller_host: "{{ controller_host }}"
controller_username: "{{ controller_username }}"
controller_password: "{{ controller_password }}"
validate_certs: "{{ controller_verify_ssl }}"

block:
- name: Generate a random_string for the test
set_fact:
random_string: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
Expand All @@ -21,10 +29,6 @@
always:
- name: Clean up - controller token
ansible.eda.controller_token:
controller_host: "{{ controller_host }}"
controller_username: "{{ controller_username }}"
controller_password: "{{ controller_password }}"
validate_certs: "{{ controller_verify_ssl }}"
name: "{{ item }}"
state: absent
loop:
Expand Down
Loading

0 comments on commit 0283c95

Please sign in to comment.