Skip to content

Commit

Permalink
Rename webhooks option to event_streams
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Sep 10, 2024
1 parent 5659368 commit 5994658
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 38 deletions.
30 changes: 11 additions & 19 deletions plugins/modules/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@
- This parameter is supported in AAP 2.5 and onwards.
If specified for AAP 2.4, value will be ignored.
type: str
webhooks:
description:
- A list of webhook IDs associated with the rulebook activation.
- This parameter is supported in AAP 2.5 and onwards.
If specified for AAP 2.4, value will be ignored.
type: list
elements: str
swap_single_source:
description:
- Allow swapping of single sources in a rulebook without name match.
Expand Down Expand Up @@ -260,16 +253,16 @@ def create_params(
if not is_aap_24 and module.params.get("k8s_service_name"):
activation_params["k8s_service_name"] = module.params["k8s_service_name"]

# Get the webhook ids
webhooks_ids = None
if not is_aap_24 and module.params.get("webhooks"):
webhooks_ids = []
for item in module.params["webhooks"]:
webhook_id = lookup_resource_id(module, controller, "webhooks", item)
if webhook_id is not None:
webhooks_ids.append(webhook_id)
if webhooks_ids is not None:
activation_params["webhooks"] = webhooks_ids
# Get the event stream ids
event_stream_ids = None
if not is_aap_24 and module.params.get("event-streams"):
event_stream_ids = []
for item in module.params["event_streams"]:
event_stream_id = lookup_resource_id(module, controller, "event-streams", item)
if event_stream_id is not None:
event_stream_ids.append(event_stream_id)
if event_stream_ids is not None:
activation_params["event_streams"] = event_stream_ids

if not is_aap_24 and module.params.get("log_level"):
activation_params["log_level"] = module.params["log_level"]
Expand Down Expand Up @@ -300,10 +293,9 @@ def main() -> None:
decision_environment_name=dict(type="str", aliases=["decision_environment"]),
awx_token_name=dict(type="str", aliases=["awx_token", "token"]),
organization_name=dict(type="str", aliases=["organization"]),
event_streams=dict(type="list", elements="int"),
eda_credentials=dict(type="list", elements="str", aliases=["credentials"]),
k8s_service_name=dict(type="str"),
webhooks=dict(type="list", elements="str"),
event_streams=dict(type="list", elements="str"),
swap_single_source=dict(type="bool", default=True),
log_level=dict(type="str", choices=["debug", "info", "error"], default="debug"),
state=dict(choices=["present", "absent"], default="present"),
Expand Down
3 changes: 1 addition & 2 deletions plugins/modules/activation_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@
"modified_at": "2024-08-15T11:45:00.987Z",
"status_message": "Activation is running successfully.",
"awx_token_id": 1,
"event_streams": [],
"log_level": "info",
"eda_credentials": [],
"k8s_service_name": "",
"webhooks": [],
"event_streams": [],
"swap_single_source": false
}
]
Expand Down
85 changes: 68 additions & 17 deletions tests/integration/targets/activation/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
image_url: "quay.io/ansible/awx:latest"
scm_url: https://github.com/ansible/event-driven-ansible.git
rulebook_name: "demo_controller_rulebook.yml"
event_stream_name: "Test_EvenStream_{{ test_id }}"
credential_name_basic: "Test_CredentialBasic_{{ test_id }}"

- name: Create an AWX controller token
ansible.eda.controller_token:
Expand Down Expand Up @@ -189,6 +191,51 @@
- name: List all the rulebook activations
ansible.eda.activation_info:

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

# Test event_streams option
- name: Create a new credential
ansible.eda.credential:
state: present
name: "{{ credential_name_basic }}"
description: "This is a test credential"
credential_type_name: "Basic Event Stream"
inputs:
username: "test"
password: "test"
organization_name: Default
register: _result

- name: Create an event stream
ansible.eda.event_stream:
state: present
name: "{{ event_stream_name }}"
credential_name: "{{ credential_name_basic }}"
organization_name: Default
register: _result

- name: Create a rulebook activation
ansible.eda.activation:
name: "{{ activation_name }}"
description: "Example Activation description"
project_name: "{{ project_name }}"
rulebook_name: "{{ rulebook_name }}"
decision_environment_name: "{{ decision_env_name }}"
enabled: False
awx_token_name: "{{ awx_token_name }}"
organization_name: Default
event_streams:
- "{{ event_stream_name }}"
register: _result

- name: Check rulebook activation creation
assert:
that:
- _result.changed

- name: Delete project
ansible.eda.project:
name: "{{ project_name }}"
Expand All @@ -213,11 +260,6 @@
- credential_deletion is changed
- credential_deletion is success

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

always:
- name: Delete AWX token
ansible.eda.controller_token:
Expand All @@ -231,18 +273,6 @@
state: absent
ignore_errors: true

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

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

- name: Delete rulebook activation
ansible.eda.activation:
name: "{{ activation_name }}"
Expand All @@ -254,3 +284,24 @@
name: "{{ decision_env_name }}"
state: absent
ignore_errors: true

- name: Delete event stream
ansible.eda.event_stream:
name: "{{ event_stream_name }}"
state: absent
ignore_errors: true

- name: Delete credentials
ansible.eda.credential:
name: "{{ item }}"
state: absent
loop:
- "{{ credential_name }}"
- "{{ credential_name_basic }}"
ignore_errors: true

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

0 comments on commit 5994658

Please sign in to comment.