@@ -29,8 +29,8 @@ class Upgrade(upgrade.Upgrade):
2929 @property
3030 def unit_state (self ) -> typing .Optional [str ]:
3131 if (
32- self ._unit_workload_version is not None
33- and self ._unit_workload_version != self ._app_workload_version
32+ self ._unit_workload_container_version is not None
33+ and self ._unit_workload_container_version != self ._app_workload_container_version
3434 ):
3535 logger .debug ("Unit upgrade state: outdated" )
3636 return "outdated"
@@ -40,28 +40,31 @@ def unit_state(self) -> typing.Optional[str]:
4040 def unit_state (self , value : str ) -> None :
4141 if value == "healthy" :
4242 # Set snap revision on first install
43- self ._unit_databag ["snap_revision" ] = snap .REVISION
44- logger .debug (f"Saved { snap .REVISION = } in unit databag while setting state healthy" )
43+ self ._unit_workload_container_version = snap .REVISION
44+ self ._unit_workload_version = self ._current_versions ["workload" ]
45+ logger .debug (
46+ f'Saved { snap .REVISION = } and { self ._current_versions ["workload" ]= } in unit databag while setting state healthy'
47+ )
4548 # Super call
4649 upgrade .Upgrade .unit_state .fset (self , value )
4750
4851 def _get_unit_healthy_status (
4952 self , * , workload_status : typing .Optional [ops .StatusBase ]
5053 ) -> ops .StatusBase :
51- if self ._unit_workload_version == self ._app_workload_version :
54+ if self ._unit_workload_container_version == self ._app_workload_container_version :
5255 if isinstance (workload_status , ops .WaitingStatus ):
5356 return ops .WaitingStatus (
54- f'Router { self ._current_versions [ "workload" ] } rev { self ._unit_workload_version } '
57+ f'Router { self ._unit_workload_version } ; Snap rev { self ._unit_workload_container_version } ; Charmed operator { self . _current_versions [ "charm" ] } '
5558 )
5659 return ops .ActiveStatus (
57- f'Router { self ._current_versions [ "workload" ] } rev { self ._unit_workload_version } running '
60+ f'Router { self ._unit_workload_version } running; Snap rev { self ._unit_workload_container_version } ; Charmed operator { self . _current_versions [ "charm" ] } '
5861 )
5962 if isinstance (workload_status , ops .WaitingStatus ):
6063 return ops .WaitingStatus (
61- f'Charmed operator upgraded. Router { self ._current_versions [ "workload" ] } rev { self ._unit_workload_version } '
64+ f'Router { self . _unit_workload_version } ; Snap rev { self ._unit_workload_container_version } (outdated); Charmed operator { self ._current_versions [ "charm" ] } '
6265 )
63- return ops .WaitingStatus (
64- f'Charmed operator upgraded. Router { self ._current_versions [ "workload" ] } rev { self ._unit_workload_version } running '
66+ return ops .ActiveStatus (
67+ f'Router { self ._unit_workload_version } running; Snap rev { self ._unit_workload_container_version } (outdated); Charmed operator { self . _current_versions [ "charm" ] } '
6568 )
6669
6770 @property
@@ -76,7 +79,7 @@ def app_status(self) -> typing.Optional[ops.StatusBase]:
7679 return super ().app_status
7780
7881 @property
79- def _unit_workload_versions (self ) -> typing .Dict [str , str ]:
82+ def _unit_workload_container_versions (self ) -> typing .Dict [str , str ]:
8083 """{Unit name: installed snap revision}"""
8184 versions = {}
8285 for unit in self ._sorted_units :
@@ -85,15 +88,28 @@ def _unit_workload_versions(self) -> typing.Dict[str, str]:
8588 return versions
8689
8790 @property
88- def _unit_workload_version (self ) -> typing .Optional [str ]:
91+ def _unit_workload_container_version (self ) -> typing .Optional [str ]:
8992 """Installed snap revision for this unit"""
9093 return self ._unit_databag .get ("snap_revision" )
9194
95+ @_unit_workload_container_version .setter
96+ def _unit_workload_container_version (self , value : str ):
97+ self ._unit_databag ["snap_revision" ] = value
98+
9299 @property
93- def _app_workload_version (self ) -> str :
100+ def _app_workload_container_version (self ) -> str :
94101 """Snap revision for current charm code"""
95102 return snap .REVISION
96103
104+ @property
105+ def _unit_workload_version (self ) -> typing .Optional [str ]:
106+ """Installed MySQL Router version for this unit"""
107+ return self ._unit_databag .get ("workload_version" )
108+
109+ @_unit_workload_version .setter
110+ def _unit_workload_version (self , value : str ):
111+ self ._unit_databag ["workload_version" ] = value
112+
97113 def reconcile_partition (self , * , action_event : ops .ActionEvent = None ) -> None :
98114 """Handle Juju action to confirm first upgraded unit is healthy and resume upgrade."""
99115 if action_event :
@@ -121,7 +137,7 @@ def upgrade_resumed(self, value: bool):
121137
122138 @property
123139 def authorized (self ) -> bool :
124- assert self ._unit_workload_version != self ._app_workload_version
140+ assert self ._unit_workload_container_version != self ._app_workload_container_version
125141 for index , unit in enumerate (self ._sorted_units ):
126142 if unit .name == self ._unit .name :
127143 # Higher number units have already upgraded
@@ -131,7 +147,8 @@ def authorized(self) -> bool:
131147 return self .upgrade_resumed
132148 return True
133149 if (
134- self ._unit_workload_versions .get (unit .name ) != self ._app_workload_version
150+ self ._unit_workload_container_versions .get (unit .name )
151+ != self ._app_workload_container_version
135152 or self ._peer_relation .data [unit ].get ("state" ) != "healthy"
136153 ):
137154 # Waiting for higher number units to upgrade
@@ -148,5 +165,8 @@ def upgrade_unit(
148165 logger .debug (f"Upgrading { self .authorized = } " )
149166 self .unit_state = "upgrading"
150167 workload_ .upgrade (unit = self ._unit , tls = tls , exporter_config = exporter_config )
151- self ._unit_databag ["snap_revision" ] = snap .REVISION
152- logger .debug (f"Saved { snap .REVISION = } in unit databag after upgrade" )
168+ self ._unit_workload_container_version = snap .REVISION
169+ self ._unit_workload_version = self ._current_versions ["workload" ]
170+ logger .debug (
171+ f'Saved { snap .REVISION = } and { self ._current_versions ["workload" ]= } in unit databag after upgrade'
172+ )
0 commit comments