@@ -173,7 +173,7 @@ def _cos_exporter_config(self, event) -> typing.Optional[relations.cos.ExporterC
173
173
if cos_relation_exists :
174
174
return self ._cos_relation .exporter_user_config
175
175
176
- def get_workload (self , * , event , refresh : charm_refresh .Common ):
176
+ def get_workload (self , * , event , refresh : charm_refresh .Common = None ):
177
177
"""MySQL Router workload
178
178
179
179
Pass `refresh` if `self.refresh` is not set
@@ -214,10 +214,10 @@ def _prioritize_statuses(statuses: typing.List[ops.StatusBase]) -> ops.StatusBas
214
214
return status
215
215
return ops .ActiveStatus ()
216
216
217
- def _determine_app_status (self , * , event , refresh : charm_refresh . Common ) -> ops .StatusBase :
217
+ def _determine_app_status (self , * , event ) -> ops .StatusBase :
218
218
"""Report app status."""
219
- if refresh .app_status_higher_priority :
220
- return refresh .app_status_higher_priority
219
+ if self . refresh .app_status_higher_priority :
220
+ return self . refresh .app_status_higher_priority
221
221
statuses = []
222
222
if self ._status :
223
223
statuses .append (self ._status )
@@ -226,32 +226,32 @@ def _determine_app_status(self, *, event, refresh: charm_refresh.Common) -> ops.
226
226
statuses .append (status )
227
227
return self ._prioritize_statuses (statuses )
228
228
229
- def _determine_unit_status (self , * , event , refresh : charm_refresh . Common ) -> ops .StatusBase :
229
+ def _determine_unit_status (self , * , event ) -> ops .StatusBase :
230
230
"""Report unit status."""
231
- if refresh .unit_status_higher_priority :
232
- return refresh .unit_status_higher_priority
231
+ if self . refresh .unit_status_higher_priority :
232
+ return self . refresh .unit_status_higher_priority
233
233
statuses = []
234
- workload_ = self .get_workload (event = event , refresh = refresh )
234
+ workload_ = self .get_workload (event = event )
235
235
if status := workload_ .status :
236
236
statuses .append (status )
237
237
# only in machine charms
238
238
if self ._ha_cluster :
239
239
if status := self ._ha_cluster .get_unit_juju_status ():
240
240
statuses .append (status )
241
- refresh_lower_priority = refresh .unit_status_lower_priority (
241
+ refresh_lower_priority = self . refresh .unit_status_lower_priority (
242
242
workload_is_running = isinstance (workload_ , workload .RunningWorkload )
243
243
)
244
244
if (not statuses or statuses == [ops .WaitingStatus ()]) and refresh_lower_priority :
245
245
return refresh_lower_priority
246
246
return self ._prioritize_statuses (statuses )
247
247
248
- def set_status (self , * , event , refresh : charm_refresh . Common , app = True , unit = True ) -> None :
248
+ def set_status (self , * , event , app = True , unit = True ) -> None :
249
249
"""Set charm status."""
250
250
if app and self ._unit_lifecycle .authorized_leader :
251
- self .app .status = self ._determine_app_status (event = event , refresh = refresh )
251
+ self .app .status = self ._determine_app_status (event = event )
252
252
logger .debug (f"Set app status to { self .app .status } " )
253
253
if unit :
254
- self .unit .status = self ._determine_unit_status (event = event , refresh = refresh )
254
+ self .unit .status = self ._determine_unit_status (event = event )
255
255
logger .debug (f"Set unit status to { self .unit .status } " )
256
256
257
257
@abc .abstractmethod
@@ -283,28 +283,26 @@ def _update_endpoints(self) -> None:
283
283
# Handlers
284
284
# =======================
285
285
286
- def reconcile (self , event = None , * , refresh : charm_refresh . Common = None ) -> None : # noqa: C901
286
+ def reconcile (self , event = None ) -> None : # noqa: C901
287
287
"""Handle most events."""
288
- if refresh is None :
289
- refresh = self .refresh
290
- workload_ = self .get_workload (event = event , refresh = refresh )
288
+ workload_ = self .get_workload (event = event )
291
289
logger .debug (
292
290
"State of reconcile "
293
291
f"{ self ._unit_lifecycle .authorized_leader = } , "
294
292
f"{ isinstance (workload_ , workload .RunningWorkload )= } , "
295
293
f"{ workload_ .container_ready = } , "
296
- f"{ refresh .workload_allowed_to_start = } , "
294
+ f"{ self . refresh .workload_allowed_to_start = } , "
297
295
f"{ self ._database_requires .is_relation_breaking (event )= } , "
298
296
f"{ self ._database_requires .does_relation_exist ()= } , "
299
- f"{ refresh .in_progress = } , "
297
+ f"{ self . refresh .in_progress = } , "
300
298
f"{ self ._cos_relation .is_relation_breaking (event )= } "
301
299
)
302
- if isinstance (refresh , charm_refresh .Machines ):
300
+ if isinstance (self . refresh , charm_refresh .Machines ):
303
301
workload_ .install (
304
302
unit = self .unit ,
305
303
model_uuid = self .model .uuid ,
306
- snap_revision = refresh .pinned_snap_revision ,
307
- refresh = refresh ,
304
+ snap_revision = self . refresh .pinned_snap_revision ,
305
+ refresh = self . refresh ,
308
306
)
309
307
self .unit .set_workload_version (workload_ .version )
310
308
@@ -315,13 +313,13 @@ def reconcile(self, event=None, *, refresh: charm_refresh.Common = None) -> None
315
313
try :
316
314
if self ._unit_lifecycle .authorized_leader :
317
315
if self ._database_requires .is_relation_breaking (event ):
318
- if refresh .in_progress :
316
+ if self . refresh .in_progress :
319
317
logger .warning (
320
318
"Modifying relations during an upgrade is not supported. The charm may be in a broken, unrecoverable state. Re-deploy the charm"
321
319
)
322
320
self ._database_provides .delete_all_databags ()
323
321
elif (
324
- not refresh .in_progress
322
+ not self . refresh .in_progress
325
323
and isinstance (workload_ , workload .RunningWorkload )
326
324
and workload_ .container_ready
327
325
):
@@ -346,13 +344,17 @@ def reconcile(self, event=None, *, refresh: charm_refresh.Common = None) -> None
346
344
certificate = self ._tls_certificate ,
347
345
certificate_authority = self ._tls_certificate_authority ,
348
346
)
349
- if not refresh .in_progress and isinstance (workload_ , workload .RunningWorkload ):
347
+ if not self .refresh .in_progress and isinstance (
348
+ workload_ , workload .RunningWorkload
349
+ ):
350
350
self ._reconcile_ports (event = event )
351
351
352
352
logger .debug (f"{ workload_ .status = } " )
353
353
if not workload_ .status :
354
- refresh .next_unit_allowed_to_refresh = True
355
- elif refresh .workload_allowed_to_start and workload_ .status == ops .WaitingStatus ():
354
+ self .refresh .next_unit_allowed_to_refresh = True
355
+ elif (
356
+ self .refresh .workload_allowed_to_start and workload_ .status == ops .WaitingStatus ()
357
+ ):
356
358
# During scale up, this code should not be reached before the first
357
359
# relation-created event is received on this unit since otherwise
358
360
# `charm_refresh.PeerRelationNotReady` would be raised
@@ -361,10 +363,10 @@ def reconcile(self, event=None, *, refresh: charm_refresh.Common = None) -> None
361
363
pass
362
364
else :
363
365
# Waiting for database requires relation; refresh can continue
364
- refresh .next_unit_allowed_to_refresh = True
365
- self .set_status (event = event , refresh = refresh )
366
+ self . refresh .next_unit_allowed_to_refresh = True
367
+ self .set_status (event = event )
366
368
except server_exceptions .Error as e :
367
369
# If not for `unit=False`, another `server_exceptions.Error` could be thrown here
368
- self .set_status (event = event , refresh = refresh , unit = False )
370
+ self .set_status (event = event , unit = False )
369
371
self .unit .status = e .status
370
372
logger .debug (f"Set unit status to { self .unit .status } " )
0 commit comments