Skip to content

Commit

Permalink
update test charm
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Feb 19, 2024
1 parent 5a752ee commit 0da5da1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tests/integration/application/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, *args):
# relation events for mongos client
self.database = DatabaseRequires(
self,
relation_name="mongos_proxy",
relation_name="mongos",
database_name="my-test-db",
extra_user_roles=EXTRA_USER_ROLES,
)
Expand Down
18 changes: 5 additions & 13 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ async def check_mongos(
ops_test: OpsTest,
unit: ops.model.Unit,
auth: bool,
app_name: Optional[str],
app_name: Optional[str] = None,
uri: str = None,
external: bool = False,
) -> bool:
"""Returns whether mongos is running on the provided unit."""
mongos_check = await generate_mongos_command(
ops_test, auth, app_name, uri, external
)
mongos_check = await generate_mongos_command(ops_test, auth, app_name, uri, external)

# since mongos is communicating only via the unix domain socket, we cannot connect to it via
# traditional pymongo methods
Expand Down Expand Up @@ -69,16 +67,12 @@ async def generate_mongos_uri(
) -> str:
"""Generates a URI for accessing mongos."""
host = (
MONGOS_SOCKET
if not external
else await get_ip_address(ops_test, app_name=MONGOS_APP_NAME)
MONGOS_SOCKET if not external else await get_ip_address(ops_test, app_name=MONGOS_APP_NAME)
)
if not auth:
return f"mongodb://{host}:27018"

secret_uri = await get_application_relation_data(
ops_test, app_name, "mongos", "secret-user"
)
secret_uri = await get_application_relation_data(ops_test, app_name, "mongos", "secret-user")

secret_data = await get_secret_data(ops_test, secret_uri)
return secret_data.get("uris")
Expand Down Expand Up @@ -125,9 +119,7 @@ async def get_application_relation_data(
data = yaml.safe_load(raw_data)

# Filter the data based on the relation name.
relation_data = [
v for v in data[unit.name]["relation-info"] if v["endpoint"] == relation_name
]
relation_data = [v for v in data[unit.name]["relation-info"] if v["endpoint"] == relation_name]
if relation_id:
# Filter the data based on the relation id.
relation_data = [v for v in relation_data if v["relation-id"] == relation_id]
Expand Down

0 comments on commit 0da5da1

Please sign in to comment.