Skip to content

Commit

Permalink
personal nits
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Sep 12, 2024
1 parent 86b7310 commit f3a0228
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions tests/integration/tls/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from pytest_operator.plugin import OpsTest
from ..helpers import get_application_relation_data
from tenacity import RetryError
from tenacity import RetryError, Retrying, stop_after_attempt, wait_exponential
from datetime import datetime
from typing import Optional, Dict
import json
Expand Down Expand Up @@ -120,20 +120,26 @@ async def mongos_tls_command(ops_test: OpsTest, unit, internal=True) -> str:
async def check_tls(ops_test, unit, enabled, internal=True) -> None:
"""Returns True if TLS matches the expected state "enabled"."""
try:
mongos_tls_check = await mongos_tls_command(
ops_test, unit=unit, internal=internal
)
print(mongos_tls_check)
complete_command = f"ssh --container mongos {unit.name} {mongos_tls_check}"
return_code, _, stderr = await ops_test.juju(*complete_command.split())

tls_enabled = return_code == 0
if enabled != tls_enabled:
logger.error(stderr)
raise ValueError(
f"TLS is{' not' if not tls_enabled else ''} enabled on {unit.name}"
)
return True
for attempt in Retrying(
stop=stop_after_attempt(10),
wait=wait_exponential(multiplier=1, min=2, max=30),
):
with attempt:
mongos_tls_check = await mongos_tls_command(
ops_test, unit=unit, internal=internal
)
complete_command = (
f"ssh --container mongos {unit.name} {mongos_tls_check}"
)
return_code, _, stderr = await ops_test.juju(*complete_command.split())

tls_enabled = return_code == 0
if enabled != tls_enabled:
logger.error(stderr)
raise ValueError(
f"TLS is{' not' if not tls_enabled else ''} enabled on {unit.name}"
)
return True
except RetryError:
return False

Expand Down

0 comments on commit f3a0228

Please sign in to comment.