Skip to content

Commit

Permalink
Merge branch '6/edge' into update-ci-int-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri authored Feb 16, 2024
2 parents 3105406 + 3d98182 commit 5c64e45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 12 additions & 3 deletions lib/charms/mongodb/v0/config_server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

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


class ClusterProvider(Object):
Expand Down Expand Up @@ -275,7 +275,13 @@ def _on_relation_broken(self, event: RelationBrokenEvent) -> None:

def is_mongos_running(self) -> bool:
"""Returns true if mongos service is running."""
with MongosConnection(None, f"mongodb://{MONGOS_SOCKET_URI_FMT}") as mongo:
connection_uri = f"mongodb://{self.charm.get_mongos_host()}"

# when running internally, connections through Unix Domain sockets do not need port.
if self.charm.is_external_client:
connection_uri = connection_uri + f":{Config.MONGOS_PORT}"

with MongosConnection(None, connection_uri) as mongo:
return mongo.is_ready

def update_config_server_db(self, config_server_db) -> bool:
Expand All @@ -285,7 +291,10 @@ def update_config_server_db(self, config_server_db) -> bool:

mongos_config = self.charm.mongos_config
mongos_start_args = get_mongos_args(
mongos_config, snap_install=True, config_server_db=config_server_db
mongos_config,
snap_install=True,
config_server_db=config_server_db,
external_connectivity=self.charm.is_external_client,
)
add_args_to_env("MONGOS_ARGS", mongos_start_args)
return True
Expand Down
9 changes: 5 additions & 4 deletions lib/charms/mongodb/v1/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

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

# path to store mongodb ketFile
KEY_FILE = "keyFile"
Expand Down Expand Up @@ -96,6 +96,7 @@ def get_mongos_args(
config,
snap_install: bool = False,
config_server_db: str = None,
external_connectivity: bool = True,
) -> str:
"""Returns the arguments used for starting mongos on a config-server side application.
Expand All @@ -104,9 +105,9 @@ def get_mongos_args(
"""
# suborinate charm which provides its own config_server_db, should only use unix domain socket
binding_ips = (
f"--bind_ip {MONGODB_COMMON_DIR}/var/mongodb-27018.sock"
if config_server_db
else "--bind_ip_all"
"--bind_ip_all"
if external_connectivity
else f"--bind_ip {MONGODB_COMMON_DIR}/var/mongodb-27018.sock"
)

# mongos running on the config server communicates through localhost
Expand Down

0 comments on commit 5c64e45

Please sign in to comment.