From 2b5fd2d94b3664ece70709930660b98b513f52e6 Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Mon, 30 Dec 2024 20:39:44 +0000 Subject: [PATCH] test: test Signed-off-by: Tiago Castro --- .github/workflows/bdd.yml | 20 +++++++++++++++----- tests/bdd/common/deployer.py | 3 +++ tests/bdd/common/docker.py | 22 +++++++++++++++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bdd.yml b/.github/workflows/bdd.yml index c19923a87..5e4398165 100644 --- a/.github/workflows/bdd.yml +++ b/.github/workflows/bdd.yml @@ -1,6 +1,9 @@ name: BDD CI on: workflow_call: + push: + branches: + - ci env: CARGO_TERM_COLOR: always @@ -33,7 +36,14 @@ jobs: - name: Run BDD Tests run: | nix-shell --run "deployer start --image-pull-policy always -w 60s && deployer stop" - nix-shell --run "./scripts/python/test.sh" + while [ $? -eq 0 ]; do + nix-shell --run "./scripts/python/test.sh" + done + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: bdd-failure + path: logs.txt - name: Cleanup if: always() run: nix-shell --run "./scripts/python/test-residue-cleanup.sh" @@ -47,7 +57,7 @@ jobs: fail-on-empty: true title: Test results # debugging - # - name: Setup tmate session - # if: ${{ failure() }} - # timeout-minutes: 120 - # uses: mxschmitt/action-tmate@v3 + - name: Setup tmate session + if: ${{ failure() }} + timeout-minutes: 1024 + uses: mxschmitt/action-tmate@v3 diff --git a/tests/bdd/common/deployer.py b/tests/bdd/common/deployer.py index e6a597128..0490c6b2e 100644 --- a/tests/bdd/common/deployer.py +++ b/tests/bdd/common/deployer.py @@ -1,5 +1,6 @@ import os import subprocess +import sys from datetime import datetime import pytest @@ -193,6 +194,8 @@ def start_with_opts(options: StartOptions): @staticmethod def stop(disconnect_nvme=False): print(f"DeployerStop: {datetime.now()}") + if hasattr(sys, "last_traceback"): + Docker.log_containers() clean = os.getenv("CLEAN") if clean is not None and clean.lower() in ("no", "false", "f", "0"): return diff --git a/tests/bdd/common/docker.py b/tests/bdd/common/docker.py index beb566252..09f1d1b45 100644 --- a/tests/bdd/common/docker.py +++ b/tests/bdd/common/docker.py @@ -1,5 +1,5 @@ import docker - +import os class Docker(object): # Determines if a container with the given name is running. @@ -78,3 +78,23 @@ def restart_container(name): docker_client = docker.from_env() container = docker_client.containers.get(name) container.restart() + + @staticmethod + def log_containers(): + docker_client = docker.from_env() + logs = os.environ["ROOT_DIR"] + "/logs.txt" + with open(logs, 'w') as log_file: + # Iterate over all running containers + for container in docker_client.containers.list(): + # Write the container's name or ID + log_file.write(f'Logs for container {container.name}:\n') + print(f'Logs for container {container.name}:\n') + log_file.write('-' * 40 + '\n') + print('-' * 40 + '\n') + # Get the container logs + logs = container.logs().decode('utf-8') + # Write the logs to the file + log_file.write(logs) + print(logs) + log_file.write('\n\n') + print('\n\n')