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

COS integration testing: improve COS model lookup #1259

Merged
Merged
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
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]}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: given that this method is supposed to only give 1 cos model (line 40), does it make sense to have a static key ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I didn't hardcode a static controller/model name is to give some flexibility for the test env. This way you could run the COS model in the same controller, or in another kubernetes controller and would also have some flexibility in naming

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UtkarshBhatthere does this answer your question? Happy to discuss more if not



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
Loading