Skip to content

Commit

Permalink
[DPE-4946] S3 integrations cluster (#287)
Browse files Browse the repository at this point in the history
* update libs

* update tests for the new form of the monitor usr URI

* legacy provider is not needed for k8s charm

* sharding components succesful start with expected args

* format + lint

* add a basic integration test

* update integration tests to work on K8s

* PR feedback

* add in flags from vm charm to test

* pr feedback

* bring libs up to date

* make corresponding changes in src code

* test components go into blocked state if no relation is present

* k8s-afy copied over test code

* use updated lib versions

* WIP adding shards to cluster

* add shard works

* test add shard

* Add remove shard tests

* add in remaining basic shard tests

* Apply suggestions from Mehdi's code review

Co-authored-by: Mehdi Bendriss <bendrissmehdi@gmail.com>

* Update tests/integration/sharding_tests/helpers.py

Co-authored-by: Mehdi Bendriss <bendrissmehdi@gmail.com>

* not necessary to open ports on K8s

* fix ha tests with correct call to get password

* revert change as pymongo does not serialised collection

* password management sharding

* test operator password management

* add tests for password management

* tests for s3 integration validity in sharding

* update tests for k8s

---------

Co-authored-by: Mehdi Bendriss <bendrissmehdi@gmail.com>
  • Loading branch information
MiaAltieri and Mehdi-Bendriss authored Aug 2, 2024
1 parent 0cd2376 commit ce3c57a
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/integration/sharding_tests/test_sharding_relations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
import pytest
from pytest_operator.plugin import OpsTest

from ..helpers import METADATA, wait_for_mongodb_units_blocked

S3_APP_NAME = "s3-integrator"
SHARD_ONE_APP_NAME = "shard"
CONFIG_SERVER_ONE_APP_NAME = "config-server-one"
CONFIG_SERVER_TWO_APP_NAME = "config-server-two"
REPLICATION_APP_NAME = "replication"
APP_CHARM_NAME = "application"
LEGACY_APP_CHARM_NAME = "legacy-application"
MONGOS_APP_NAME = "mongos"
MONGOS_HOST_APP_NAME = "application-host"

SHARDING_COMPONENTS = [SHARD_ONE_APP_NAME, CONFIG_SERVER_ONE_APP_NAME]

CONFIG_SERVER_REL_NAME = "config-server"
SHARD_REL_NAME = "sharding"
DATABASE_REL_NAME = "first-database"
LEGACY_RELATION_NAME = "obsolete"


@pytest.mark.runner(["self-hosted", "linux", "X64", "jammy", "large"])
@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."""
database_charm = await ops_test.build_charm(".")
resources = {"mongodb-image": METADATA["resources"]["mongodb-image"]["upstream-source"]}

await ops_test.model.deploy(
database_charm,
config={"role": "config-server"},
resources=resources,
application_name=CONFIG_SERVER_ONE_APP_NAME,
)
await ops_test.model.deploy(
database_charm,
config={"role": "config-server"},
resources=resources,
application_name=CONFIG_SERVER_TWO_APP_NAME,
)
await ops_test.model.deploy(
database_charm,
resources=resources,
config={"role": "shard"},
application_name=SHARD_ONE_APP_NAME,
)

await ops_test.model.deploy(S3_APP_NAME, channel="edge")

await ops_test.model.wait_for_idle(
apps=[
CONFIG_SERVER_ONE_APP_NAME,
CONFIG_SERVER_TWO_APP_NAME,
SHARD_ONE_APP_NAME,
],
idle_period=20,
raise_on_blocked=False,
)


@pytest.mark.runner(["self-hosted", "linux", "X64", "jammy", "large"])
@pytest.mark.group(1)
@pytest.mark.abort_on_fail
async def test_shard_s3_relation(ops_test: OpsTest) -> None:
"""Verifies integrating a shard to s3-integrator fails."""
# attempt to add a replication deployment as a shard to the config server.
await ops_test.model.integrate(
f"{SHARD_ONE_APP_NAME}",
f"{S3_APP_NAME}",
)

await wait_for_mongodb_units_blocked(
ops_test,
SHARD_ONE_APP_NAME,
status="Relation to s3-integrator is not supported, config role must be config-server",
timeout=300,
)

# clean up relations
await ops_test.model.applications[SHARD_ONE_APP_NAME].remove_relation(
f"{S3_APP_NAME}:s3-credentials",
f"{SHARD_ONE_APP_NAME}:s3-credentials",
)

0 comments on commit ce3c57a

Please sign in to comment.