Skip to content

Commit

Permalink
sanity: Uses k8s-test-harness utils (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiubelu authored Jul 19, 2024
1 parent f73a54f commit b2b5b77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ coverage[toml]==7.2.5
pytest==7.3.1
PyYAML==6.0.1
tenacity==8.2.3
git+https://github.com/claudiubelu/k8s-test-harness.git@main
git+https://github.com/canonical/k8s-test-harness.git@main
31 changes: 17 additions & 14 deletions tests/sanity/test_whereabouts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#
# Copyright 2024 Canonical, Ltd.
#
import os

import pytest
from k8s_test_harness.util import docker_util
from k8s_test_harness.util import docker_util, env_util

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


def _test_whereabouts_rock(image_variable, expected_files):
def _test_whereabouts_rock(image_version, expected_files):
"""Test Whereabouts rock."""
image = os.getenv(image_variable)
assert image is not None, f"${image_variable} is not set"
rock = env_util.get_build_meta_info_for_rock_version(
"whereabouts", image_version, "amd64"
)
image = rock.image

# check rock filesystem
docker_util.ensure_image_contains_paths(image, expected_files)

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

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

# check script. It expects serviceaccount token to exist.
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
process = docker_util.run_in_docker(image, ["/install-cni.sh"], False)
assert (
"cat: /var/run/secrets/kubernetes.io/serviceaccount/token: No such file or directory"
in process.stderr
)

# whereabouts:0.5.4 also has a /ip-reconciler
if version == "0.5.4":
process = docker_util.run_in_docker(image, False, "/ip-reconciler")
process = docker_util.run_in_docker(image, ["/ip-reconciler"], False)
expected_message = "failed to instantiate the Kubernetes client"
assert expected_message in process.stderr


def test_whereabouts_rock_0_6_3():
_test_whereabouts_rock("ROCK_WHEREABOUTS_0_6_3", ROCK_EXPECTED_FILES)
_test_whereabouts_rock("0.6.3", ROCK_EXPECTED_FILES)


def test_whereabouts_rock_0_6_1():
_test_whereabouts_rock("ROCK_WHEREABOUTS_0_6_1", ROCK_EXPECTED_FILES)
_test_whereabouts_rock("0.6.1", ROCK_EXPECTED_FILES)


def test_whereabouts_rock_0_5_4():
_test_whereabouts_rock("ROCK_WHEREABOUTS_0_5_4", ROCK_EXPECTED_FILES + ["/ip-reconciler"])
_test_whereabouts_rock("0.5.4", ROCK_EXPECTED_FILES + ["/ip-reconciler"])
1 change: 1 addition & 0 deletions tests/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ commands =
pass_env =
TEST_*
ROCK_*
BUILT_ROCKS_METADATA

[testenv: integration]
allowlist_externals =
Expand Down

0 comments on commit b2b5b77

Please sign in to comment.