diff --git a/lib/charms/mongodb/v0/shards_interface.py b/lib/charms/mongodb/v0/shards_interface.py index 19375b2b4..7c633bfdf 100644 --- a/lib/charms/mongodb/v0/shards_interface.py +++ b/lib/charms/mongodb/v0/shards_interface.py @@ -9,12 +9,10 @@ import logging from charms.mongodb.v0.helpers import KEY_FILE -from charms.mongodb.v0.mongodb import MongoDBConnection, NotReadyError, PyMongoError from charms.mongodb.v0.users import MongoDBUser, OperatorUser from ops.charm import CharmBase from ops.framework import Object from ops.model import BlockedStatus, MaintenanceStatus -from tenacity import RetryError, Retrying, stop_after_delay, wait_fixed from config import Config @@ -139,12 +137,7 @@ def _on_relation_changed(self, event): # shards rely on the config server for secrets relation_data = event.relation.data[event.app] self.update_keyfile(key_file_contents=relation_data.get(KEYFILE_KEY)) - - try: - self.update_operator_password(new_password=relation_data.get(OPERATOR_PASSWORD_KEY)) - except RetryError: - self.charm.unit.status = BlockedStatus("Shard not added to config-server") - return + self.update_operator_password(new_password=relation_data.get(OPERATOR_PASSWORD_KEY)) self.charm.unit.status = MaintenanceStatus("Adding shard to config-server") @@ -167,24 +160,6 @@ def update_operator_password(self, new_password: str) -> None: if not new_password or new_password == current_password or not self.charm.unit.is_leader(): return - # updating operator password, usually comes after keyfile was updated, hence, the mongodb - # service was restarted. Sometimes this requires units getting insync again. - for attempt in Retrying(stop=stop_after_delay(60), wait=wait_fixed(3)): - with attempt: - # TODO, in the future use set_password from src/charm.py - this will require adding - # a library, for exceptions used in both charm code and lib code. - with MongoDBConnection(self.charm.mongodb_config) as mongo: - try: - mongo.set_user_password(OperatorUser.get_username(), new_password) - except NotReadyError: - logger.error( - "Failed changing the password: Not all members healthy or finished initial sync." - ) - raise - except PyMongoError as e: - logger.error(f"Failed changing the password: {e}") - raise - self.charm.set_secret( Config.Relations.APP_SCOPE, MongoDBUser.get_password_key_name_for_user(OperatorUser.get_username()),