Skip to content

Commit

Permalink
pedros suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Feb 9, 2024
1 parent ed6415e commit 7b5e9c2
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 6 deletions.
2 changes: 0 additions & 2 deletions tests/integration/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/integration/backup_tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pytest_operator.plugin import OpsTest
from tenacity import RetryError, Retrying, stop_after_delay, wait_fixed

from tests.integration.helpers import get_app_name
from ..helpers import get_app_name

from ..ha_tests import helpers as ha_helpers
from . import helpers
Expand Down
112 changes: 112 additions & 0 deletions tests/integration/sharding_tests/test_sharding_backups.py
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,
)
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ all_path = {[vars]src_path} {[vars]tests_path} {[vars]mongodb_lib_path}

[testenv]
set_env =
PYTHONPATH = {tox_root}/lib:{[vars]src_path}
PYTHONBREAKPOINT=ipdb.set_trace
PYTHONPATH = {[vars]src_path}:{tox_root}/lib
PY_COLORS=1
PYTHONDONTWRITEBYTECODE=1
pass_env =
PYTHONPATH
CHARM_BUILD_DIR
Expand Down

0 comments on commit 7b5e9c2

Please sign in to comment.