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 e7fd3c0
Show file tree
Hide file tree
Showing 24 changed files with 409 additions and 624 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
2 changes: 1 addition & 1 deletion plugins/module_utils/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_exactly_one(
self, endpoint, name=None, **kwargs
) -> Optional[dict[str, bool]]:
result = self.get_one_or_many(
endpoint, name=name, allow_none=False, want_one=True, **kwargs
endpoint, name=name, allow_none=True, want_one=True, **kwargs
)
# typing: needed as get_one_or_many can also return lists, not expected
# to reach this ever.
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def lookup(module: AnsibleModule, controller: Controller, endpoint, name):


def create_params(module: AnsibleModule, controller: Controller) -> dict[str, Any]:
activation_params = {}
activation_params: dict[str, Any] = {}

# Get the project id
project_id = None
Expand Down 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 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
51 changes: 16 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 @@ -87,10 +83,10 @@
- name: Read the generated key
set_fact:
ssh_key_data: "{{ lookup('file', tempdir.stdout + '/id_rsa') }}"
no_log: true

- 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 +106,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 +122,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 +131,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 +149,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 +166,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 +184,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 +203,6 @@

- name: Delete credential
ansible.eda.credential:
<<: *credential_defaults
name: "{{ credential_name }}"
state: absent
register: credential_deletion
Expand All @@ -228,49 +215,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 e7fd3c0

Please sign in to comment.