Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 39 additions & 32 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@
"access-key": "minio",
"secret-key": "minio-secret-key",
}
MINIO_CLIENT_IMAGE = "quay.io/minio/mc"


async def run_probe_pod(ops_test: OpsTest, pod_name: str, image: str, command: tuple):
"""Run a one-off probe Pod via kubectl, always deleting it afterwards."""
kubectl_cmd = (
"kubectl",
"run",
"-i",
"--restart=Never",
"--command",
f"--namespace={ops_test.model_name}",
pod_name,
f"--image={image}",
"--",
*command,
)
try:
return await ops_test.run(*kubectl_cmd)
finally:
await ops_test.run(
"kubectl",
"delete",
"pod",
pod_name,
f"--namespace={ops_test.model_name}",
"--ignore-not-found",
"--now",
)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -127,24 +156,13 @@ async def connect_client_to_server(
f"&& mc rb {alias}/{bucket}"
)

kubectl_cmd = (
"kubectl",
"run",
"--rm",
"-i",
"--restart=Never",
"--command",
f"--namespace={ops_test.model_name}",
"minio-deployment-test",
"--image=minio/mc",
"--",
"sh",
"-c",
minio_cmd,
ret_code, stdout, stderr = await run_probe_pod(
ops_test,
pod_name="minio-client-test",
image=MINIO_CLIENT_IMAGE,
command=("sh", "-c", minio_cmd),
)

ret_code, stdout, stderr = await ops_test.run(*kubectl_cmd)

if ret_code != 0:
raise ConnectionError(
f"Connection to Minio returned code {ret_code} with stdout:\n{stdout}\n"
Expand Down Expand Up @@ -192,24 +210,13 @@ async def test_connect_to_console(ops_test: OpsTest):

url = f"http://{service_name}.{model_name}.svc.cluster.local:{port}"

kubectl_cmd = (
"kubectl",
"run",
"--rm",
"-i",
"--restart=Never",
"--command",
f"--namespace={ops_test.model_name}",
"minio-deployment-test",
"--image=curlimages/curl",
"--",
"curl",
"-I",
url,
ret_code, stdout, stderr = await run_probe_pod(
ops_test,
pod_name="minio-console-test",
image="curlimages/curl",
command=("curl", "-I", url),
)

ret_code, stdout, stderr = await ops_test.run(*kubectl_cmd)

assert (
ret_code == 0
), f"Test returned code {ret_code} with stdout:\n{stdout}\nstderr:\n{stderr}"
Expand Down
71 changes: 39 additions & 32 deletions tests/integration/test_charm_ambient.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@
"access-key": "minio",
"secret-key": "minio-secret-key",
}
MINIO_CLIENT_IMAGE = "quay.io/minio/mc"


async def run_probe_pod(ops_test: OpsTest, pod_name: str, image: str, command: tuple):
"""Run a one-off probe Pod via kubectl, always deleting it afterwards."""
kubectl_cmd = (
"kubectl",
"run",
"-i",
"--restart=Never",
"--command",
f"--namespace={ops_test.model_name}",
pod_name,
f"--image={image}",
"--",
*command,
)
try:
return await ops_test.run(*kubectl_cmd)
finally:
await ops_test.run(
"kubectl",
"delete",
"pod",
pod_name,
f"--namespace={ops_test.model_name}",
"--ignore-not-found",
"--now",
)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -135,24 +164,13 @@ async def connect_client_to_server(
f"&& mc rb {alias}/{bucket}"
)

kubectl_cmd = (
"kubectl",
"run",
"--rm",
"-i",
"--restart=Never",
"--command",
f"--namespace={ops_test.model_name}",
"minio-deployment-test",
"--image=minio/mc",
"--",
"sh",
"-c",
minio_cmd,
ret_code, stdout, stderr = await run_probe_pod(
ops_test,
pod_name="minio-client-test",
image=MINIO_CLIENT_IMAGE,
command=("sh", "-c", minio_cmd),
)

ret_code, stdout, stderr = await ops_test.run(*kubectl_cmd)

if ret_code != 0:
raise ConnectionError(
f"Connection to Minio returned code {ret_code} with stdout:\n{stdout}\n"
Expand Down Expand Up @@ -200,24 +218,13 @@ async def test_connect_to_console(ops_test: OpsTest):

url = f"http://{service_name}.{model_name}.svc.cluster.local:{port}"

kubectl_cmd = (
"kubectl",
"run",
"--rm",
"-i",
"--restart=Never",
"--command",
f"--namespace={ops_test.model_name}",
"minio-deployment-test",
"--image=curlimages/curl",
"--",
"curl",
"-I",
url,
ret_code, stdout, stderr = await run_probe_pod(
ops_test,
pod_name="minio-console-test",
image="curlimages/curl",
command=("curl", "-I", url),
)

ret_code, stdout, stderr = await ops_test.run(*kubectl_cmd)

assert (
ret_code == 0
), f"Test returned code {ret_code} with stdout:\n{stdout}\nstderr:\n{stderr}"
Expand Down
Loading