Skip to content

Commit

Permalink
use exisiting function
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Aug 30, 2024
1 parent b275352 commit 79e0707
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
15 changes: 1 addition & 14 deletions tests/integration/client_relations/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MongoClient,
get_application_relation_data,
get_secret_data,
get_mongos_user_password,
)

from pytest_operator.plugin import OpsTest
Expand All @@ -41,20 +42,6 @@
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())


@retry(stop=stop_after_attempt(10), wait=wait_fixed(15), reraise=True)
async def get_mongos_user_password(
ops_test: OpsTest, app_name=MONGOS_APP_NAME, relation_name="cluster"
) -> Tuple[str, str]:
secret_uri = await get_application_relation_data(
ops_test, app_name, relation_name=relation_name, key="secret-user"
)
assert secret_uri, "No secret URI found"

secret_data = await get_secret_data(ops_test, secret_uri)

return secret_data.get("username"), secret_data.get("password")


@retry(stop=stop_after_attempt(10), wait=wait_fixed(15), reraise=True)
async def get_client_connection_string(
ops_test: OpsTest, app_name=MONGOS_APP_NAME, relation_name="cluster"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
from pytest_operator.plugin import OpsTest
from typing import Tuple

from ..helpers import (
build_cluster,
Expand All @@ -14,11 +15,12 @@
check_mongos,
get_direct_mongos_client,
MONGOS_PORT,
get_secret_data,
get_application_relation_data,
)
from .helpers import (
is_relation_joined,
get_client_connection_string,
get_mongos_user_password,
)

CLIENT_RELATION_NAME = "mongos"
Expand Down Expand Up @@ -55,7 +57,6 @@ async def test_integrate_with_internal_client(ops_test: OpsTest) -> None:
await ops_test.model.wait_for_idle(
apps=[APPLICATION_APP_NAME, MONGOS_APP_NAME], status="active", idle_period=20
)

await ops_test.model.block_until(
lambda: is_relation_joined(
ops_test,
Expand Down Expand Up @@ -145,3 +146,15 @@ async def test_removed_relation_no_longer_has_access(ops_test: OpsTest):
assert (
not mongos_can_connect_with_auth
), "Client can still connect after relation broken."


# TODO, use get_mongos_user_password in base helpers once DPE:5215 is fixed retrieve via secret
async def get_mongos_user_password(
ops_test: OpsTest, app_name=MONGOS_APP_NAME, relation_name="cluster"
) -> Tuple[str, str]:
secret_uri = await get_application_relation_data(
ops_test, app_name, relation_name=relation_name, key="secret-user"
)

secret_data = await get_secret_data(ops_test, secret_uri)
return secret_data.get("username"), secret_data.get("password")

0 comments on commit 79e0707

Please sign in to comment.