Skip to content

Commit

Permalink
tests: pin deployed charms to a latest and stable compatible version (#…
Browse files Browse the repository at this point in the history
…408)

* tests: pin deployed charms to a latest and stable compatible version

This commit pins all charms that get deployed from Charmhub to a latest/edge or suggested versions.

Part of canonical/bundle-kubeflow#863
  • Loading branch information
DnPlas authored Apr 16, 2024
1 parent e0d2c02 commit 79545af
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 26 deletions.
35 changes: 26 additions & 9 deletions tests/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@

log = logging.getLogger(__name__)

# Test dependencies
DEX_AUTH = "dex-auth"
DEX_AUTH_CHANNEL = "latest/edge"
TRUST_DEX_AUTH = True
OIDC_GATEKEEPER = "oidc-gatekeeper"
OIDC_GATEKEEPER_CHANNEL = "latest/edge"
TRUST_OIDC_GATEKEEPER = False
TENSORBOARD_CONTROLLER = "tensorboard-controller"
TENSORBOARD_CONTROLLER_CHANNEL = "latest/edge"
TRUST_TENSORBOARD_CONTROLLER = True
INGRESS_REQUIRER = "kubeflow-volumes"
INGRESS_REQUIRER_CHANNEL = "latest/edge"
TRUST_INGRESS_REQUIRER = True

ISTIO_PILOT = "istio-pilot"
ISTIO_GATEWAY_APP_NAME = "istio-ingressgateway"
TENSORBOARD_CONTROLLER = "tensorboard-controller"
KUBEFLOW_VOLUMES = "kubeflow-volumes"

USERNAME = "user123"
PASSWORD = "user123"
Expand Down Expand Up @@ -100,17 +110,19 @@ async def test_ingress_relation(ops_test: OpsTest):
TODO (https://github.com/canonical/istio-operators/issues/259): Change this from using a
specific charm that implements ingress's requirer interface to a generic charm
"""
await ops_test.model.deploy(KUBEFLOW_VOLUMES, channel="latest/edge", trust=True)
await ops_test.model.deploy(
INGRESS_REQUIRER, channel=INGRESS_REQUIRER_CHANNEL, trust=TRUST_INGRESS_REQUIRER
)

await ops_test.model.add_relation(f"{ISTIO_PILOT}:ingress", f"{KUBEFLOW_VOLUMES}:ingress")
await ops_test.model.add_relation(f"{ISTIO_PILOT}:ingress", f"{INGRESS_REQUIRER}:ingress")

await ops_test.model.wait_for_idle(
status="active",
raise_on_blocked=False,
timeout=90 * 10,
)

assert_virtualservice_exists(name=KUBEFLOW_VOLUMES, namespace=ops_test.model_name)
assert_virtualservice_exists(name=INGRESS_REQUIRER, namespace=ops_test.model_name)

# Confirm that the UI is reachable through the ingress
gateway_ip = await get_gateway_ip(ops_test)
Expand All @@ -123,7 +135,11 @@ async def test_gateway_info_relation(ops_test: OpsTest):
TODO (https://github.com/canonical/istio-operators/issues/259): Change this from using a
specific charm that implements ingress's requirer interface to a generic charm
"""
await ops_test.model.deploy(TENSORBOARD_CONTROLLER, channel="latest/edge", trust=True)
await ops_test.model.deploy(
TENSORBOARD_CONTROLLER,
channel=TENSORBOARD_CONTROLLER_CHANNEL,
trust=TRUST_TENSORBOARD_CONTROLLER,
)

await ops_test.model.add_relation(
f"{ISTIO_PILOT}:gateway-info", f"{TENSORBOARD_CONTROLLER}:gateway-info"
Expand Down Expand Up @@ -234,8 +250,8 @@ async def test_enable_ingress_auth(ops_test: OpsTest):
regular_ingress_gateway_ip = await get_gateway_ip(ops_test)
await ops_test.model.deploy(
DEX_AUTH,
channel="2.31/stable",
trust=True,
channel=DEX_AUTH_CHANNEL,
trust=TRUST_DEX_AUTH,
config={
"static-username": USERNAME,
"static-password": PASSWORD,
Expand All @@ -245,7 +261,8 @@ async def test_enable_ingress_auth(ops_test: OpsTest):

await ops_test.model.deploy(
OIDC_GATEKEEPER,
channel="ckf-1.6/stable",
channel=OIDC_GATEKEEPER_CHANNEL,
trust=TRUST_OIDC_GATEKEEPER,
config={"public-url": regular_ingress_gateway_ip},
)

Expand Down
10 changes: 7 additions & 3 deletions tests/test_bundle_tls_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
plural="gateways",
)

SELF_SIGNED_CERTIFICATES = "self-signed-certificates"
SELF_SIGNED_CERTIFICATES_CHANNEL = "latest/edge"
SELF_SIGNED_CERTIFICATES_TRUST = True


@pytest.fixture(scope="session")
def lightkube_client() -> lightkube.Client:
Expand Down Expand Up @@ -53,12 +57,12 @@ async def test_build_and_deploy_istio_charms(ops_test: OpsTest):
)

await ops_test.model.deploy(
"self-signed-certificates",
channel="edge",
SELF_SIGNED_CERTIFICATES,
channel=SELF_SIGNED_CERTIFICATES_CHANNEL,
)

await ops_test.model.add_relation(
f"{ISTIO_PILOT}:certificates", "self-signed-certificates:certificates"
f"{ISTIO_PILOT}:certificates", f"{SELF_SIGNED_CERTIFICATES}:certificates"
)

await ops_test.model.wait_for_idle(
Expand Down
42 changes: 28 additions & 14 deletions tests/test_cos_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
ISTIO_GATEWAY_APP_NAME = "istio-ingressgateway"


PROMETHEUS_K8S = "prometheus-k8s"
PROMETHEUS_K8S_CHANNEL = "latest/stable"
PROMETHEUS_K8S_TRUST = True
PROMETHEUS_SCRAPE_K8S = "prometheus-scrape-config-k8s"
PROMETHEUS_SCRAPE_K8S_CHANNEL = "latest/stable"
PROMETHEUS_SCRAPE_CONFIG = {"scrape_interval": "30s"}


@pytest.mark.abort_on_fail
async def test_build_and_deploy_istio_charms(ops_test: OpsTest):
# Build, deploy, and relate istio charms
Expand Down Expand Up @@ -48,23 +56,28 @@ async def test_build_and_deploy_istio_charms(ops_test: OpsTest):

async def test_prometheus_grafana_integration_istio_pilot(ops_test: OpsTest):
"""Deploy prometheus and required relations, then test the metrics."""
prometheus = "prometheus-k8s"
prometheus_scrape = "prometheus-scrape-config-k8s"
scrape_config = {"scrape_interval": "30s"}

# Deploy and relate prometheus
await ops_test.model.deploy(prometheus, channel="latest/stable", trust=True)
await ops_test.model.deploy(prometheus_scrape, channel="latest/stable", config=scrape_config)
await ops_test.model.deploy(
PROMETHEUS_K8S,
channel=PROMETHEUS_K8S_CHANNEL,
trust=PROMETHEUS_K8S_TRUST,
)
await ops_test.model.deploy(
PROMETHEUS_SCRAPE_K8S,
channel=PROMETHEUS_SCRAPE_K8S_CHANNEL,
config=PROMETHEUS_SCRAPE_CONFIG,
)

await ops_test.model.add_relation(ISTIO_PILOT, prometheus_scrape)
await ops_test.model.add_relation("istio-pilot", PROMETHEUS_SCRAPE_K8S)
await ops_test.model.add_relation(
f"{prometheus}:metrics-endpoint", f"{prometheus_scrape}:metrics-endpoint"
f"{PROMETHEUS_K8S}:metrics-endpoint",
f"{PROMETHEUS_SCRAPE_K8S}:metrics-endpoint",
)

await ops_test.model.wait_for_idle(status="active", timeout=90 * 10)

await ops_test.model.wait_for_idle(status="active", timeout=60 * 20)
status = await ops_test.model.get_status()
prometheus_unit_ip = status["applications"][prometheus]["units"][f"{prometheus}/0"]["address"]
prometheus_unit_ip = status["applications"][PROMETHEUS_K8S]["units"][f"{PROMETHEUS_K8S}/0"][
"address"
]
log.info(f"Prometheus available at http://{prometheus_unit_ip}:9090")

for attempt in retry_for_5_attempts:
Expand All @@ -89,9 +102,10 @@ async def test_prometheus_grafana_integration_istio_pilot(ops_test: OpsTest):
async def test_istio_pilot_alert_rules(ops_test: OpsTest):
"""Test alert rules availability and match with what is found in the source code."""

prometheus = "prometheus-k8s"
status = await ops_test.model.get_status()
prometheus_unit_ip = status["applications"][prometheus]["units"][f"{prometheus}/0"]["address"]
prometheus_unit_ip = status["applications"][PROMETHEUS_K8S]["units"][f"{PROMETHEUS_K8S}/0"][
"address"
]

# Get targets and assert they are available
targets_url = f"http://{prometheus_unit_ip}:9090/api/v1/targets"
Expand Down

0 comments on commit 79545af

Please sign in to comment.