diff --git a/lib/charms/mongodb/v0/set_status.py b/lib/charms/mongodb/v0/set_status.py index f67fbd0ba..98d1dabac 100644 --- a/lib/charms/mongodb/v0/set_status.py +++ b/lib/charms/mongodb/v0/set_status.py @@ -4,7 +4,7 @@ # See LICENSE file for licensing details. import json import logging -from typing import Tuple +from typing import Optional, Tuple from charms.mongodb.v1.mongodb import MongoConfiguration, MongoDBConnection from ops.charm import CharmBase @@ -22,7 +22,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 2 +LIBPATCH = 3 AUTH_FAILED_CODE = 18 UNAUTHORISED_CODE = 13 @@ -223,6 +223,20 @@ def prioritize_statuses(self, statuses: Tuple) -> StatusBase: # if all statuses are active report mongodb status over sharding status return mongodb_status + def get_invalid_integration_status(self) -> Optional[StatusBase]: + """Returns a status if an invalid integration is present.""" + if not self.charm.cluster.is_valid_mongos_integration(): + return BlockedStatus( + "Relation to mongos not supported, config role must be config-server" + ) + + if not self.charm.backups.is_valid_s3_integration(): + return BlockedStatus( + "Relation to s3-integrator is not supported, config role must be config-server" + ) + + return self.charm.get_cluster_mismatched_revision_status() + def build_unit_status(mongodb_config: MongoConfiguration, unit_host: str) -> StatusBase: """Generates the status of a unit based on its status reported by mongod.""" diff --git a/src/charm.py b/src/charm.py index 6dc026400..0690ff78d 100755 --- a/src/charm.py +++ b/src/charm.py @@ -636,7 +636,7 @@ def _on_storage_detaching(self, event: StorageDetachingEvent) -> None: def _on_update_status(self, event: UpdateStatusEvent): # user-made mistakes might result in other incorrect statues. Prioritise informing users of # their mistake. - invalid_integration_status = self.get_invalid_integration_status() + invalid_integration_status = self.status.get_invalid_integration_status() if invalid_integration_status: self.status.set_and_share_status(invalid_integration_status) return @@ -1495,20 +1495,6 @@ def _is_removing_last_replica(self) -> bool: """Returns True if the last replica (juju unit) is getting removed.""" return self.app.planned_units() == 0 and len(self.peers_units) == 0 - def get_invalid_integration_status(self) -> Optional[StatusBase]: - """Returns a status if an invalid integration is present.""" - if not self.cluster.is_valid_mongos_integration(): - return BlockedStatus( - "Relation to mongos not supported, config role must be config-server" - ) - - if not self.backups.is_valid_s3_integration(): - return BlockedStatus( - "Relation to s3-integrator is not supported, config role must be config-server" - ) - - return self.get_cluster_mismatched_revision_status() - def is_relation_feasible(self, rel_interface) -> bool: """Returns true if the proposed relation is feasible.""" if self.is_sharding_component() and rel_interface in Config.Relations.DB_RELATIONS: