Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHORE for [DPE-5095] move over code to be re-used by K8s into correct lib #464

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/charms/mongodb/v0/set_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# 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 charms.mongodb.v1.mongodb import MongoDBConfiguration, MongoDBConnection
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved
from ops.charm import CharmBase
from ops.framework import Object
from ops.model import ActiveStatus, BlockedStatus, StatusBase, WaitingStatus
Expand All @@ -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
Expand Down Expand Up @@ -223,8 +223,22 @@ 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"
)

def build_unit_status(mongodb_config: MongoConfiguration, unit_host: str) -> StatusBase:
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: MongoDBConfiguration, unit_host: str) -> StatusBase:
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved
"""Generates the status of a unit based on its status reported by mongod."""
try:
with MongoDBConnection(mongodb_config) as mongo:
Expand Down
16 changes: 1 addition & 15 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.set_status.get_invalid_integration_status()
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved
if invalid_integration_status:
self.status.set_and_share_status(invalid_integration_status)
return
Expand Down Expand Up @@ -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:
Expand Down
Loading