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

kfp-api: test #634

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
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
39 changes: 30 additions & 9 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- kfp-viewer
- kfp-viz
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: python3 -m pip install tox
- run: tox -e ${{ matrix.charm }}-lint

Expand All @@ -62,7 +62,7 @@ jobs:
- kfp-viewer
- kfp-viz
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: python3 -m pip install tox
- run: tox -e ${{ matrix.charm }}-unit

Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
- name: Maximise GH runner space
uses: jlumbroso/[email protected]

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
Expand All @@ -122,17 +122,22 @@ jobs:
# Pinned to 3.x/stable due to https://github.com/canonical/charmcraft/issues/1845
charmcraft-channel: 3.x/stable

- name: Download packed charm(s)
id: download-charms
timeout-minutes: 5
uses: actions/download-artifact@v4
with:
pattern: packed-charm-cache-true-.-charms-${{ matrix.charm }}-*
merge-multiple: true
path: /tmp/

- name: Integration tests
run: |
# Requires the model to be called kubeflow due to
# https://github.com/canonical/kfp-operators/issues/389
juju add-model kubeflow
sg snap_microk8s -c "tox -e ${{ matrix.charm }}-integration -- --model kubeflow"

- name: Collect charm debug artifacts
uses: canonical/kubeflow-ci/actions/dump-charm-debug-artifacts@main
if: always()

test-bundle:
name: Test the bundle
runs-on: ubuntu-20.04
Expand All @@ -153,7 +158,7 @@ jobs:
uses: jlumbroso/[email protected]

- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
Expand All @@ -165,11 +170,27 @@ jobs:
charmcraft-channel: 3.x/stable
microk8s-addons: "dns hostpath-storage rbac metallb:10.64.140.43-10.64.140.49"

- name: Download packed charm(s)
id: download-charms
timeout-minutes: 5
uses: actions/download-artifact@v4
with:
pattern: packed-charm-cache-true-.-charms-*
merge-multiple: true
path: /tmp/

- name: Debug
run: |
ls -lh .
echo "------------"
ls -lh /tmp/charms
echo "------------"
for d in ls -lh /tmp/charms/; do ls -lh $d; done
- name: Run test
run: |
# Requires the model to be called kubeflow due to kfp-viewer
juju add-model kubeflow
sg snap_microk8s -c "tox -e bundle-integration-${{ matrix.sdk }} -- --model kubeflow --bundle=./tests/integration/bundles/kfp_latest_edge.yaml.j2" --charmcraft-clean
sg snap_microk8s -c "tox -e bundle-integration-${{ matrix.sdk }} -- --model kubeflow --bundle=./tests/integration/bundles/kfp_latest_edge.yaml.j2"

- name: Get all
run: kubectl get all -A
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/on_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ name: On Pull Request
# On pull_request, we:
# * always publish to charmhub at latest/edge/branchname
# * always run tests

# * always run builds with cache
on:
pull_request:

jobs:
get-paths-and-build:
name: Get charm paths and build with cache
uses: canonical/charmed-kubeflow-workflows/.github/workflows/get_charms_build_with_cache.yaml@KF-67140-update-build-charms-version

tests:
name: Run Tests
needs: [get-paths-and-build]
uses: ./.github/workflows/integrate.yaml
secrets: inherit

# publish runs in parallel with tests, as we always publish in this situation
publish-charm:
name: Publish Charm
needs: [get-paths-and-build]
uses: ./.github/workflows/publish.yaml
secrets: inherit
135 changes: 9 additions & 126 deletions charms/kfp-api/tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,163 +45,46 @@ class TestCharm:
@pytest.mark.abort_on_fail
async def test_build_and_deploy(self, ops_test: OpsTest):
"""Deploy kfp-api with required charms and relations."""
built_charm_path = await ops_test.build_charm("./")
logger.info(f"Built charm {built_charm_path}")

image_path = METADATA["resources"]["oci-image"]["upstream-source"]
resources = {"oci-image": image_path}

await ops_test.model.deploy(
entity_url=built_charm_path,
entity_url="/tmp/charms/kfp-api/kfp-api_ubuntu-20.04-amd64.charm",
application_name=APP_NAME,
resources=resources,
trust=True,
)

# FIXME: we should probably stop deploying mariadb as:
# 1) The team has acceped and started using mysql-k8s more extensively
# 2) The repository level integration tests use mysql-k8s only
await ops_test.model.deploy(
entity_url=MARIADB_CHARM,
application_name=KFP_DB,
config=MARIADB_CONFIG,
channel=MARIADB_CHANNEL,
trust=MARIADB_TRUST,
)
await ops_test.model.deploy(
entity_url=MINIO, config=MINIO_CONFIG, channel=MINIO_CHANNEL, trust=MINIO_TRUST
)
await ops_test.model.deploy(
entity_url=KFP_VIZ, channel=KFP_VIZ_CHANNEL, trust=KFP_VIZ_TRUST
)

# FIXME: This assertion belongs to unit tests
# test no database relation, charm should be in blocked state
# assert ops_test.model.applications[APP_NAME].units[0].workload_status == "blocked"

await ops_test.model.add_relation(f"{APP_NAME}:mysql", f"{KFP_DB}:mysql")
await ops_test.model.add_relation(f"{APP_NAME}:object-storage", f"{MINIO}:object-storage")
await ops_test.model.add_relation(f"{APP_NAME}:kfp-viz", f"{KFP_VIZ}:kfp-viz")

await ops_test.model.wait_for_idle(
apps=[APP_NAME, KFP_VIZ, KFP_DB, MINIO],
status="active",
raise_on_blocked=False,
raise_on_error=False,
timeout=90 * 20,
)

# Deploying grafana-agent-k8s and add all relations
await deploy_and_assert_grafana_agent(
ops_test.model, APP_NAME, metrics=True, dashboard=True, logging=True
)

# FIXME: this test case belongs in unit tests as it is asserting the status of the
# unit under a certain condition, we don't actually need the presence of any deployed
# charm to test this.
@pytest.mark.abort_on_fail
async def test_relational_db_relation_with_mysql_relation(self, ops_test: OpsTest):
"""Test failure of addition of relational-db relation with mysql relation present."""
# deploy mysql-k8s charm
await ops_test.model.deploy(
MYSQL,
channel=MYSQL_CHANNEL,
application_name=KFP_DB,
config=MYSQL_CONFIG,
trust=MYSQL_TRUST,
)
await ops_test.model.relate(f"{APP_NAME}:relational-db", f"{KFP_DB}:database")
await ops_test.model.wait_for_idle(
apps=[MYSQL],
status="active",
raise_on_blocked=True,
timeout=90 * 30,
idle_period=20,
)

# add relational-db relation which should put charm into blocked state,
# because at this point mysql relation is already established
await ops_test.model.relate(f"{APP_NAME}:relational-db", f"{MYSQL}:database")

# verify that charm goes into blocked state
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="blocked",
raise_on_blocked=False,
raise_on_error=True,
timeout=60 * 10,
idle_period=10,
)
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "blocked"

# remove just added relational-db relation
await ops_test.juju("remove-relation", f"{APP_NAME}:relational-db", f"{MYSQL}:database")

# FIXME: this test case belongs in unit tests as it is asserting the status of the
# unit under a certain condition, we don't actually need the presence of any deployed
# charm to test this.
@pytest.mark.abort_on_fail
async def test_relational_db_relation_with_mysql_k8s(self, ops_test: OpsTest):
"""Test no relation and relation with mysql-k8s charm."""

# verify that charm is active state
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
raise_on_blocked=False,
raise_on_error=True,
timeout=60 * 10,
)
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "active"

# remove existing mysql relation which should put charm into blocked state,
# because there will be no database relations
await ops_test.juju("remove-relation", f"{APP_NAME}:mysql", f"{KFP_DB}:mysql")

# verify that charm goes into blocked state
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="blocked",
raise_on_blocked=False,
raise_on_error=True,
timeout=60 * 10,
)
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "blocked"

# add relational-db relation which should put charm into active state
await ops_test.model.relate(f"{APP_NAME}:relational-db", f"{MYSQL}:database")

# verify that charm goes into active state
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
apps=[APP_NAME, KFP_VIZ, KFP_DB, MINIO],
status="active",
raise_on_blocked=False,
raise_on_error=True,
timeout=60 * 10,
raise_on_error=False,
timeout=90 * 20,
)
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "active"

# FIXME: this test case belongs in unit tests as it is asserting the status of the
# unit under a certain condition, we don't actually need the presence of any deployed
# charm to test this.
@pytest.mark.abort_on_fail
async def test_msql_relation_with_relational_db_relation(self, ops_test: OpsTest):
"""Test failure of addition of mysql relation with relation-db relation present."""

# add mysql relation which should put charm into blocked state,
# because at this point relational-db relation is already established
await ops_test.model.relate(f"{APP_NAME}:mysql", f"{KFP_DB}:mysql")

# verify that charm goes into blocked state
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="blocked",
raise_on_blocked=False,
raise_on_error=True,
timeout=60 * 10,
# Deploying grafana-agent-k8s and add all relations
await deploy_and_assert_grafana_agent(
ops_test.model, APP_NAME, metrics=True, dashboard=True, logging=True
)
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "blocked"

# remove redundant relation
await ops_test.juju("remove-relation", f"{APP_NAME}:mysql", f"{KFP_DB}:mysql")

async def test_alert_rules(self, ops_test: OpsTest):
"""Test check charm alert rules and rules defined in relation data bag."""
Expand Down
8 changes: 4 additions & 4 deletions charms/kfp-metadata-writer/tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

@pytest.mark.abort_on_fail
async def test_build_and_deploy_with_relations(ops_test: OpsTest):
built_charm_path = await ops_test.build_charm(CHARM_ROOT)
log.info(f"Built charm {built_charm_path}")

image_path = METADATA["resources"]["oci-image"]["upstream-source"]
resources = {"oci-image": image_path}

await ops_test.model.deploy(
entity_url=built_charm_path, application_name=APP_NAME, resources=resources, trust=True
entity_url="/tmp/charms/kfp-metadata-writer/kfp-metadata-writer_ubuntu-20.04-amd64.charm",
application_name=APP_NAME,
resources=resources,
trust=True,
)
await ops_test.model.deploy(entity_url=MLMD, channel=MLMD_CHANNEL, trust=True)
await ops_test.model.integrate(f"{MLMD}:grpc", f"{APP_NAME}:grpc")
Expand Down
5 changes: 1 addition & 4 deletions charms/kfp-persistence/tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ class TestCharm:
@pytest.mark.abort_on_fail
async def test_build_and_deploy(self, ops_test: OpsTest):
"""Deploy kfp-persistence with required charms and relations."""
built_charm_path = await ops_test.build_charm("./")
logger.info(f"Built charm {built_charm_path}")

image_path = METADATA["resources"]["oci-image"]["upstream-source"]
resources = {"oci-image": image_path}

await ops_test.model.deploy(
entity_url=built_charm_path,
entity_url="/tmp/charms/kfp-persistence/kfp-persistence_ubuntu-20.04-amd64.charm",
application_name=APP_NAME,
resources=resources,
trust=True,
Expand Down
Loading
Loading