diff --git a/requirements.txt b/requirements.txt index 218fd9a4d..ff9e7f2be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ cosl==0.0.5 importlib-resources==5.10.2 tenacity==8.1.0 pymongo==4.3.3 -ops==2.0.0 +ops==2.4.1 jsonschema==4.17.3 cryptography==38.0.4 pure-sasl==0.6.2 @@ -12,7 +12,7 @@ pycparser==2.2 pkgutil-resolve-name==1.3.10 pydantic==1.10.7 pyrsistent==0.19.3 -pyyaml==6.0 +pyyaml==6.0.1 zipp==3.11.0 pyOpenSSL==22.1.0 typing-extensions==4.5.0 \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index 99f89d86a..f1a43d64e 100755 --- a/src/charm.py +++ b/src/charm.py @@ -209,11 +209,13 @@ def _peers(self) -> Optional[Relation]: return self.model.get_relation(Config.Relations.PEERS) @property - def _db_initialised(self) -> bool: + def db_initialised(self) -> bool: + """Check if MongoDB is initialised.""" return "db_initialised" in self.app_peer_data - @_db_initialised.setter - def _db_initialised(self, value): + @db_initialised.setter + def db_initialised(self, value): + """Set the db_initialised flag.""" if isinstance(value, bool): self.app_peer_data["db_initialised"] = str(value) else: @@ -345,7 +347,7 @@ def _on_relation_handler(self, event: RelationEvent) -> None: # only leader should configure replica set and app-changed-events can trigger the relation # changed hook resulting in no JUJU_REMOTE_UNIT if this is the case we should return # further reconfiguration can be successful only if a replica set is initialised. - if not (self.unit.is_leader() and event.unit) or not self._db_initialised: + if not (self.unit.is_leader() and event.unit) or not self.db_initialised: return with MongoDBConnection(self.mongodb_config) as mongo: @@ -455,7 +457,7 @@ def _on_update_status(self, event: UpdateStatusEvent): return # no need to report on replica set status until initialised - if not self._db_initialised: + if not self.db_initialised: return # Cannot check more advanced MongoDB statuses if mongod hasn't started. @@ -676,7 +678,7 @@ def _generate_secrets(self) -> None: def _update_hosts(self, event: LeaderElectedEvent) -> None: """Update replica set hosts and remove any unremoved replicas from the config.""" - if not self._db_initialised: + if not self.db_initialised: return self.process_unremoved_units(event) @@ -684,7 +686,7 @@ def _update_hosts(self, event: LeaderElectedEvent) -> None: def update_app_relation_data(self) -> None: """Helper function to update application relation data.""" - if not self._db_initialised: + if not self.db_initialised: return database_users = set() @@ -826,7 +828,7 @@ def _push_tls_certificate_to_workload(self) -> None: def _connect_mongodb_exporter(self) -> None: """Exposes the endpoint to mongodb_exporter.""" - if not self._db_initialised: + if not self.db_initialised: return # must wait for leader to set URI before connecting @@ -840,7 +842,7 @@ def _connect_mongodb_exporter(self) -> None: def _connect_pbm_agent(self) -> None: """Updates URI for pbm-agent.""" - if not self._db_initialised: + if not self.db_initialised: return # must wait for leader to set URI before any attempts to update are made @@ -879,7 +881,7 @@ def _run_diagnostic_command(self, cmd) -> None: logger.error(f"Exception occurred running '{cmd}'\n {e}") def _initialise_replica_set(self, event: StartEvent) -> None: - if self._db_initialised: + if self.db_initialised: # The replica set should be initialised only once. Check should be # external (e.g., check initialisation inside peer relation). We # shouldn't rely on MongoDB response because the data directory @@ -913,7 +915,7 @@ def _initialise_replica_set(self, event: StartEvent) -> None: return # replica set initialised properly and ready to go - self._db_initialised = True + self.db_initialised = True self.unit.status = ActiveStatus() def _unit_ip(self, unit: Unit) -> str: diff --git a/tox.ini b/tox.ini index 858f5402a..48c428ef7 100644 --- a/tox.ini +++ b/tox.ini @@ -72,7 +72,7 @@ pass_env = CI_PACKED_CHARMS deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands = @@ -86,7 +86,7 @@ pass_env = CI_PACKED_CHARMS deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands = @@ -100,7 +100,7 @@ pass_env = CI_PACKED_CHARMS deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands = @@ -114,7 +114,7 @@ pass_env = CI_PACKED_CHARMS deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands = @@ -128,7 +128,7 @@ pass_env = CI_PACKED_CHARMS deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands = @@ -147,7 +147,7 @@ pass_env = GCP_SECRET_KEY deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands = @@ -161,7 +161,7 @@ pass_env = CI_PACKED_CHARMS deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands = @@ -176,7 +176,7 @@ pass_env = CI_PACKED_CHARMS deps = pytest - juju==2.9.38.1 # juju 3.3.0 has issues with retrieving action results + juju==2.9.44.0 # The latest python-libjuju that supports both juju 2.9 and 3.0 pytest-operator -r {tox_root}/requirements.txt commands =