Skip to content

Commit e4b8a80

Browse files
committed
Add application.get_status to get the most up to date status from API
Introduces an internal self._status which is initially set to the 'unknown' which has the lowest severity. The regular property self.status uses both self._status and the unit statuses to derive the most severe status as the application status
1 parent d1c9cb2 commit e4b8a80

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

juju/application.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,15 @@ def status(self):
9191
"""
9292
status = self.safe_data['status']['current']
9393
if status == "unset":
94-
unit_status = []
94+
known_statuses = []
9595
for unit in self.units:
96-
unit_status.append(unit.workload_status)
97-
return derive_status(unit_status)
96+
known_statuses.append(unit.workload_status)
97+
# If the self.get_status() is called (i.e. the status
98+
# is received by FullStatus from the API) then add
99+
# that into this computation as it might be more up
100+
# to date (and more severe).
101+
known_statuses.append(self._status)
102+
return derive_status(known_statuses)
98103
return status
99104

100105
@property
@@ -445,6 +450,23 @@ async def get_actions(self, schema=False):
445450
actions = {k: v.description for k, v in actions.items()}
446451
return actions
447452

453+
async def get_status(self):
454+
"""Get the application status using info from the FullStatus
455+
as well, because it might be more up to date than our model
456+
457+
:return: str status
458+
"""
459+
460+
client_facade = client.ClientFacade.from_connection(self.connection)
461+
462+
full_status = await client_facade.FullStatus(patterns=None)
463+
_app = full_status.applications.get(self.name, None)
464+
if not _app:
465+
raise JujuError(f"application is not in FullStatus : {self.name}")
466+
467+
self._status = derive_status([self.status, _app.status.status])
468+
return self._status
469+
448470
def attach_resource(self, resource_name, file_name, file_obj):
449471
"""Updates the resource for an application by uploading file from
450472
local disk to the Juju controller.

0 commit comments

Comments
 (0)