Skip to content

Commit

Permalink
rollback license relocation (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
delgod authored May 19, 2023
1 parent 9516429 commit 5fca9e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
File renamed without changes.
33 changes: 17 additions & 16 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ def on_mongod_pebble_ready(self, event) -> None:
self.unit.status = ActiveStatus()

def _on_start(self, event) -> None:
"""Initialize MongoDB.
"""Initialise MongoDB.
Initialization of replSet should be made once after start.
Initialisation 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.
This event handler is deferred if initialisation of MongoDB
replica set fails.
By doing so, it is guaranteed that another
attempt at initialisation will be made.
Initial operator user can be created only through localhost connection.
see https://www.mongodb.com/docs/manual/core/localhost-exception/
Expand All @@ -173,7 +174,7 @@ def _on_start(self, event) -> None:
return

if not container.exists("/tmp/mongodb-27017.sock"):
logger.debug("mongod socket is not ready yet.")
logger.debug("The mongod socket is not ready yet.")
event.defer()
return

Expand Down Expand Up @@ -232,18 +233,18 @@ def _reconfigure(self, event) -> None:
try:
replset_members = mongo.get_replset_members()

# compare set of mongod replica set members and juju hosts
# compare sets 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
logger.info("Reconfigure replica set")
for member in replset_members - self.mongodb_config.hosts:
logger.debug("Removing %s from replica set", member)
logger.debug("Removing %s from the replica set", member)
mongo.remove_replset_member(member)
for member in self.mongodb_config.hosts - replset_members:
logger.debug("Adding %s to replica set", member)
logger.debug("Adding %s to the replica set", member)
with MongoDBConnection(
self.mongodb_config, member, direct=True
) as direct_mongo:
Expand All @@ -269,7 +270,6 @@ def _mongodb_exporter_layer(self) -> Layer:
"mongodb_exporter": {
"override": "replace",
"summary": "mongodb_exporter",
# todo pass URI in correct way
"command": "mongodb_exporter --collector.diagnosticdata --compatible-mode",
"startup": "enabled",
"user": UNIX_USER,
Expand Down Expand Up @@ -368,8 +368,9 @@ def mongodb_config(self) -> MongoDBConfiguration:
tls_internal=internal_ca is not None,
)

def _pull_licenses(self, container: Container) -> None:
"""Pull licenses from workload."""
@staticmethod
def _pull_licenses(container: Container) -> None:
"""Pull licences from workload."""
licenses = [
"snap",
"rock",
Expand All @@ -381,7 +382,7 @@ def _pull_licenses(self, container: Container) -> None:
for license_name in licenses:
try:
license_file = container.pull(path=f"/licenses/LICENSE-{license_name}")
f = open(f"src/licenses/LICENSE-{license_name}", "x")
f = open("LICENSE", "x")
f.write(str(license_file.read()))
f.close()
except FileExistsError:
Expand Down Expand Up @@ -452,7 +453,7 @@ def _fix_data_dir(container: Container) -> None:
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"
assert len(paths) == 1, "list_files doesn't return only the directory itself"
logger.debug(f"Data directory ownership: {paths[0].user}:{paths[0].group}")
if paths[0].user != UNIX_USER or paths[0].group != UNIX_GROUP:
container.exec(f"chown -o {UNIX_USER} -g {UNIX_GROUP} -R {DATA_DIR}".split(" "))
Expand Down Expand Up @@ -547,7 +548,7 @@ def monitor_config(self) -> MongoDBConfiguration:
username="monitor",
# MongoDB Exporter can only connect to one replica - not the entire set.
password=self.get_secret("app", "monitor_password"),
hosts=[self.get_hostname_by_unit(self.unit.name)],
hosts={self.get_hostname_by_unit(self.unit.name)},
roles={"monitor"},
tls_external=self.tls.get_tls_files("unit") is not None,
tls_internal=self.tls.get_tls_files("app") is not None,
Expand Down Expand Up @@ -595,7 +596,7 @@ def _on_set_password(self, event: ActionEvent) -> None:
mongo.set_user_password(username, new_password)
except NotReadyError:
event.fail(
"Failed changing the password: Not all members healthy or finished initial sync."
"Failed to change the password: Not all members healthy or finished initial sync."
)
return
except PyMongoError as e:
Expand Down

0 comments on commit 5fca9e9

Please sign in to comment.