-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed6415e
commit 7b5e9c2
Showing
4 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
tests/integration/sharding_tests/test_sharding_backups.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import secrets | ||
import string | ||
|
||
import pytest | ||
from pytest_operator.plugin import OpsTest | ||
from tenacity import RetryError, Retrying, stop_after_delay, wait_fixed | ||
|
||
from ..backup_tests import helpers as backup_helpers | ||
|
||
S3_APP_NAME = "s3-integrator" | ||
SHARD_ONE_APP_NAME = "shard-one" | ||
SHARD_TWO_APP_NAME = "shard-two" | ||
SHARD_APPS = [SHARD_ONE_APP_NAME, SHARD_TWO_APP_NAME] | ||
CONFIG_SERVER_APP_NAME = "config-server-one" | ||
SHARD_REL_NAME = "sharding" | ||
CONFIG_SERVER_REL_NAME = "config-server" | ||
S3_REL_NAME = "s3-credentials" | ||
TIMEOUT = 10 * 60 | ||
|
||
|
||
@pytest.mark.group(1) | ||
@pytest.mark.abort_on_fail | ||
async def test_build_and_deploy(ops_test: OpsTest) -> None: | ||
"""Build and deploy a sharded cluster.""" | ||
my_charm = await ops_test.build_charm(".") | ||
await ops_test.model.deploy( | ||
my_charm, | ||
num_units=2, | ||
config={"role": "config-server"}, | ||
application_name=CONFIG_SERVER_APP_NAME, | ||
) | ||
await ops_test.model.deploy( | ||
my_charm, num_units=2, config={"role": "shard"}, application_name=SHARD_ONE_APP_NAME | ||
) | ||
await ops_test.model.deploy( | ||
my_charm, num_units=1, config={"role": "shard"}, application_name=SHARD_TWO_APP_NAME | ||
) | ||
|
||
# deploy the s3 integrator charm | ||
await ops_test.model.deploy(S3_APP_NAME, channel="edge") | ||
|
||
await ops_test.model.wait_for_idle( | ||
apps=[S3_APP_NAME, CONFIG_SERVER_APP_NAME, SHARD_ONE_APP_NAME, SHARD_TWO_APP_NAME], | ||
idle_period=20, | ||
raise_on_blocked=False, | ||
timeout=TIMEOUT, | ||
raise_on_error=False, | ||
) | ||
|
||
|
||
@pytest.mark.group(1) | ||
async def test_set_credentials_in_cluster(ops_test: OpsTest) -> None: | ||
"""Tests that sharded cluster can be configured for s3 configurations.""" | ||
await backup_helpers.set_credentials(ops_test, cloud="AWS") | ||
choices = string.ascii_letters + string.digits | ||
unique_path = "".join([secrets.choice(choices) for _ in range(4)]) | ||
configuration_parameters = { | ||
"bucket": "data-charms-testing", | ||
"path": f"mongodb-vm/test-{unique_path}", | ||
"endpoint": "https://s3.amazonaws.com", | ||
"region": "us-east-1", | ||
} | ||
|
||
# apply new configuration options | ||
await ops_test.model.applications[S3_APP_NAME].set_config(configuration_parameters) | ||
await ops_test.model.wait_for_idle(apps=[S3_APP_NAME], status="active", timeout=TIMEOUT) | ||
|
||
# provide config-server to entire cluster and s3-integrator to config-server - integrations | ||
# made in succession to test race conditions. | ||
await ops_test.model.integrate( | ||
f"{S3_APP_NAME}:{S3_REL_NAME}", | ||
f"{CONFIG_SERVER_APP_NAME}:{S3_REL_NAME}", | ||
) | ||
await ops_test.model.integrate( | ||
f"{SHARD_ONE_APP_NAME}:{SHARD_REL_NAME}", | ||
f"{CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}", | ||
) | ||
await ops_test.model.integrate( | ||
f"{SHARD_TWO_APP_NAME}:{SHARD_REL_NAME}", | ||
f"{CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}", | ||
) | ||
|
||
await ops_test.model.wait_for_idle( | ||
apps=[ | ||
CONFIG_SERVER_APP_NAME, | ||
SHARD_ONE_APP_NAME, | ||
SHARD_TWO_APP_NAME, | ||
], | ||
idle_period=20, | ||
status="active", | ||
timeout=TIMEOUT, | ||
) | ||
|
||
|
||
@pytest.mark.group(1) | ||
async def test_shard_cannot_integrate_s3(ops_test: OpsTest) -> None: | ||
await ops_test.model.integrate( | ||
f"{SHARD_ONE_APP_NAME}:{S3_REL_NAME}", | ||
f"{S3_APP_NAME}:{S3_REL_NAME}", | ||
) | ||
await ops_test.model.wait_for_idle( | ||
apps=[ | ||
SHARD_ONE_APP_NAME, | ||
], | ||
idle_period=20, | ||
status="blocked", | ||
timeout=TIMEOUT, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters