Skip to content

Commit

Permalink
Run integration tests in CI (#274)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Alina Buzachis <[email protected]>
Co-authored-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
alinabuzachis and Akasurde authored Aug 21, 2024
1 parent 94a3a71 commit 858f415
Show file tree
Hide file tree
Showing 34 changed files with 673 additions and 574 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ testuser
toxinidir
trustore
truststore
testpass
77 changes: 77 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Run integration tests
on:
pull_request:
types:
- opened
- reopened
- labeled
- unlabeled
- synchronize
branches:
- main
- stable-*
schedule:
- cron: '0 */8 * * *'

jobs:
integration-tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version:
- "3.11"
ansible-version:
- "milestone"

steps:
- name: Checkout ansible/eda
uses: actions/checkout@v3
with:
path: ansible_collections/ansible/eda
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: "0"

- name: Checkout ansible/eda-server
uses: actions/checkout@v3
with:
repository: ansible/eda-server
path: eda-server # Note: Specify a separate path for this repository

- name: Run API in background
run: |
docker compose -p eda -f docker-compose-stage.yaml pull
docker compose -p eda -f docker-compose-stage.yaml up -d
until curl -s http://localhost:8000/_healthz | grep -q "OK"; do
echo "Waiting for API to be ready..."
sleep 1
done
working-directory: eda-server/tools/docker # Adjusted to the specific directory where docker-compose.yaml is located

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install ansible-core (${{ matrix.ansible-version }})
run: >-
python3 -m pip install
https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz
--disable-pip-version-check
shell: bash

- name: Print the ansible version
run: ansible --version

- name: Create integration_config.yml
run: |
touch tests/integration/integration_config.yml
echo "controller_host: 'https://localhost:8443'" >> tests/integration/integration_config.yml
echo "controller_username: 'admin'" >> tests/integration/integration_config.yml
echo "controller_password: 'testpass'" >> tests/integration/integration_config.yml
echo "controller_verify_ssl: false" >> tests/integration/integration_config.yml
working-directory: ansible_collections/ansible/eda

- name: Run integration tests
run: ansible-test integration -v
working-directory: ansible_collections/ansible/eda
9 changes: 5 additions & 4 deletions docs/rst/credential_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ Parameters

<div class="ansible-option-cell">
<div class="ansibleOptionAnchor" id="parameter-organization_name"></div>
<div class="ansibleOptionAnchor" id="parameter-org_name"></div>
<div class="ansibleOptionAnchor" id="parameter-organization"></div>

.. _ansible_collections.ansible.eda.credential_module__parameter-org_name:
.. _ansible_collections.ansible.eda.credential_module__parameter-organization:
.. _ansible_collections.ansible.eda.credential_module__parameter-organization_name:

.. rst-class:: ansible-option-title
Expand All @@ -385,9 +385,9 @@ Parameters

.. ansible-option-type-line::

:ansible-option-aliases:`aliases: org_name`
:ansible-option-aliases:`aliases: organization`

:ansible-option-type:`integer`
:ansible-option-type:`string`

.. raw:: html

Expand Down Expand Up @@ -565,6 +565,7 @@ Examples
inputs:
field1: "field1"
credential_type_name: "GitLab Personal Access Token"
organization_name: Default

- name: Delete an EDA Credential
ansible.eda.credential:
Expand Down
40 changes: 40 additions & 0 deletions docs/rst/decision_environment_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,44 @@ Parameters
Setting this option will change the existing name.


.. raw:: html

</div>

* - .. raw:: html

<div class="ansible-option-cell">
<div class="ansibleOptionAnchor" id="parameter-organization_name"></div>
<div class="ansibleOptionAnchor" id="parameter-organization"></div>

.. _ansible_collections.ansible.eda.decision_environment_module__parameter-organization:
.. _ansible_collections.ansible.eda.decision_environment_module__parameter-organization_name:

.. rst-class:: ansible-option-title

**organization_name**

.. raw:: html

<a class="ansibleOptionLink" href="#parameter-organization_name" title="Permalink to this option"></a>

.. ansible-option-type-line::

:ansible-option-aliases:`aliases: organization`

:ansible-option-type:`string`

.. raw:: html

</div>

- .. raw:: html

<div class="ansible-option-cell">

The name of the organization.


.. raw:: html

</div>
Expand Down Expand Up @@ -529,6 +567,7 @@ Examples
description: "Example Decision Environment description"
image_url: "quay.io/test"
credential: "Example Credential"
organization_name: Default
state: present

- name: Update the name of the Decision Environment
Expand All @@ -538,6 +577,7 @@ Examples
controller_password: MySuperSecretPassw0rd
name: "Example Decision Environment"
new_name: "Latest Example Decision Environment"
organization_name: Default
state: present

- name: Delete the the Decision Environment
Expand Down
40 changes: 40 additions & 0 deletions docs/rst/project_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,44 @@ Parameters
Setting this option will change the existing name.


.. raw:: html

</div>

* - .. raw:: html

<div class="ansible-option-cell">
<div class="ansibleOptionAnchor" id="parameter-organization_name"></div>
<div class="ansibleOptionAnchor" id="parameter-organization"></div>

.. _ansible_collections.ansible.eda.project_module__parameter-organization:
.. _ansible_collections.ansible.eda.project_module__parameter-organization_name:

.. rst-class:: ansible-option-title

**organization_name**

.. raw:: html

<a class="ansibleOptionLink" href="#parameter-organization_name" title="Permalink to this option"></a>

.. ansible-option-type-line::

:ansible-option-aliases:`aliases: organization`

:ansible-option-type:`string`

.. raw:: html

</div>

- .. raw:: html

<div class="ansible-option-cell">

The name of the organization.


.. raw:: html

</div>
Expand Down Expand Up @@ -528,6 +566,7 @@ Examples
name: "Example Project"
description: "Example project description"
url: "https://example.com/project1"
organization_name: Default
state: present

- name: Update the name of the project
Expand All @@ -539,6 +578,7 @@ Examples
new_name: "Latest Example Project"
description: "Example project description"
url: "https://example.com/project1"
organization_name: Default
state: present

- name: Delete the project
Expand Down
6 changes: 6 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ action_groups:
eda:
- activation
- activation_info
- controller_token
- credential
- credential_info
- credential_type
- credential_type_info
- decision_environment
- decision_environment_info
- project
- project_info
- user
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
8 changes: 6 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,11 @@ 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
17 changes: 12 additions & 5 deletions plugins/modules/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
organization_name:
description:
- The name of the organization.
type: int
type: str
aliases:
- org_name
- organization
description:
description:
- Description of the credential.
Expand All @@ -67,6 +67,7 @@
inputs:
field1: "field1"
credential_type_name: "GitLab Personal Access Token"
organization_name: Default
- name: Delete an EDA Credential
ansible.eda.credential:
Expand Down Expand Up @@ -108,13 +109,19 @@ def main() -> None:
description=dict(type="str"),
inputs=dict(type="dict"),
credential_type_name=dict(type="str"),
organization_name=dict(type="int", aliases=["org_name"]),
organization_name=dict(type="str", aliases=["organization"]),
state=dict(choices=["present", "absent"], default="present"),
)

argument_spec.update(AUTH_ARGSPEC)

required_if = [("state", "present", ("name", "credential_type_name", "inputs"))]
required_if = [
(
"state",
"present",
("name", "credential_type_name", "inputs", "organization_name"),
)
]

module = AnsibleModule(
argument_spec=argument_spec, required_if=required_if, supports_check_mode=True
Expand Down Expand Up @@ -154,7 +161,7 @@ def main() -> None:
credential_params["credential_type_id"] = credential_type_id

organization_id = None
if module.params.get("organization_id"):
if module.params.get("organization_name"):
organization_id = lookup(
module, controller, "organizations", module.params["organization_name"]
)
Expand Down
24 changes: 23 additions & 1 deletion plugins/modules/decision_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
default: "present"
choices: ["present", "absent"]
type: str
organization_name:
description:
- The name of the organization.
type: str
aliases:
- organization
extends_documentation_fragment:
- ansible.eda.eda_controller.auths
"""
Expand All @@ -60,6 +66,7 @@
description: "Example Decision Environment description"
image_url: "quay.io/test"
credential: "Example Credential"
organization_name: Default
state: present
- name: Update the name of the Decision Environment
Expand All @@ -69,6 +76,7 @@
controller_password: MySuperSecretPassw0rd
name: "Example Decision Environment"
new_name: "Latest Example Decision Environment"
organization_name: Default
state: present
- name: Delete the the Decision Environment
Expand Down Expand Up @@ -103,12 +111,17 @@ def main() -> None:
description=dict(),
image_url=dict(),
credential=dict(),
organization_name=dict(type="str", aliases=["organization"]),
state=dict(choices=["present", "absent"], default="present"),
)

argument_spec.update(AUTH_ARGSPEC)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_if = [("state", "present", ("name", "organization_name", "image_url"))]

module = AnsibleModule(
argument_spec=argument_spec, required_if=required_if, supports_check_mode=True
)

client = Client(
host=module.params.get("controller_host"),
Expand Down Expand Up @@ -166,6 +179,15 @@ def main() -> None:
# in the loop above
decision_environment_type_params["credential"] = credential_type["id"]

organization_id = None
if module.params.get("organization_name"):
organization_id = controller.resolve_name_to_id(
"organizations", module.params["organization_name"]
)

if organization_id:
decision_environment_type_params["organization_id"] = organization_id

if new_name:
decision_environment_type_params["name"] = new_name
elif decision_environment_type:
Expand Down
Loading

0 comments on commit 858f415

Please sign in to comment.