Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run integration tests in CI #274

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
28 changes: 27 additions & 1 deletion plugins/modules/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
description:
- The name of the credential to associate with the project.
type: str
organization_name:
description:
- The name of the organization.
type: str
aliases:
- organization
state:
description:
- Desired state of the resource.
Expand All @@ -59,6 +65,7 @@
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 @@ -70,6 +77,7 @@
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 Expand Up @@ -98,12 +106,17 @@ def main() -> None:
description=dict(),
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", "url", "organization_name"))]

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 @@ -158,6 +171,19 @@ def main() -> None:
# in the loop above
project_type_params["eda_credential_id"] = credential_id["id"]

organization_id = None
if module.params.get("organization_name"):
try:
organization_id = controller.resolve_name_to_id(
"organizations", module.params["organization_name"]
)
except EDAError as eda_err:
module.fail_json(msg=str(eda_err))
raise

if organization_id:
project_type_params["organization_id"] = organization_id

if new_name:
project_type_params["name"] = new_name
elif project_type:
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
4 changes: 4 additions & 0 deletions tests/integration/integration_config.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
controller_host: "https://localhost:8443"
controller_username: "admin"
controller_password: "testpass"
controller_verify_ssl: false
Loading
Loading