Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
49 changes: 21 additions & 28 deletions lib/charms/mysql/v0/async_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
MySQLPromoteClusterToPrimaryError,
MySQLRejoinClusterError,
)
from constants import (
BACKUPS_PASSWORD_KEY,
BACKUPS_USERNAME,
CLUSTER_ADMIN_PASSWORD_KEY,
CLUSTER_ADMIN_USERNAME,
MONITORING_PASSWORD_KEY,
MONITORING_USERNAME,
PEER,
ROOT_PASSWORD_KEY,
ROOT_USERNAME,
SERVER_CONFIG_PASSWORD_KEY,
SERVER_CONFIG_USERNAME,
)
from ops import (
ActionEvent,
ActiveStatus,
Expand All @@ -31,20 +44,6 @@
from ops.framework import Object
from tenacity import RetryError, Retrying, stop_after_attempt, wait_fixed

from constants import (
BACKUPS_PASSWORD_KEY,
BACKUPS_USERNAME,
CLUSTER_ADMIN_PASSWORD_KEY,
CLUSTER_ADMIN_USERNAME,
MONITORING_PASSWORD_KEY,
MONITORING_USERNAME,
PEER,
ROOT_PASSWORD_KEY,
ROOT_USERNAME,
SERVER_CONFIG_PASSWORD_KEY,
SERVER_CONFIG_USERNAME,
)

if typing.TYPE_CHECKING:
from charm import MySQLOperatorCharm

Expand All @@ -53,7 +52,7 @@
# The unique Charmhub library identifier, never change it
LIBID = "4de21f1a022c4e2c87ac8e672ec16f6a"
LIBAPI = 0
LIBPATCH = 9
LIBPATCH = 10

RELATION_OFFER = "replication-offer"
RELATION_CONSUMER = "replication"
Expand Down Expand Up @@ -407,9 +406,7 @@ def idle(self) -> bool:
# transitional state between relation created and setup_action
return False

if self.state not in [States.READY, States.UNINITIALIZED]:
return False
return True
return self.state in [States.READY, States.UNINITIALIZED]

@property
def secret(self) -> Secret | None:
Expand All @@ -430,7 +427,7 @@ def _get_secret(self) -> Secret:

def _on_create_replication(self, event: ActionEvent):
"""Promote the offer side to primary on initial setup."""
if not self._charm.app_peer_data.get("async-ready") == "true":
if self._charm.app_peer_data.get("async-ready") != "true":
event.fail("Relation created but not ready")
return

Expand Down Expand Up @@ -491,10 +488,8 @@ def _on_offer_created(self, event: RelationCreatedEvent):
):
# Test for a broken relation on the primary side
logger.error(
(
"Cannot setup async relation with primary cluster in blocked/read-only state\n"
"Remove the relation."
)
"Cannot setup async relation with primary cluster in blocked/read-only state\n"
"Remove the relation."
)
message = f"Cluster is in a blocked state. Remove {RELATION_OFFER} relation"
self._charm.unit.status = BlockedStatus(message)
Expand All @@ -503,10 +498,8 @@ def _on_offer_created(self, event: RelationCreatedEvent):
if not self.model.get_relation(RELATION_OFFER):
# safeguard against a deferred event a previous relation.
logger.error(
(
"Relation created running against removed relation.\n"
f"Remove {RELATION_OFFER} relation and retry."
)
"Relation created running against removed relation.\n"
f"Remove {RELATION_OFFER} relation and retry."
)
self._charm.unit.status = BlockedStatus(f"Remove {RELATION_OFFER} relation and retry")
return
Expand Down Expand Up @@ -887,7 +880,7 @@ def _on_consumer_non_leader_created(self, _):
# set waiting state to inhibit auto recovery, only when not already set
if self._charm.unit.is_leader():
return
if not self._charm.unit_peer_data.get("member-state") == "waiting":
if self._charm.unit_peer_data.get("member-state") != "waiting":
self._charm.unit_peer_data["member-state"] = "waiting"
self._charm.unit.status = WaitingStatus("waiting replica cluster be configured")

Expand Down
17 changes: 7 additions & 10 deletions lib/charms/mysql/v0/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,16 @@ def is_unit_blocked(self) -> bool:
list_backups_in_s3_path,
upload_content_to_s3,
)
from ops.charm import ActionEvent
from ops.framework import Object
from ops.jujuversion import JujuVersion
from ops.model import BlockedStatus, MaintenanceStatus

from constants import (
MYSQL_DATA_DIR,
PEER,
SERVER_CONFIG_PASSWORD_KEY,
SERVER_CONFIG_USERNAME,
)
from ops.charm import ActionEvent
from ops.framework import Object
from ops.jujuversion import JujuVersion
from ops.model import BlockedStatus, MaintenanceStatus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔


logger = logging.getLogger(__name__)

Expand All @@ -112,7 +111,7 @@ def is_unit_blocked(self) -> bool:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 15
LIBPATCH = 16

ANOTHER_S3_CLUSTER_REPOSITORY_ERROR_MESSAGE = "S3 repository claimed by another cluster"
MOVE_RESTORED_CLUSTER_TO_ANOTHER_S3_REPOSITORY_ERROR = (
Expand Down Expand Up @@ -249,9 +248,7 @@ def _on_list_backups(self, event: ActionEvent) -> None:
event.set_results({"backups": self._format_backups_list(backups)})
except Exception as e:
error_message = (
getattr(e, "message")
if hasattr(e, "message")
else "Failed to retrieve backup ids from S3"
e.message if hasattr(e, "message") else "Failed to retrieve backup ids from S3"
)
logger.error(error_message)
event.fail(error_message)
Expand Down Expand Up @@ -312,7 +309,7 @@ def _on_create_backup(self, event: ActionEvent) -> None:
f"Model Name: {self.model.name}\n"
f"Application Name: {self.model.app.name}\n"
f"Unit Name: {self.charm.unit.name}\n"
f"Juju Version: {str(juju_version)}\n"
f"Juju Version: {juju_version!s}\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

)

if not upload_content_to_s3(metadata, f"{backup_path}.metadata", s3_parameters):
Expand Down
Loading