From 7fba666a26b302af76063736a9ebbe96b0020133 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Thu, 18 Jul 2024 17:37:35 +0000 Subject: [PATCH] sanity: Uses k8s-test-harness utils --- tests/requirements-test.txt | 2 +- tests/sanity/test_whereabouts.py | 31 +++++++++++++++++-------------- tests/tox.ini | 1 + 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/requirements-test.txt b/tests/requirements-test.txt index 4892f82..ff57d6b 100644 --- a/tests/requirements-test.txt +++ b/tests/requirements-test.txt @@ -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 diff --git a/tests/sanity/test_whereabouts.py b/tests/sanity/test_whereabouts.py index 4c88542..5f34775 100644 --- a/tests/sanity/test_whereabouts.py +++ b/tests/sanity/test_whereabouts.py @@ -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", @@ -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"]) diff --git a/tests/tox.ini b/tests/tox.ini index 555e9c8..8bbb851 100644 --- a/tests/tox.ini +++ b/tests/tox.ini @@ -46,6 +46,7 @@ commands = pass_env = TEST_* ROCK_* + BUILT_ROCKS_METADATA [testenv: integration] allowlist_externals =