99from pytest_operator .plugin import OpsTest
1010from tenacity import Retrying , stop_after_delay , wait_fixed
1111
12+ from .test_restore_cluster import SECOND_APPLICATION
1213from ..helpers import (
1314 CHARM_SERIES ,
1415 db_connect ,
@@ -554,8 +555,19 @@ async def test_network_cut_without_ip_change(
554555@pytest .mark .group (1 )
555556async def test_deploy_zero_units (ops_test : OpsTest ):
556557 """Scale the database to zero units and scale up again."""
557- app = await app_name (ops_test )
558+ charm = await ops_test .build_charm ("." )
559+ async with ops_test .fast_forward ():
560+ await ops_test .model .deploy (
561+ charm ,
562+ num_units = 1 ,
563+ application_name = SECOND_APPLICATION ,
564+ series = CHARM_SERIES ,
565+ storage = {"pgdata" : {"pool" : "lxd-btrfs" , "size" : 2048 }},
566+ config = {"profile" : "testing" },
567+ )
568+ await ops_test .model .wait_for_idle (status = "active" , timeout = 1500 )
558569
570+ app = await app_name (ops_test )
559571 dbname = f"{ APPLICATION_NAME .replace ('-' , '_' )} _first_database"
560572 connection_string , _ = await get_db_connection (ops_test , dbname = dbname )
561573
@@ -580,6 +592,13 @@ async def test_deploy_zero_units(ops_test: OpsTest):
580592 if await unit .is_leader_from_status :
581593 primary_storage = storage_id (ops_test , unit .name )
582594
595+ logger .info (f"get storage id app: { SECOND_APPLICATION } " )
596+ second_storage = ""
597+ for unit in ops_test .model .applications [SECOND_APPLICATION ].units :
598+ if await unit .is_leader_from_status :
599+ second_storage = storage_id (ops_test , unit .name )
600+ break
601+
583602 # Scale the database to zero units.
584603 logger .info ("scaling database to zero units" )
585604 await scale_application (ops_test , app , 0 )
@@ -601,13 +620,23 @@ async def test_deploy_zero_units(ops_test: OpsTest):
601620 await add_unit_with_storage (ops_test , app = app , storage = primary_storage )
602621 await ops_test .model .wait_for_idle (status = "active" , timeout = 1500 )
603622
623+ logger .info ("scaling database to tow unit using foreign cluster's storage" )
624+ await add_unit_with_storage (ops_test , app = app , storage = second_storage )
625+ await ops_test .model .block_until (
626+ lambda :
627+ timeout = 1500
628+ )
629+
604630 connection_string , _ = await get_db_connection (ops_test , dbname = dbname )
605631 logger .info ("checking whether writes are increasing" )
606632 await are_writes_increasing (ops_test )
607633
608634 logger .info ("check test database data" )
609635 await validate_test_data (connection_string )
610636
637+
638+
639+
611640 # Scale up to two units.
612641 logger .info ("scaling database to two unit" )
613642 prev_units = [unit .name for unit in ops_test .model .applications [app ].units ]
0 commit comments