Skip to content

Commit

Permalink
Move charmed-mongodb.mongosh reference to a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
phvalguima committed Sep 22, 2023
1 parent 2694b00 commit 24474ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/charms/mongodb/v0/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
MONGODB_COMMON_DIR = "/var/snap/charmed-mongodb/common"
MONGODB_SNAP_DATA_DIR = "/var/snap/charmed-mongodb/current"

MONGO_SHELL = "charmed-mongodb.mongosh"

DATA_DIR = "/var/lib/mongodb"
CONF_DIR = "/etc/mongod"
Expand All @@ -49,9 +50,7 @@


# noinspection GrazieInspection
def get_create_user_cmd(
config: MongoDBConfiguration, mongo_path="charmed-mongodb.mongosh"
) -> List[str]:
def get_create_user_cmd(config: MongoDBConfiguration, mongo_path=MONGO_SHELL) -> List[str]:
"""Creates initial admin user for MongoDB.
Initial admin user can be created only through localhost connection.
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from uuid import uuid4

import pytest
from charms.mongodb.v0.helpers import MONGO_SHELL
from pymongo import MongoClient
from pymongo.errors import PyMongoError, ServerSelectionTimeoutError
from pytest_operator.plugin import OpsTest
Expand Down Expand Up @@ -181,7 +182,7 @@ async def test_monitor_user(ops_test: OpsTest) -> None:
hosts = ",".join(replica_set_hosts)
replica_set_uri = f"mongodb://monitor:{password}@{hosts}/admin?replicaSet=mongodb"

admin_mongod_cmd = f"charmed-mongodb.mongosh '{replica_set_uri}' --eval 'rs.conf()'"
admin_mongod_cmd = f"{MONGO_SHELL} '{replica_set_uri}' --eval 'rs.conf()'"
check_monitor_cmd = f"exec --unit {unit.name} -- {admin_mongod_cmd}"
return_code, _, _ = await ops_test.juju(*check_monitor_cmd.split())
assert return_code == 0, "command rs.conf() on monitor user does not work"
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/tls_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime

import ops
from charms.mongodb.v0.helpers import MONGO_SHELL
from pytest_operator.plugin import OpsTest
from tenacity import RetryError, Retrying, stop_after_attempt, wait_exponential

Expand Down Expand Up @@ -33,7 +34,7 @@ async def mongo_tls_command(ops_test: OpsTest) -> str:
replica_set_uri = f"mongodb://operator:" f"{password}@" f"{hosts}/admin?replicaSet={app}"

return (
f"charmed-mongodb.mongosh '{replica_set_uri}' --eval 'rs.status()'"
f"{MONGO_SHELL} '{replica_set_uri}' --eval 'rs.status()'"
f" --tls --tlsCAFile {EXTERNAL_CERT_PATH}"
f" --tlsCertificateKeyFile {EXTERNAL_PEM_PATH}"
)
Expand Down

0 comments on commit 24474ab

Please sign in to comment.