Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion releases/latest/mysql-k8s-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ applications:
revision: 113
scale: 1
grafana-agent-k8s:
channel: latest/edge
channel: 1/edge
charm: grafana-agent-k8s
constraints: arch=amd64
resources:
Expand Down
14 changes: 13 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.

from typing import Dict
from typing import Dict, Optional

from juju.unit import Unit
from pytest_operator.plugin import OpsTest


async def get_leader_unit(ops_test: OpsTest, app_name: str) -> Optional[Unit]:
"""Get the leader unit of a given application.

Args:
ops_test: The ops test framework instance
app_name: The name of the application
"""
for unit in ops_test.model.applications[app_name].units:
if await unit.is_leader_from_status():
return unit


async def get_unit_ip(ops_test: OpsTest, unit_name: str) -> str:
"""Get unit IP address."""
status = await ops_test.model.get_status()
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pytest_operator.plugin import OpsTest

from .connector import MysqlConnector
from .helpers import get_credentials, get_unit_ip
from .helpers import get_credentials, get_leader_unit, get_unit_ip

waiting_apps = [
"mysql-router-k8s",
Expand Down Expand Up @@ -91,14 +91,14 @@ async def test_smoke(ops_test: OpsTest) -> None:
await ensure_statuses(ops_test)

logger.info("Confirming data-integrator's database exists")
mysql_unit = ops_test.model.applications["mysql-k8s"].units[0]
mysql_unit_address = await get_unit_ip(ops_test, mysql_unit.name)
server_config_credentials = await get_credentials(mysql_unit, "serverconfig")
mysql_leader = await get_leader_unit(ops_test, "mysql-k8s")
mysql_leader_address = await get_unit_ip(ops_test, mysql_leader.name)
server_config_credentials = await get_credentials(mysql_leader, "serverconfig")

database_config = {
"user": server_config_credentials["username"],
"password": server_config_credentials["password"],
"host": mysql_unit_address,
"host": mysql_leader_address,
"raise_on_warnings": False,
}

Expand Down
Loading