Skip to content

Commit

Permalink
Merge pull request #1259 from sabaini/cos-integration-controller
Browse files Browse the repository at this point in the history
COS integration testing: improve COS model lookup
  • Loading branch information
sabaini authored Aug 29, 2024
2 parents 664040d + f1b1c3a commit f8b4d09
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions zaza/openstack/charm_tests/ceph/mon/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"""Integration tests for ceph-mon."""

import unittest

import zaza.model
from juju import juju
from zaza import sync_wrapper
from zaza.openstack.charm_tests import test_utils as test_utils

from zaza.openstack.charm_tests.ceph.mon.tests import (
Expand All @@ -28,21 +28,52 @@
)


async def async_find_cos_model():
"""Find a COS model.
Look for models first on the current controller, then on a k8s controller.
Return the first model with a name starting with "cos".
"""
models = await zaza.controller.async_list_models()
cos_models = [m for m in models if m.startswith("cos")]
if cos_models:
return cos_models[0]
# Look for a k8s controller
j = juju.Juju()
k8s = [
k for k, v in j.get_controllers().items() if v["type"] == "kubernetes"
]
if not k8s:
return
ctrl = juju.Controller()
await ctrl.connect(k8s[0])
k8s_models = await ctrl.list_models()
cos_models = [m for m in k8s_models if m.startswith("cos")]
await ctrl.disconnect()
if not cos_models:
return
return f"{k8s[0]}:{cos_models[0]}"


find_cos_model = sync_wrapper(async_find_cos_model)


class COSModelNotFound(Exception):
"""Exception raised when no COS model is found."""

pass


class COSIntegrationTest(test_utils.BaseCharmTest):
"""Test COS integration with ceph-mon."""

@classmethod
def setUpClass(cls):
"""Run class setup for running cos integration testing."""
# skip if there are no COS models
cos_models = [
m for m in zaza.controller.list_models() if m.startswith("cos")
]
if not cos_models:
raise unittest.SkipTest("No COS models found")

cls.cos_model = cos_models[0]

# look for a cos model on the current controller
cls.cos_model = find_cos_model()
if not cls.cos_model:
raise COSModelNotFound("No COS model found, cannot run tests")
cls.grafana_details = zaza.model.run_action_on_leader(
"grafana", "get-admin-password", model_name=cls.cos_model
).results
Expand Down

0 comments on commit f8b4d09

Please sign in to comment.