Skip to content

Commit

Permalink
pin integration test dependencies, refactor constants in tests (#155)
Browse files Browse the repository at this point in the history
Pins dependencies in the integration tests to their corresponding channels for this release.

Ref: canonical/bundle-kubeflow#866
  • Loading branch information
ca-scribner authored and DnPlas committed Jun 12, 2024
1 parent dce1cbc commit 14d5393
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 39 deletions.
69 changes: 36 additions & 33 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
APP_NAME = "training-operator"
CHARM_LOCATION = None
APP_PREVIOUS_CHANNEL = "1.7/stable"

PROMETHEUS_K8S = "prometheus-k8s"
PROMETHEUS_K8S_CHANNEL = "latest/stable"
PROMETHEUS_K8S_TRUST = True
GRAFANA_K8S = "grafana-k8s"
GRAFANA_K8S_CHANNEL = "latest/stable"
GRAFANA_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
Expand Down Expand Up @@ -130,51 +141,43 @@ def assert_job_status_running_success():

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

# Deploy and relate prometheus
# FIXME: Unpin revision once https://github.com/canonical/bundle-kubeflow/issues/688 is closed
await ops_test.juju(
"deploy",
prometheus,
"--channel",
"latest/edge",
"--revision",
"137",
"--trust",
check=True,
await ops_test.model.deploy(
PROMETHEUS_K8S,
channel=PROMETHEUS_K8S_CHANNEL,
trust=PROMETHEUS_K8S_TRUST,
)
# FIXME: Unpin revision once https://github.com/canonical/bundle-kubeflow/issues/690 is closed
await ops_test.juju(
"deploy",
grafana,
"--channel",
"latest/edge",
"--revision",
"89",
"--trust",
check=True,

await ops_test.model.deploy(
GRAFANA_K8S,
channel=GRAFANA_K8S_CHANNEL,
trust=GRAFANA_K8S_TRUST,
)
await ops_test.model.deploy(prometheus_scrape, channel="latest/beta", config=scrape_config)

await ops_test.model.add_relation(APP_NAME, prometheus_scrape)
await ops_test.model.deploy(
PROMETHEUS_SCRAPE_K8S,
channel=PROMETHEUS_SCRAPE_K8S_CHANNEL,
config=PROMETHEUS_SCRAPE_CONFIG,
)

await ops_test.model.add_relation(APP_NAME, PROMETHEUS_SCRAPE_K8S)
await ops_test.model.add_relation(
f"{prometheus}:grafana-dashboard", f"{grafana}:grafana-dashboard"
f"{PROMETHEUS_K8S}:grafana-dashboard",
f"{GRAFANA_K8S}:grafana-dashboard",
)
await ops_test.model.add_relation(
f"{APP_NAME}:grafana-dashboard", f"{grafana}:grafana-dashboard"
f"{APP_NAME}:grafana-dashboard", f"{GRAFANA_K8S}:grafana-dashboard"
)
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=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"
]
logger.info(f"Prometheus available at http://{prometheus_unit_ip}:9090")

for attempt in retry_for_5_attempts:
Expand Down Expand Up @@ -245,7 +248,7 @@ async def test_upgrade(ops_test: OpsTest):
"""

# deploy stable version of the charm
await ops_test.model.deploy(entity_url=APP_NAME, channel="1.5/stable", trust=True)
await ops_test.model.deploy(entity_url=APP_NAME, channel=APP_PREVIOUS_CHANNEL, trust=True)
await ops_test.model.wait_for_idle(
apps=[APP_NAME], status="active", raise_on_blocked=True, timeout=60 * 10
)
Expand Down
19 changes: 13 additions & 6 deletions tests/integration/test_charm_with_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
APP_NAME = "training-operator"

KUBEFLOW_ROLES = "kubeflow-roles"
KUBEFLOW_ROLES_CHANNEL = "latest/edge"
KUBEFLOW_ROLES_TRUST = True
KUBEFLOW_PROFILES = "kubeflow-profiles"
KUBEFLOW_PROFILES_CHANNEL = "latest/edge"
KUBEFLOW_PROFILES_TRUST = True

log = logging.getLogger(__name__)


Expand All @@ -46,14 +53,14 @@ async def test_build_and_deploy(ops_test: OpsTest):

# Deploy kubeflow-roles and kubeflow-profiles to create a Profile
await ops_test.model.deploy(
entity_url="kubeflow-roles",
channel="latest/edge",
trust=True,
entity_url=KUBEFLOW_ROLES,
channel=KUBEFLOW_ROLES_CHANNEL,
trust=KUBEFLOW_ROLES_TRUST,
)
await ops_test.model.deploy(
entity_url="kubeflow-profiles",
channel="latest/edge",
trust=True,
entity_url=KUBEFLOW_PROFILES,
channel=KUBEFLOW_PROFILES_CHANNEL,
trust=KUBEFLOW_PROFILES_TRUST,
)

await ops_test.model.wait_for_idle(
Expand Down

0 comments on commit 14d5393

Please sign in to comment.