Skip to content

Commit a065c6c

Browse files
authored
Merge branch 'main' into feat/SMS-490-intra-app-comm-pattern
2 parents cf3d5b3 + 5f1c44d commit a065c6c

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

tests/integration/helpers.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,40 @@ def assert_request_returns_http_code(
134134
assert (
135135
returned_code == code
136136
), f"Expected {code} but got {returned_code} for {source_unit} -> {target_url} on {method}"
137+
138+
139+
@retry(
140+
wait=wait_exponential(multiplier=1, min=1, max=10), stop=stop_after_delay(120), reraise=True
141+
)
142+
def assert_tcp_connectivity(
143+
model: str, source_unit: str, host: str, port: int, inverse_check: bool = False
144+
):
145+
"""Test TCP connectivity from source unit to target host:port using /dev/tcp.
146+
147+
Args:
148+
model: Juju model name
149+
source_unit: Source unit name (e.g., "sender/0")
150+
host: Target hostname or IP
151+
port: Target port number
152+
inverse_check: Pass if the connection fails
153+
"""
154+
cmd = f'timeout 5 bash -c "echo >/dev/tcp/{host}/{port}"'
155+
156+
try:
157+
_ = sh.juju.ssh( # pyright: ignore
158+
"-m",
159+
model,
160+
source_unit,
161+
cmd,
162+
_return_cmd=True,
163+
)
164+
exit_code = 0
165+
logger.info(f"TCP connectivity test succeeded: {source_unit} -> {host}:{port}")
166+
except sh.ErrorReturnCode as e:
167+
exit_code = e.exit_code
168+
logger.info(f"TCP connectivity test failed with exit code {exit_code}: {source_unit} -> {host}:{port}")
169+
170+
if not inverse_check:
171+
assert exit_code == 0, f"Expected TCP connection to {host}:{port} to succeed, but got exit code {exit_code}"
172+
else:
173+
assert exit_code != 0, f"Expected TCP connection to {host}:{port} to fail, but it succeeded"

tests/integration/test_charm.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
APP_NAME,
1313
RESOURCES,
1414
assert_request_returns_http_code,
15+
assert_tcp_connectivity,
1516
istio_k8s,
1617
validate_labels,
1718
validate_policy_exists,
@@ -328,8 +329,8 @@ async def test_modeloperator_rule(ops_test: OpsTest, service_mesh_tester):
328329
service_mesh_tester, application_name="sender", resources=resources, trust=True
329330
)
330331
await omm.model.wait_for_idle(status="active")
331-
# Return code is 400 because I do not know how to properly format an api call to the modeloperator. But we only
332-
# care that the request reached its destination.
333-
assert_request_returns_http_code(
334-
omm.model.name, "sender/0", f"http://modeloperator.{ops_test.model.name}:17071", code=400
332+
# Test TCP connectivity to modeloperator - we only care that the network connection can be established,
333+
# proving that the service mesh allows traffic from off-mesh workloads to the modeloperator
334+
assert_tcp_connectivity(
335+
omm.model.name, "sender/0", f"modeloperator.{ops_test.model.name}.svc.cluster.local", 17071
335336
)

0 commit comments

Comments
 (0)