Skip to content

Commit

Permalink
Change OCI image to new ROCK (#87)
Browse files Browse the repository at this point in the history
* Change OCI image to new ROCK

* Update tests to check for mongo cli
  • Loading branch information
jardon authored Jan 25, 2023
1 parent 784c51f commit ea8940d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ juju add-model dev
# Enable DEBUG logging
juju model-config logging-config="<root>=INFO;unit=DEBUG"
# Deploy the charm
juju deploy ./mongodb-k8s_ubuntu-20.04-amd64.charm --resource mongodb-image=mongo:4.4 --num-units=1
juju deploy ./mongodb-k8s_ubuntu-20.04-amd64.charm --resource mongodb-image=dataplatformoci/mongodb:5.0 --num-units=1
```

## Canonical Contributor Agreement
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ tls internal key - `string`; TLS external key for encryption inside the cluster
### Basic Usage
To deploy a single unit of MongoDB using its default configuration
```shell
juju deploy ./mongodb-k8s_ubuntu-20.04-amd64.charm --resource mongodb-image=mongo:4.4
juju deploy ./mongodb-k8s_ubuntu-20.04-amd64.charm --resource mongodb-image=dataplatformoci/mongodb:5.0
```

It is customary to use MongoDB with replication. Hence usually more than one unit (preferably an odd number to prohibit a "split-brain" scenario) is deployed. To deploy MongoDB with multiple replicas, specify the number of desired units with the `-n` option.
```shell
juju deploy ./mongodb-k8s_ubuntu-20.04-amd64.charm --resource mongodb-image=mongo:4.4
juju deploy ./mongodb-k8s_ubuntu-20.04-amd64.charm --resource mongodb-image=dataplatformoci/mongodb:5.0
-n <number_of_replicas>
```

Expand Down
2 changes: 1 addition & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resources:
mongodb-image:
type: oci-image
description: OCI image for mongodb
upstream-source: 'mongo:latest'
upstream-source: 'dataplatformoci/mongodb:5.0'
storage:
db:
type: filesystem
Expand Down
10 changes: 8 additions & 2 deletions tests/integration/ha_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
wait_fixed,
)

from tests.integration.helpers import APP_NAME, get_password, mongodb_uri, primary_host
from tests.integration.helpers import (
APP_NAME,
get_mongo_cmd,
get_password,
mongodb_uri,
primary_host,
)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
MONGODB_CONTAINER_NAME = "mongod"
Expand Down Expand Up @@ -440,7 +446,7 @@ async def set_log_level(ops_test: OpsTest, level: int, component: str = None) ->
"--container",
MONGODB_CONTAINER_NAME,
"",
"mongosh",
await get_mongo_cmd(ops_test, pass_unit),
"-u",
"operator",
"-p",
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ async def get_password(ops_test: OpsTest, unit_id: int) -> str:
return action.results["operator-password"]


async def get_mongo_cmd(ops_test: OpsTest, unit_name: str):
ls_code, _, _ = await ops_test.juju(f"ssh --container {unit_name} ls /usr/bin/mongosh")

mongo_cmd = "/usr/bin/mongo" if ls_code != 0 else "/usr/bin/mongosh"
return mongo_cmd


async def mongodb_uri(ops_test: OpsTest, unit_ids: List[int] = None) -> str:
if unit_ids is None:
unit_ids = UNIT_IDS
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/tls_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pytest_operator.plugin import OpsTest
from tenacity import RetryError, Retrying, stop_after_attempt, wait_exponential

from tests.integration.helpers import get_password
from tests.integration.helpers import get_mongo_cmd, get_password

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -62,8 +62,10 @@ async def run_tls_check(ops_test: OpsTest, unit: ops.model.Unit) -> int:
password = await get_password(ops_test, unit_id=0)
mongo_uri = f"mongodb://operator:{password}@{hosts}/admin?"

mongo_cmd = (
f"/usr/bin/mongosh {mongo_uri} --eval 'rs.status()'"
mongo_cmd = await get_mongo_cmd(ops_test, unit.name)

mongo_cmd += (
f" {mongo_uri} --eval 'rs.status()'"
f" --tls --tlsCAFile /etc/mongodb/external-ca.crt"
f" --tlsCertificateKeyFile /etc/mongodb/external-cert.pem"
)
Expand Down

0 comments on commit ea8940d

Please sign in to comment.