Skip to content

Commit

Permalink
sanity: Uses k8s-test-harness utils
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiubelu committed Jul 19, 2024
1 parent d2cbe77 commit 9b9cd8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
1 change: 1 addition & 0 deletions tests/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage[toml]==7.2.5
pytest==7.3.1
PyYAML==6.0.1
tenacity==8.2.3
git+https://github.com/canonical/k8s-test-harness.git@main
28 changes: 5 additions & 23 deletions tests/sanity/test_whereabouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright 2024 Canonical, Ltd.
#
import os
import subprocess

import pytest
from k8s_test_harness.util import docker_util

ROCK_EXPECTED_FILES = [
"/host",
Expand All @@ -14,42 +14,24 @@
]


def _run_in_docker(image, check_exit_code, *command):
return subprocess.run(
[
"docker",
"run",
"--rm",
"-i",
"--entrypoint",
command[0],
image,
*command[1:],
],
check=check_exit_code,
capture_output=True,
text=True,
)


@pytest.mark.abort_on_fail
def test_whereabouts_rock():
"""Test Whereabouts rock."""
image_variable = "ROCK_WHEREABOUTS"
image = os.getenv(image_variable)
assert image is not None, f"${image_variable} is not set"
# check rock filesystem
_run_in_docker(image, True, "ls", "-la", *ROCK_EXPECTED_FILES)
docker_util.ensure_image_contains_paths(image, ROCK_EXPECTED_FILES)

# check binary name and version.
process = _run_in_docker(image, True, "/whereabouts", "version")
process = docker_util.run_in_docker(image, True, "/whereabouts", "version")
output = process.stderr
assert "whereabouts" in output and "0.6.3" in output

# check other binary. It expects KUBERNETES_SERVICE_HOST to be defined.
process = _run_in_docker(image, False, "/ip-control-loop")
process = docker_util.run_in_docker(image, False, "/ip-control-loop")
assert "KUBERNETES_SERVICE_HOST" in process.stderr

# check script. It expects serviceaccount token to exist.
process = _run_in_docker(image, False, "/install-cni.sh")
process = docker_util.run_in_docker(image, False, "/install-cni.sh")
"cat: /var/run/secrets/kubernetes.io/serviceaccount/token: No such file or directory" in process.stderr

0 comments on commit 9b9cd8b

Please sign in to comment.