File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ applications:
66 revision : 113
77 scale : 1
88 grafana-agent-k8s :
9- channel : latest /edge
9+ channel : 1 /edge
1010 charm : grafana-agent-k8s
1111 constraints : arch=amd64
1212 resources :
Original file line number Diff line number Diff line change 11# Copyright 2023 Canonical Ltd.
22# See LICENSE file for licensing details.
33
4- from typing import Dict
4+ from typing import Dict , Optional
55
66from juju .unit import Unit
77from pytest_operator .plugin import OpsTest
88
99
10+ async def get_leader_unit (ops_test : OpsTest , app_name : str ) -> Optional [Unit ]:
11+ """Get the leader unit of a given application.
12+
13+ Args:
14+ ops_test: The ops test framework instance
15+ app_name: The name of the application
16+ """
17+ for unit in ops_test .model .applications [app_name ].units :
18+ if await unit .is_leader_from_status ():
19+ return unit
20+
21+
1022async def get_unit_ip (ops_test : OpsTest , unit_name : str ) -> str :
1123 """Get unit IP address."""
1224 status = await ops_test .model .get_status ()
Original file line number Diff line number Diff line change 1111from pytest_operator .plugin import OpsTest
1212
1313from .connector import MysqlConnector
14- from .helpers import get_credentials , get_unit_ip
14+ from .helpers import get_credentials , get_leader_unit , get_unit_ip
1515
1616waiting_apps = [
1717 "mysql-router-k8s" ,
@@ -91,14 +91,14 @@ async def test_smoke(ops_test: OpsTest) -> None:
9191 await ensure_statuses (ops_test )
9292
9393 logger .info ("Confirming data-integrator's database exists" )
94- mysql_unit = ops_test . model . applications [ "mysql-k8s" ]. units [ 0 ]
95- mysql_unit_address = await get_unit_ip (ops_test , mysql_unit .name )
96- server_config_credentials = await get_credentials (mysql_unit , "serverconfig" )
94+ mysql_leader = await get_leader_unit ( ops_test , "mysql-k8s" )
95+ mysql_leader_address = await get_unit_ip (ops_test , mysql_leader .name )
96+ server_config_credentials = await get_credentials (mysql_leader , "serverconfig" )
9797
9898 database_config = {
9999 "user" : server_config_credentials ["username" ],
100100 "password" : server_config_credentials ["password" ],
101- "host" : mysql_unit_address ,
101+ "host" : mysql_leader_address ,
102102 "raise_on_warnings" : False ,
103103 }
104104
You can’t perform that action at this time.
0 commit comments