diff --git a/lib/charms/mongodb/v0/helpers.py b/lib/charms/mongodb/v0/helpers.py index 2232545e8..b7aa6f1b5 100644 --- a/lib/charms/mongodb/v0/helpers.py +++ b/lib/charms/mongodb/v0/helpers.py @@ -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" @@ -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. diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index 56da305c5..bc71fc748 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -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 @@ -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" diff --git a/tests/integration/tls_tests/helpers.py b/tests/integration/tls_tests/helpers.py index cfc7fd121..0f7f8ff9e 100644 --- a/tests/integration/tls_tests/helpers.py +++ b/tests/integration/tls_tests/helpers.py @@ -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 @@ -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}" )