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

Add integration test #9

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Integration tests

on:
pull_request:

jobs:
integration-tests:
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
secrets: inherit
with:
channel: 1.28-strict/stable
modules: '["test_charm.py"]'
juju-channel: 3.1/stable
self-hosted-runner: true
self-hosted-runner-label: "xlarge"
microk8s-addons: "dns ingress rbac storage metallb:10.15.119.2-10.15.119.4 registry"
5 changes: 3 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from charm_helpers import create_env
from literals import (
AIRBYTE_API_PORT,
BUCKET_CONFIGS,
CONNECTOR_BUILDER_SERVER_API_PORT,
CONTAINERS,
Expand Down Expand Up @@ -282,8 +283,7 @@ def _update(self, event):
self.unit.status = BlockedStatus(f"failed to create buckets: {str(e)}")
return

env = create_env(self.model.name, self.app.name, self.config, self._state)
self.model.unit.set_ports(INTERNAL_API_PORT, CONNECTOR_BUILDER_SERVER_API_PORT)
self.model.unit.set_ports(AIRBYTE_API_PORT, INTERNAL_API_PORT, CONNECTOR_BUILDER_SERVER_API_PORT)

for container_name in list(CONTAINERS.keys()):
container = self.unit.get_container(container_name)
Expand All @@ -303,6 +303,7 @@ def _update(self, event):
permissions=0o755,
)

env = create_env(self.model.name, self.app.name, container_name, self.config, self._state)
pebble_layer = get_pebble_layer(container_name, env)
container.add_layer(container_name, pebble_layer, combine=True)
container.replan()
Expand Down
7 changes: 6 additions & 1 deletion src/charm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
from structured_config import StorageType


def create_env(model_name, app_name, config, state):
def create_env(model_name, app_name, container_name, config, state):
"""Create set of environment variables for application.

Args:
model_name: Name of the juju model.
app_name: Name of the application.
container_name: Name of Airbyte container.
config: Charm config.
state: Charm state.

Expand Down Expand Up @@ -70,6 +71,10 @@ def create_env(model_name, app_name, config, state):
"AIRBYTE_URL": config["webapp-url"],
}

# https://github.com/airbytehq/airbyte/issues/29506#issuecomment-1775148609
if container_name == "airbyte-api-server":
env.update({"INTERNAL_API_HOST": f"http://{app_name}:{INTERNAL_API_PORT}"})

if config["storage-type"].value == StorageType.minio and state.minio:
minio_endpoint = construct_svc_endpoint(
state.minio["service"],
Expand Down
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Tests module."""
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for jenkins-k8s charm tests."""

import pytest


def pytest_addoption(parser: pytest.Parser):
"""Parse additional pytest options.

Args:
parser: pytest command line parser.
"""
# The prebuilt charm file.
parser.addoption("--charm-file", action="append", default=[])
61 changes: 61 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

"""Charm integration test config."""

import asyncio
import logging

import pytest_asyncio
from helpers import (
APP_NAME_AIRBYTE_SERVER,
APP_NAME_TEMPORAL_ADMIN,
APP_NAME_TEMPORAL_SERVER,
create_default_namespace,
get_airbyte_charm_resources,
perform_airbyte_integrations,
perform_temporal_integrations,
run_sample_workflow,
)
from pytest_operator.plugin import OpsTest

logger = logging.getLogger(__name__)


@pytest_asyncio.fixture(name="deploy", scope="module")
async def deploy(ops_test: OpsTest):
"""Test the app is up and running."""
await ops_test.model.set_config({"update-status-hook-interval": "1m"})

charm = await ops_test.build_charm(".")
resources = get_airbyte_charm_resources()

await ops_test.model.deploy(charm, resources=resources, application_name=APP_NAME_AIRBYTE_SERVER, trust=True)
await ops_test.model.deploy(
APP_NAME_TEMPORAL_SERVER,
channel="edge",
config={"num-history-shards": 4},
)
await ops_test.model.deploy(APP_NAME_TEMPORAL_ADMIN, channel="edge")
await ops_test.model.deploy("postgresql-k8s", channel="14/edge", trust=True)
await ops_test.model.deploy("minio", channel="edge")

async with ops_test.fast_forward():
kelkawi-a marked this conversation as resolved.
Show resolved Hide resolved
await ops_test.model.wait_for_idle(
apps=["postgresql-k8s", "minio"],
status="active",
raise_on_blocked=False,
timeout=1200,
)
await ops_test.model.wait_for_idle(
apps=[APP_NAME_TEMPORAL_SERVER, APP_NAME_TEMPORAL_ADMIN],
status="blocked",
raise_on_blocked=False,
timeout=600,
)

await perform_temporal_integrations(ops_test)
await create_default_namespace(ops_test)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have to create the default namespace manually, isn't the relation between temporal and airbyte going to create a namespace?

Copy link
Collaborator Author

@kelkawi-a kelkawi-a Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's currently no relation between Temporal and Airbyte charms, so this step needs to be done manually.

await run_sample_workflow(ops_test)

await perform_airbyte_integrations(ops_test)
Loading
Loading