54
54
storage_type ,
55
55
update_restart_condition ,
56
56
validate_test_data ,
57
- wait_network_restore ,
57
+ wait_network_restore , get_last_added_unit ,
58
58
)
59
59
60
60
logger = logging .getLogger (__name__ )
@@ -595,7 +595,7 @@ async def test_deploy_zero_units(ops_test: OpsTest):
595
595
except Exception as e :
596
596
assert False , f"{ e } unit host = http://{ unit_ip } :8008, something went wrong"
597
597
598
- # Scale the database to one unit.
598
+ # Scale up to one unit.
599
599
logger .info ("scaling database to one unit" )
600
600
await add_unit_with_storage (ops_test , app = app , storage = primary_storage )
601
601
await ops_test .model .wait_for_idle (status = "active" , timeout = 1500 )
@@ -607,18 +607,34 @@ async def test_deploy_zero_units(ops_test: OpsTest):
607
607
logger .info ("check test database data" )
608
608
await validate_test_data (connection_string )
609
609
610
- # Scale the database to three units.
610
+ # Scale up to two units.
611
611
logger .info ("scaling database to two unit" )
612
+ prev_units = [unit .name for unit in ops_test .model .applications [app ].units ]
612
613
await scale_application (ops_test , application_name = app , count = 2 )
613
- for unit in ops_test .model .applications [app ].units :
614
- if not await unit .is_leader_from_status ():
615
- assert await reused_replica_storage (
616
- ops_test , unit_name = unit .name
617
- ), "attached storage not properly re-used by Postgresql."
618
- logger .info (f"check test database data of unit name { unit .name } " )
619
- connection_string , _ = await get_db_connection (
620
- ops_test , dbname = dbname , is_primary = False , replica_unit_name = unit .name
621
- )
622
- await validate_test_data (connection_string )
614
+ unit = await get_last_added_unit (ops_test , app , prev_units )
615
+
616
+ logger .info (f"check test database data of unit name { unit .name } " )
617
+ connection_string , _ = await get_db_connection (
618
+ ops_test , dbname = dbname , is_primary = False , replica_unit_name = unit .name
619
+ )
620
+ await validate_test_data (connection_string )
621
+ assert await reused_replica_storage (
622
+ ops_test , unit_name = unit .name
623
+ ), "attached storage not properly re-used by Postgresql."
624
+
625
+ # Scale up to three units.
626
+ logger .info ("scaling database to three unit" )
627
+ prev_units = [unit .name for unit in ops_test .model .applications [app ].units ]
628
+ await scale_application (ops_test , application_name = app , count = 3 )
629
+ unit = await get_last_added_unit (ops_test , app , prev_units )
630
+
631
+ logger .info (f"check test database data of unit name { unit .name } " )
632
+ connection_string , _ = await get_db_connection (
633
+ ops_test , dbname = dbname , is_primary = False , replica_unit_name = unit .name
634
+ )
635
+ await validate_test_data (connection_string )
636
+ assert await reused_replica_storage (
637
+ ops_test , unit_name = unit .name
638
+ ), "attached storage not properly re-used by Postgresql."
623
639
624
640
await check_writes (ops_test )
0 commit comments