From ac8f8762e019542bf337b731f5b005a36c1ca90b Mon Sep 17 00:00:00 2001 From: Liam Young Date: Sat, 29 Feb 2020 14:47:48 +0000 Subject: [PATCH] Add required relations --- ops_openstack.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ops_openstack.py b/ops_openstack.py index 82fe7c8..435d992 100644 --- a/ops_openstack.py +++ b/ops_openstack.py @@ -10,6 +10,7 @@ from charmhelpers.fetch import ( ) from ops.model import ( ActiveStatus, + BlockedStatus, MaintenanceStatus, WaitingStatus, ) @@ -24,6 +25,8 @@ class OSBaseCharm(CharmBase): RESTART_MAP = {} + REQUIRED_RELATIONS = [] + def __init__(self, framework, key): super().__init__(framework, key) self.state.set_default(is_started=False) @@ -47,6 +50,14 @@ class OSBaseCharm(CharmBase): if self.state.is_paused: self.model.unit.status = MaintenanceStatus( "Paused. Use 'resume' action to resume normal service.") + missing_relations = [] + for relation in self.REQUIRED_RELATIONS: + if not self.framework.model.get_relation(relation): + missing_relations.append(relation) + if missing_relations: + self.model.unit.status = BlockedStatus( + 'Missing relations: {}'.format(', '.join(missing_relations))) + return if self.state.is_started: self.model.unit.status = ActiveStatus('Unit is ready') else: