Skip to content

Commit 57441ed

Browse files
authored
[MISC] Add linters (#667)
* Autolint * Manual changes * Final format * Typo * Bugbears
1 parent 1566086 commit 57441ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+637
-547
lines changed

lib/charms/mysql/v0/async_replication.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414
MySQLPromoteClusterToPrimaryError,
1515
MySQLRejoinClusterError,
1616
)
17+
from constants import (
18+
BACKUPS_PASSWORD_KEY,
19+
BACKUPS_USERNAME,
20+
CLUSTER_ADMIN_PASSWORD_KEY,
21+
CLUSTER_ADMIN_USERNAME,
22+
MONITORING_PASSWORD_KEY,
23+
MONITORING_USERNAME,
24+
PEER,
25+
ROOT_PASSWORD_KEY,
26+
ROOT_USERNAME,
27+
SERVER_CONFIG_PASSWORD_KEY,
28+
SERVER_CONFIG_USERNAME,
29+
)
1730
from ops import (
1831
ActionEvent,
1932
ActiveStatus,
@@ -31,20 +44,6 @@
3144
from ops.framework import Object
3245
from tenacity import RetryError, Retrying, stop_after_attempt, wait_fixed
3346

34-
from constants import (
35-
BACKUPS_PASSWORD_KEY,
36-
BACKUPS_USERNAME,
37-
CLUSTER_ADMIN_PASSWORD_KEY,
38-
CLUSTER_ADMIN_USERNAME,
39-
MONITORING_PASSWORD_KEY,
40-
MONITORING_USERNAME,
41-
PEER,
42-
ROOT_PASSWORD_KEY,
43-
ROOT_USERNAME,
44-
SERVER_CONFIG_PASSWORD_KEY,
45-
SERVER_CONFIG_USERNAME,
46-
)
47-
4847
if typing.TYPE_CHECKING:
4948
from charm import MySQLOperatorCharm
5049

@@ -53,7 +52,7 @@
5352
# The unique Charmhub library identifier, never change it
5453
LIBID = "4de21f1a022c4e2c87ac8e672ec16f6a"
5554
LIBAPI = 0
56-
LIBPATCH = 9
55+
LIBPATCH = 10
5756

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

410-
if self.state not in [States.READY, States.UNINITIALIZED]:
411-
return False
412-
return True
409+
return self.state in [States.READY, States.UNINITIALIZED]
413410

414411
@property
415412
def secret(self) -> Secret | None:
@@ -430,7 +427,7 @@ def _get_secret(self) -> Secret:
430427

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

@@ -491,10 +488,8 @@ def _on_offer_created(self, event: RelationCreatedEvent):
491488
):
492489
# Test for a broken relation on the primary side
493490
logger.error(
494-
(
495-
"Cannot setup async relation with primary cluster in blocked/read-only state\n"
496-
"Remove the relation."
497-
)
491+
"Cannot setup async relation with primary cluster in blocked/read-only state\n"
492+
"Remove the relation."
498493
)
499494
message = f"Cluster is in a blocked state. Remove {RELATION_OFFER} relation"
500495
self._charm.unit.status = BlockedStatus(message)
@@ -503,10 +498,8 @@ def _on_offer_created(self, event: RelationCreatedEvent):
503498
if not self.model.get_relation(RELATION_OFFER):
504499
# safeguard against a deferred event a previous relation.
505500
logger.error(
506-
(
507-
"Relation created running against removed relation.\n"
508-
f"Remove {RELATION_OFFER} relation and retry."
509-
)
501+
"Relation created running against removed relation.\n"
502+
f"Remove {RELATION_OFFER} relation and retry."
510503
)
511504
self._charm.unit.status = BlockedStatus(f"Remove {RELATION_OFFER} relation and retry")
512505
return
@@ -887,7 +880,7 @@ def _on_consumer_non_leader_created(self, _):
887880
# set waiting state to inhibit auto recovery, only when not already set
888881
if self._charm.unit.is_leader():
889882
return
890-
if not self._charm.unit_peer_data.get("member-state") == "waiting":
883+
if self._charm.unit_peer_data.get("member-state") != "waiting":
891884
self._charm.unit_peer_data["member-state"] = "waiting"
892885
self._charm.unit.status = WaitingStatus("waiting replica cluster be configured")
893886

lib/charms/mysql/v0/backups.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,16 @@ def is_unit_blocked(self) -> bool:
8787
list_backups_in_s3_path,
8888
upload_content_to_s3,
8989
)
90-
from ops.charm import ActionEvent
91-
from ops.framework import Object
92-
from ops.jujuversion import JujuVersion
93-
from ops.model import BlockedStatus, MaintenanceStatus
94-
9590
from constants import (
9691
MYSQL_DATA_DIR,
9792
PEER,
9893
SERVER_CONFIG_PASSWORD_KEY,
9994
SERVER_CONFIG_USERNAME,
10095
)
96+
from ops.charm import ActionEvent
97+
from ops.framework import Object
98+
from ops.jujuversion import JujuVersion
99+
from ops.model import BlockedStatus, MaintenanceStatus
101100

102101
logger = logging.getLogger(__name__)
103102

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

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

117116
ANOTHER_S3_CLUSTER_REPOSITORY_ERROR_MESSAGE = "S3 repository claimed by another cluster"
118117
MOVE_RESTORED_CLUSTER_TO_ANOTHER_S3_REPOSITORY_ERROR = (
@@ -249,9 +248,7 @@ def _on_list_backups(self, event: ActionEvent) -> None:
249248
event.set_results({"backups": self._format_backups_list(backups)})
250249
except Exception as e:
251250
error_message = (
252-
getattr(e, "message")
253-
if hasattr(e, "message")
254-
else "Failed to retrieve backup ids from S3"
251+
e.message if hasattr(e, "message") else "Failed to retrieve backup ids from S3"
255252
)
256253
logger.error(error_message)
257254
event.fail(error_message)
@@ -312,7 +309,7 @@ def _on_create_backup(self, event: ActionEvent) -> None:
312309
f"Model Name: {self.model.name}\n"
313310
f"Application Name: {self.model.app.name}\n"
314311
f"Unit Name: {self.charm.unit.name}\n"
315-
f"Juju Version: {str(juju_version)}\n"
312+
f"Juju Version: {juju_version!s}\n"
316313
)
317314

318315
if not upload_content_to_s3(metadata, f"{backup_path}.metadata", s3_parameters):

0 commit comments

Comments
 (0)