Skip to content

Commit

Permalink
fix issues detected by linter (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
delgod authored May 4, 2023
1 parent e5356d3 commit 1726926
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/charms/mongodb/v0/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def create_role(self, role_name: str, privileges: dict, roles: dict = []):
Args:
role_name: name of the role to be added.
privileges: privledges to be associated with the role.
privileges: privileges to be associated with the role.
roles: List of roles from which this role inherits privileges.
"""
try:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ importlib-resources==5.12.0 ; python_full_version >= "3.8.10" and python_version
jsonschema==4.17.3 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:0f864437ab8b6076ba6707453ef8f98a6a0d512a80e93f8abdb676f737ecb60d \
--hash=sha256:a870ad254da1a8ca84b6a2905cac29d265f805acc57af304784962a2aa6508f6
ops==2.2.0; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
ops==2.2.0 ; python_full_version >= "3.8.10" and python_full_version < "4.0.0" \
--hash=sha256:14d4c43f4a4dc0830af1b2cb21313ef93308d3c389f7bedecc14a70b69000b64 \
--hash=sha256:90fa55249f5c3a7bcb7cc73731227eac867f9bb8426100d10724fe461de142a8
pkgutil-resolve-name==1.3.10 ; python_full_version >= "3.8.10" and python_version < "3.9" \
Expand Down
44 changes: 23 additions & 21 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Run the developer's favourite document database — MongoDB! Charm for MongoDB is a fully supported,
automated solution from Canonical for running production-grade MongoDB on Kubernetes. It offers
simple, secure and highly available setup with automatic recovery on fail-over. The solution
a simple, secure and highly available setup with automatic recovery on fail-over. The solution
includes scaling and other capabilities.
"""

Expand Down Expand Up @@ -71,8 +71,8 @@ def __init__(self, *args):
def _generate_passwords(self) -> None:
"""Generate passwords and put them into peer relation.
The same keyFile and operator password on all members needed.
It means, it is needed to generate them once and share between members.
The same keyFile and operator password on all members are needed.
It means it is needed to generate them once and share between members.
NB: only leader should execute this function.
"""
if not self.get_secret("app", "operator_password"):
Expand Down Expand Up @@ -129,16 +129,17 @@ def _on_start(self, event) -> None:
Initialization of replSet should be made once after start.
MongoDB needs some time to become fully started.
This event handler is deferred if initialization of MongoDB
replica set fails. By doing so it is guaranteed that another
attempt at initialization will be made.
replica set fails.
By doing so, it is guaranteed that another attempt at initialization
will be made.
Initial operator user can be created only through localhost connection.
see https://www.mongodb.com/docs/manual/core/localhost-exception/
unfortunately, pymongo unable to create connection that considered
as local connection by MongoDB, even if socket connection used.
As result, where are only hackish ways to create initial user.
It is needed to install mongodb-clients inside charm container to make
this function work correctly.
unfortunately, pymongo unable to create a connection that is considered
as local connection by MongoDB, even if a socket connection is used.
As a result, there are only hackish ways to create initial user.
It is needed to install mongodb-clients inside the charm container
to make this function work correctly.
"""
if not self.unit.is_leader():
return
Expand Down Expand Up @@ -188,7 +189,7 @@ def _on_start(self, event) -> None:
self.app_peer_data["db_initialised"] = "True"

def _reconfigure(self, event) -> None:
"""Reconfigure replicat set.
"""Reconfigure replica set.
The amount replicas in the MongoDB replica set is updated.
"""
Expand All @@ -207,12 +208,12 @@ def _reconfigure(self, event) -> None:
try:
replset_members = mongo.get_replset_members()

# compare set of mongod replica set members and juju hosts
# to avoid the unnecessary reconfiguration.
# compare a set of mongod replica set members and juju hosts
# to avoid unnecessary reconfiguration.
if replset_members == self.mongodb_config.hosts:
return

# remove members first, it is faster
# to remove members first, it is faster
logger.info("Reconfigure replica set")
for member in replset_members - self.mongodb_config.hosts:
logger.debug("Removing %s from replica set", member)
Expand Down Expand Up @@ -398,11 +399,12 @@ def _push_certificate_to_workload(self, container: Container) -> None:
group=UNIX_GROUP,
)

def _fix_data_dir(self, container: Container) -> None:
@staticmethod
def _fix_data_dir(container: Container) -> None:
"""Ensure the data directory for mongodb is writable for the "mongodb" user.
Until the ability to set fsGroup and fsGroupChangePolicy via Pod securityContext
is available we fix permissions incorrectly with chown.
is available, we fix permissions incorrectly with chown.
"""
paths = container.list_files(DATA_DIR, itself=True)
assert len(paths) == 1, "list_files doesn't return only directory itself"
Expand Down Expand Up @@ -433,11 +435,11 @@ def _init_user(self, container: Container) -> None:
Initial operator user can be created only through localhost connection.
see https://www.mongodb.com/docs/manual/core/localhost-exception/
unfortunately, pymongo unable to create connection that considered
as local connection by MongoDB, even if socket connection used.
As a result, where are only hackish ways to create initial user.
It is needed to install mongodb-clients inside charm container to make
this function work correctly.
unfortunately, pymongo unable to create a connection that is considered
as local connection by MongoDB, even if a socket connection is used.
As a result, there are only hackish ways to create initial user.
It is needed to install mongodb-clients inside the charm container
to make this function work correctly.
"""
if "user_created" in self.app_peer_data:
return
Expand Down
1 change: 1 addition & 0 deletions tests/integration/ha_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ async def get_process_pid(
container_name,
unit_name,
"pgrep",
"-x",
process,
]
return_code, pid, _ = await ops_test.juju(*get_pid_commands)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ commands =
poetry run codespell {tox_root} --skip {tox_root}/.git --skip {tox_root}/.tox \
--skip {tox_root}/build --skip {tox_root}/lib --skip {tox_root}/venv \
--skip {tox_root}/.mypy_cache --skip {tox_root}/icon.svg \
--skip {tox_root}/poetry.lock
--skip {tox_root}/poetry.lock --skip {tox_root}/.idea
# pflake8 wrapper supports config from pyproject.toml
poetry run pflake8 {[vars]all_path}
poetry run isort --check-only --diff {[vars]all_path}
Expand Down

0 comments on commit 1726926

Please sign in to comment.