66import shutil
77import zipfile
88from pathlib import Path
9+ from time import sleep
910
1011import pytest
1112import tomli
@@ -128,10 +129,6 @@ async def test_upgrade_from_edge(ops_test: OpsTest, charm, continuous_writes) ->
128129 await application .refresh (path = charm , resources = resources )
129130
130131 logger .info ("Wait for upgrade to start" )
131-
132- # Blocked status is expected due to:
133- # (on PR) compatibility checks (on PR charm revision is '16/1.25.0+dirty...')
134- # (non-PR) the first unit upgraded and paused (pause-after-unit-refresh=first)
135132 await ops_test .model .block_until (lambda : application .status == "blocked" , timeout = 60 * 3 )
136133
137134 logger .info ("Wait for refresh to block as paused or incompatible" )
@@ -144,23 +141,34 @@ async def test_upgrade_from_edge(ops_test: OpsTest, charm, continuous_writes) ->
144141 refresh_order = sorted (
145142 application .units , key = lambda unit : int (unit .name .split ("/" )[1 ]), reverse = True
146143 )
147- if "Refresh incompatible" in application .status_message :
144+
145+ if "Refresh incompatible" in refresh_order [0 ].workload_status_message :
148146 logger .info ("Application refresh is blocked due to incompatibility" )
149147
150148 action = await refresh_order [0 ].run_action (
151149 "force-refresh-start" , ** {"check-compatibility" : False }
152150 )
153151 await action .wait ()
154152
155- logger .info ("Wait for first incompatible unit to upgrade" )
156- async with ops_test .fast_forward ("60s" ):
157- await ops_test .model .wait_for_idle (
158- apps = [DATABASE_APP_NAME ], idle_period = 30 , timeout = TIMEOUT
159- )
153+ logger .info ("Wait for first incompatible unit to upgrade" )
154+ async with ops_test .fast_forward ("60s" ):
155+ await ops_test .model .wait_for_idle (
156+ apps = [DATABASE_APP_NAME ], idle_period = 30 , timeout = TIMEOUT
157+ )
158+ else :
159+ async with ops_test .fast_forward ("60s" ):
160+ await ops_test .model .block_until (
161+ lambda : all (unit .workload_status == "active" for unit in application .units ),
162+ timeout = 60 * 3 ,
163+ )
160164
161- logger .info ("Run resume-refresh action" )
162- action = await refresh_order [1 ].run_action ("resume-refresh" )
165+ sleep (60 )
166+
167+ leader_unit = await get_leader_unit (ops_test , DATABASE_APP_NAME )
168+ logger .info (f"Run resume-refresh action on { leader_unit .name } " )
169+ action = await leader_unit .run_action ("resume-refresh" )
163170 await action .wait ()
171+ logger .info (f"Results from the action: { action .results } " )
164172
165173 logger .info ("Wait for upgrade to complete" )
166174 async with ops_test .fast_forward ("60s" ):
@@ -227,9 +235,14 @@ async def test_fail_and_rollback(ops_test, charm, continuous_writes) -> None:
227235
228236 logger .info ("Wait for upgrade to fail" )
229237
238+ # Highest to lowest unit number
239+ refresh_order = sorted (
240+ application .units , key = lambda unit : int (unit .name .split ("/" )[1 ]), reverse = True
241+ )
242+
230243 await ops_test .model .block_until (
231244 lambda : application .status == "blocked"
232- and "incompatible" in application . status_message . lower () ,
245+ and "Refresh incompatible" in refresh_order [ 0 ]. workload_status_message ,
233246 timeout = TIMEOUT ,
234247 )
235248
@@ -244,9 +257,24 @@ async def test_fail_and_rollback(ops_test, charm, continuous_writes) -> None:
244257 await ops_test .model .block_until (lambda : application .status == "blocked" , timeout = TIMEOUT )
245258
246259 logger .info ("Wait for application to recover" )
260+ async with ops_test .fast_forward ("60s" ):
261+ await ops_test .model .block_until (
262+ lambda : all (unit .workload_status == "active" for unit in application .units ),
263+ timeout = 60 * 3 ,
264+ )
265+
266+ sleep (60 )
267+
268+ leader_unit = await get_leader_unit (ops_test , DATABASE_APP_NAME )
269+ logger .info (f"Run resume-refresh action on { leader_unit .name } " )
270+ action = await leader_unit .run_action ("resume-refresh" )
271+ await action .wait ()
272+ logger .info (f"Results from the action: { action .results } " )
273+
274+ logger .info ("Wait for upgrade to complete" )
247275 async with ops_test .fast_forward ("60s" ):
248276 await ops_test .model .wait_for_idle (
249- apps = [DATABASE_APP_NAME ], status = "active" , timeout = TIMEOUT
277+ apps = [DATABASE_APP_NAME ], status = "active" , idle_period = 30 , timeout = TIMEOUT
250278 )
251279
252280 logger .info ("Ensure continuous_writes after rollback procedure" )
0 commit comments