Skip to content

Commit

Permalink
Merge branch 'main' into KF-3609-frontend-test-case
Browse files Browse the repository at this point in the history
  • Loading branch information
DnPlas authored Jul 19, 2023
2 parents cac279c + 0bb53f4 commit cb73a81
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion charms/kfp-api/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resources:
oci-image:
type: oci-image
description: Backing OCI image
upstream-source: gcr.io/ml-pipeline/api-server:2.0.0-alpha.7
upstream-source: charmedkubeflow/api-server:2.0.0-alpha.7_20.04_1
requires:
mysql:
interface: mysql
Expand Down
5 changes: 4 additions & 1 deletion charms/kfp-api/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
]
MYSQL_WARNING = "Relation mysql is deprecated."
UNBLOCK_MESSAGE = "Remove deprecated mysql relation to unblock."
KFP_API_SERVICE_NAME = "apiserver"


class KfpApiOperator(CharmBase):
Expand Down Expand Up @@ -180,11 +181,13 @@ def service_environment(self):
@property
def _kfp_api_layer(self) -> Layer:
"""Create and return Pebble framework layer."""
# The service name should be the same as the one
# defined in the Rockcraft project: apiserver
layer_config = {
"summary": "kfp-api layer",
"description": "Pebble config layer for kfp-api",
"services": {
self._container_name: {
KFP_API_SERVICE_NAME: {
"override": "replace",
"summary": "ML Pipeline API Server",
"command": f"bash -c '{self._exec_command}'",
Expand Down
28 changes: 15 additions & 13 deletions charms/kfp-api/tests/unit/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from ops.model import ActiveStatus, BlockedStatus, WaitingStatus
from ops.testing import Harness

from charm import ErrorWithStatus, KfpApiOperator
from charm import KFP_API_SERVICE_NAME, ErrorWithStatus, KfpApiOperator

KFP_API_CONTAINER_NAME = "ml-pipeline-api-server"


@pytest.fixture()
Expand Down Expand Up @@ -41,7 +43,7 @@ def harness() -> Harness:
harness = Harness(KfpApiOperator)

# setup container networking simulation
harness.set_can_connect("ml-pipeline-api-server", True)
harness.set_can_connect(KFP_API_CONTAINER_NAME, True)

return harness

Expand All @@ -53,7 +55,7 @@ class TestCharm:
@patch("charm.KfpApiOperator.k8s_resource_handler")
def test_not_leader(self, k8s_resource_handler: MagicMock, harness: Harness):
harness.begin_with_initial_hooks()
harness.container_pebble_ready("ml-pipeline-api-server")
harness.container_pebble_ready(KFP_API_CONTAINER_NAME)
assert harness.charm.model.unit.status == WaitingStatus("Waiting for leadership")

@pytest.mark.parametrize(
Expand Down Expand Up @@ -110,7 +112,7 @@ def test_mysql_relation(
):
harness.set_leader(True)
harness.begin()
harness.container_pebble_ready("ml-pipeline-api-server")
harness.container_pebble_ready(KFP_API_CONTAINER_NAME)

mysql_app = "mysql_app"
mysql_unit = f"{mysql_app}/0"
Expand All @@ -133,7 +135,7 @@ def test_mysql_relation(
def test_mysql_relation_too_many_relations(self, harness: Harness):
harness.set_leader(True)
harness.begin()
harness.container_pebble_ready("ml-pipeline-api-server")
harness.container_pebble_ready(KFP_API_CONTAINER_NAME)

mysql_app = "mysql_app"
mysql_unit = f"{mysql_app}/0"
Expand All @@ -151,7 +153,7 @@ def test_mysql_relation_too_many_relations(self, harness: Harness):
def test_kfp_viz_relation_missing(self, harness: Harness):
harness.set_leader(True)
harness.begin()
harness.container_pebble_ready("ml-pipeline-api-server")
harness.container_pebble_ready(KFP_API_CONTAINER_NAME)

# check for correct error message when retrieving missing relation data
interfaces = harness.charm._get_interfaces()
Expand Down Expand Up @@ -311,7 +313,7 @@ def test_relations_that_provide_data(
):
harness.set_leader(True)
harness.begin()
harness.container_pebble_ready("ml-pipeline-api-server")
harness.container_pebble_ready(KFP_API_CONTAINER_NAME)

other_app = "other-app"
other_unit = f"{other_app}/0"
Expand Down Expand Up @@ -393,7 +395,7 @@ def test_install_with_all_inputs_and_pebble(
harness.update_relation_data(kfpapi_rel_id, "kfp-api-subscriber", kfpapi_data)

harness.begin_with_initial_hooks()
harness.container_pebble_ready("ml-pipeline-api-server")
harness.container_pebble_ready(KFP_API_CONTAINER_NAME)
this_app_name = harness.charm.model.app.name

# Test that we sent data to anyone subscribing to us
Expand All @@ -413,12 +415,12 @@ def test_install_with_all_inputs_and_pebble(
k8s_resource_handler.apply.assert_called()

# test Pebble
assert harness.charm.container.get_service("ml-pipeline-api-server").is_running()
pebble_plan = harness.get_container_pebble_plan("ml-pipeline-api-server")
assert harness.charm.container.get_service("apiserver").is_running()
pebble_plan = harness.get_container_pebble_plan(KFP_API_CONTAINER_NAME)
assert pebble_plan
assert pebble_plan.services
pebble_plan_info = pebble_plan.to_dict()
pebble_exec_command = pebble_plan_info["services"]["ml-pipeline-api-server"]["command"]
pebble_exec_command = pebble_plan_info["services"][KFP_API_SERVICE_NAME]["command"]
exec_command = (
# TODO: Remove 'sleep' as soon as a fix for
# https://github.com/canonical/pebble/issues/240 is provided
Expand All @@ -429,7 +431,7 @@ def test_install_with_all_inputs_and_pebble(
"-logtostderr=true "
)
assert pebble_exec_command == f"bash -c '{exec_command}'"
test_env = pebble_plan_info["services"]["ml-pipeline-api-server"]["environment"]
test_env = pebble_plan_info["services"][KFP_API_SERVICE_NAME]["environment"]
# there should be 1 environment variable
assert 1 == len(test_env)
assert "test_model" == test_env["POD_NAMESPACE"]
Expand All @@ -450,7 +452,7 @@ def test_update_status(
"""Test update status handler."""
harness.set_leader(True)
harness.begin_with_initial_hooks()
harness.container_pebble_ready("ml-pipeline-api-server")
harness.container_pebble_ready(KFP_API_CONTAINER_NAME)

# test successful update status
_apply_k8s_resources.reset_mock()
Expand Down
2 changes: 1 addition & 1 deletion charms/kfp-persistence/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resources:
oci-image:
type: oci-image
description: Backing OCI image
upstream-source: gcr.io/ml-pipeline/persistenceagent:2.0.0-alpha.7
upstream-source: charmedkubeflow/persistenceagent:2.0.0-alpha.7_22.04_1
requires:
kfp-api:
interface: k8s-service
Expand Down
2 changes: 1 addition & 1 deletion charms/kfp-schedwf/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ resources:
oci-image:
type: oci-image
description: Backing OCI image
upstream-source: gcr.io/ml-pipeline/scheduledworkflow:2.0.0-alpha.7
upstream-source: charmedkubeflow/scheduledworkflow:2.0.0-alpha.7_22.04_1
2 changes: 1 addition & 1 deletion charms/kfp-viewer/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ resources:
oci-image:
type: oci-image
description: Backing OCI image
upstream-source: gcr.io/ml-pipeline/viewer-crd-controller:2.0.0-alpha.7
upstream-source: charmedkubeflow/viewer-crd-controller:2.0.0-alpha.7_22.04_1

0 comments on commit cb73a81

Please sign in to comment.