From 584269a3bba973229a5f85548125a09950d1d0c4 Mon Sep 17 00:00:00 2001 From: Ronen Hilewicz Date: Mon, 25 Nov 2024 13:51:46 -0500 Subject: [PATCH] Move end-to-end tests into chart/directory/tests dir --- .github/workflows/ci.yaml | 8 +++-- charts/directory/.helmignore | 1 + .../directory/test}/no-tls.values.yaml | 0 .../directory/test}/tests.yaml | 0 .../directory/test}/tls.values.yaml | 0 tools/ktest/ktest.py | 33 +++---------------- tools/ktest/namespace.py | 27 ++++++++++----- 7 files changed, 31 insertions(+), 38 deletions(-) rename {test/directory => charts/directory/test}/no-tls.values.yaml (100%) rename {test/directory => charts/directory/test}/tests.yaml (100%) rename {test/directory => charts/directory/test}/tls.values.yaml (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c97d46f..1e68aa7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -61,11 +61,15 @@ jobs: chmod +x ./bin/topaz ./bin/topaz version echo "TOPAZ=$(realpath ./bin/topaz)" >> "$GITHUB_ENV" + echo "TOPAZ_CERTS_DIR=$(./bin/topaz config info | jq '.config.topaz_certs_dir' -r)" >> "$GITHUB_ENV" - name: Install topazd container run: | ${TOPAZ} install --container-tag=${{ env.TOPAZ_VERSION }} ${TOPAZ} version + - + name: Generate topaz certs + run: ${TOPAZ} certs generate - name: Install uv package manager uses: astral-sh/setup-uv@v3 @@ -112,6 +116,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SSH_PUBLIC_KEY: ${{ steps.sshkey.outputs.public_key }} SSH_PRIVATE_KEY: ${{ steps.sshkey.outputs.private_key }} + TOPAZ_CERTS_DIR: ${{ env.TOPAZ_CERTS_DIR }} run: | - cd tools/ktest - uv run ktest.py ../../test/directory/tests.yaml + uv run --project tools/ktest tools/ktest/ktest.py charts/directory/test/tests.yaml diff --git a/charts/directory/.helmignore b/charts/directory/.helmignore index c1c4640..9038f21 100644 --- a/charts/directory/.helmignore +++ b/charts/directory/.helmignore @@ -24,3 +24,4 @@ build/ ci/ +test/ diff --git a/test/directory/no-tls.values.yaml b/charts/directory/test/no-tls.values.yaml similarity index 100% rename from test/directory/no-tls.values.yaml rename to charts/directory/test/no-tls.values.yaml diff --git a/test/directory/tests.yaml b/charts/directory/test/tests.yaml similarity index 100% rename from test/directory/tests.yaml rename to charts/directory/test/tests.yaml diff --git a/test/directory/tls.values.yaml b/charts/directory/test/tls.values.yaml similarity index 100% rename from test/directory/tls.values.yaml rename to charts/directory/test/tls.values.yaml diff --git a/tools/ktest/ktest.py b/tools/ktest/ktest.py index 2109d31..0d8631c 100755 --- a/tools/ktest/ktest.py +++ b/tools/ktest/ktest.py @@ -16,7 +16,7 @@ from model import Deployment, Spec, Test from namespace import Namespace -logger = logging.getLogger("k3stest") +logger = logging.getLogger(__name__) COLOR_HARNESS = "blue" COLOR_STEP = "magenta" @@ -120,8 +120,8 @@ def execute_cleanup(self): echo("🧹", step, cl=COLOR_STEP) try: self.subprocess(step) - except: - pass + except Exception as e: + logger.error("cleanup failed: %s", e) def set_image_pull_secret(self, ns: Namespace): if self.test.pull_secret: @@ -186,33 +186,10 @@ def git_root(from_path: str) -> str: def init_logging(level=logging.INFO): - loggers = ( - logging.getLogger(name) - for name in logging.root.manager.loggerDict - if name.startswith("k3test") - ) - for logger in loggers: - init_logger(logger, level) - - -def init_logger(logger: logging.Logger, level=logging.INFO): - logger.setLevel(level) - - # create console handler and set level to debug - ch = logging.StreamHandler() - ch.setLevel(logging.DEBUG) - - # create formatter - formatter = logging.Formatter( - "%(asctime)s - %(levelname)s - %(name)s - %(message)s" + logging.basicConfig( + format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", level=level ) - # add formatter to ch - ch.setFormatter(formatter) - - # add ch to logger - logger.addHandler(ch) - if __name__ == "__main__": main() diff --git a/tools/ktest/namespace.py b/tools/ktest/namespace.py index 11f227a..3f90186 100644 --- a/tools/ktest/namespace.py +++ b/tools/ktest/namespace.py @@ -13,7 +13,7 @@ from model import ConfigMap, Secret -logger = logging.getLogger("k3test.namespace") +logger = logging.getLogger(__name__) class Namespace: @@ -96,13 +96,24 @@ def forward(self, svc: str, ports: Mapping[int, int]): yield proc finally: logger.debug("terminating port-forward: %s", svc) - proc.terminate() - try: - proc.wait(1) - except subprocess.TimeoutExpired: - logger.info("timeout expired. killing port-forward: %s", svc) - proc.kill() - logger.debug("port-forward terminated: %s", svc) + for stop in (proc.terminate, proc.kill): + logger.debug("attempting to '%s' port-forward: %s", stop.__name__, svc) + stop() + try: + proc.communicate(timeout=3) + logger.debug("port-forward exited: %s", svc) + # wait for the port to become available again + time.sleep(3) + break + except subprocess.TimeoutExpired: + logger.info("timeout expired waiting for: %s", svc) + + if proc.returncode is None: + logger.debug("unable to stop port-forwarding: %s", svc) + else: + logger.debug( + "port-forward terminated: %s. exit code: %d", svc, proc.returncode + ) @lru_cache(maxsize=32) def svc_pod(self, svc: str) -> str: