Skip to content

Commit

Permalink
[DPE-2636] Move to Mongodb 6/edge
Browse files Browse the repository at this point in the history
Add support for snap's 6/edge channel as well as migrating from older ```mongo``` CLI to ```mongosh```.

Creates a constant: ```MONGO_SHELL```, that holds the value of the CLI name that is going to be used across the operator.
  • Loading branch information
phvalguima authored Sep 22, 2023
1 parent 92f35e4 commit 04480b0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ jobs:
with:
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
# TODO - wait until track request is approved:
# https://discourse.charmhub.io/t/request-track-6-for-charmed-mongodb-operator/11900
# - name: Upload charm to charmhub
# uses: canonical/charming-actions/[email protected]
# with:
# credentials: "${{ secrets.CHARMHUB_TOKEN }}"
# github-token: "${{ secrets.GITHUB_TOKEN }}"
# channel: "6/edge"
- name: Upload charm to charmhub
uses: canonical/charming-actions/[email protected]
with:
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
channel: "6/edge"
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.mongo"
) -> 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
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Config:
MONGODB_SNAP_DATA_DIR = "/var/snap/charmed-mongodb/current"
MONGOD_CONF_DIR = f"{MONGODB_SNAP_DATA_DIR}/etc/mongod"
MONGOD_CONF_FILE_PATH = f"{MONGOD_CONF_DIR}/mongod.conf"
SNAP_PACKAGES = [("charmed-mongodb", "5/edge", 84)]
SNAP_PACKAGES = [("charmed-mongodb", "6/edge", 87)]

class Role:
"""Role config names for MongoDB Charm."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def mongo_tls_command(ops_test: OpsTest) -> str:
replica_set_uri = f"mongodb://{hosts}/admin?replicaSet={app}"

return (
f"charmed-mongodb.mongo '{replica_set_uri}' --eval 'rs.status()'"
f"charmed-mongodb.mongosh '{replica_set_uri}' --eval 'rs.status()'"
f" --tls --tlsCAFile {EXTERNAL_CERT_PATH}"
f" --tlsCertificateKeyFile {EXTERNAL_PEM_PATH}"
)
Expand Down
4 changes: 3 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 @@ -180,7 +181,8 @@ 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.mongo '{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.mongo '{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 04480b0

Please sign in to comment.