From 27cf6858413b20d196f64d855684cadd09f229ea Mon Sep 17 00:00:00 2001 From: Paul Hildebrandt Date: Wed, 27 Nov 2024 13:05:29 +0100 Subject: [PATCH 1/7] safety Signed-off-by: Paul Hildebrandt --- tests/conftest.py | 60 +++++++++++++++++++++++++++++++++++++ tests/helper.py | 27 +++++++++++++++++ tests/test_push_manifest.py | 59 ++++++++++++++++++++++++++++++++++++ zot/config.json | 13 ++++++++ 4 files changed, 159 insertions(+) create mode 100644 tests/conftest.py create mode 100644 tests/helper.py create mode 100644 tests/test_push_manifest.py create mode 100644 zot/config.json diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..ec30740 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,60 @@ +from helper import call_command, spawn_background_process +import os +import tempfile +import sys +import shutil +import json +import pytest +from dotenv import load_dotenv + + +def write_zot_config(config_dict, file_path): + with open(file_path, "w") as config_file: + json.dump(config_dict, config_file, indent=4) + + +@pytest.fixture(autouse=False, scope="function") +def zot_session(): + load_dotenv() + print("start zot session") + zot_config = { + "distSpecVersion": "1.1.0", + "storage": {"rootDirectory": "output/registry/zot"}, + "http": {"address": "127.0.0.1", "port": "18081"}, + "log": {"level": "warn"}, + } + + with tempfile.NamedTemporaryFile(delete=False, suffix=".json") as temp_config_file: + write_zot_config(zot_config, temp_config_file.name) + zot_config_file_path = temp_config_file.name + + print(f"Spawning zot registry with config {zot_config_file_path}") + zot_process = spawn_background_process( + f"zot serve {zot_config_file_path}", + stdout=sys.stdout, + stderr=sys.stderr, + ) + + yield zot_process + print("clean up zot session") + + zot_process.terminate() + + if os.path.isdir("./output"): + shutil.rmtree("./output") + if os.path.isfile(zot_config_file_path): + os.remove(zot_config_file_path) + + +def pytest_sessionstart(session): + #call_command("./cert/gencert.sh") + print("pytest session started") + #call_command("./test-data/build-test-data.sh --dummy") + + +def pytest_sessionfinish(session): + print("pytest session finished") + #if os.path.isfile("./cert/oci-sign.crt"): + # os.remove("./cert/oci-sign.crt") + #if os.path.isfile("./cert/oci-sign.key"): + # os.remove("./cert/oci-sign.key") \ No newline at end of file diff --git a/tests/helper.py b/tests/helper.py new file mode 100644 index 0000000..8c0d864 --- /dev/null +++ b/tests/helper.py @@ -0,0 +1,27 @@ +import subprocess +import shlex + +import os + +ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) +ZOT_CONFIG_FILE = f"/zot/config.json" + + +def spawn_background_process(cmd, stdout=None, stderr=None): + args = shlex.split(cmd) + process = subprocess.Popen(args, shell=False, stdout=stdout, stderr=stderr) + return process + + +def call_command(cmd): + try: + args = shlex.split(cmd) + result = subprocess.run( + args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + output = result.stdout.decode("utf-8") + return output + + except subprocess.CalledProcessError as e: + error_message = e.stderr.decode("utf-8") + return f"An error occurred: {error_message}" \ No newline at end of file diff --git a/tests/test_push_manifest.py b/tests/test_push_manifest.py new file mode 100644 index 0000000..d54a916 --- /dev/null +++ b/tests/test_push_manifest.py @@ -0,0 +1,59 @@ +import pytest +from click.testing import CliRunner +import sys +sys.path.append("src") +from glcli import cli + +CONTAINER_NAME_ZOT_EXAMPLE = "127.0.0.1:18081/gardenlinux-example" +#GARDENLINUX_ROOT_DIR_EXAMPLE = "test-data/build-metal-gardener_prod" +TEST_DATA_DIR = "" + +@pytest.mark.usefixtures("zot_session") +@pytest.mark.parametrize( + "version, cname, arch", + [ + ("today", "aws-gardener_prod", "arm64"), + ("today", "aws-gardener_prod", "amd64"), + ("today", "gcp-gardener_prod", "arm64"), + ("today", "gcp-gardener_prod", "amd64"), + ("today", "azure-gardener_prod", "arm64"), + ("today", "azure-gardener_prod", "amd64"), + ("today", "openstack-gardener_prod", "arm64"), + ("today", "openstack-gardener_prod", "amd64"), + ("today", "openstackbaremetal-gardener_prod", "arm64"), + ("today", "openstackbaremetal-gardener_prod", "amd64"), + ("today", "metal-kvm_dev", "arm64"), + ("today", "metal-kvm_dev", "amd64"), + ], +) + + +def test_push_manifest(version, arch, cname): + runner = CliRunner() + result = runner.invoke( + cli, + [ + "push-manifest", + "--container", + CONTAINER_NAME_ZOT_EXAMPLE, + "--version", + "1702.0", + "--arch", + "amd64", + "--cname", + "metal-gardener_prod", + "--dir", + #GARDENLINUX_ROOT_DIR_EXAMPLE + ], + catch_exceptions=False, + ) + if result.exit_code != 0: + print(f"Exit Code: {result.exit_code}") + print(f"Output: {result.output}") + if result.exception: + print(result.exception) + try: + print(f"Output: {result.stderr}") + except ValueError: + print("No stderr captured.") + assert result.exit_code == 0 \ No newline at end of file diff --git a/zot/config.json b/zot/config.json new file mode 100644 index 0000000..b9cf9d1 --- /dev/null +++ b/zot/config.json @@ -0,0 +1,13 @@ +{ + "distSpecVersion": "1.1.0", + "storage": { + "rootDirectory": "output/registry/zot" + }, + "http": { + "address": "127.0.0.1", + "port": "8081" + }, + "log": { + "level": "warn" + } +} \ No newline at end of file From 9616fc61fc89086cc7c2d21e54c8311486aaa08a Mon Sep 17 00:00:00 2001 From: Paul Hildebrandt Date: Wed, 27 Nov 2024 19:39:20 +0100 Subject: [PATCH 2/7] working e2e push manifests Signed-off-by: Paul Hildebrandt --- .gitignore | 3 +- tests/conftest.py | 38 +++++----------- tests/data/build-test-data.sh | 85 +++++++++++++++++++++++++++++++++++ tests/helper.py | 7 +-- tests/test_push_manifest.py | 23 +++++----- tests/zot/config.json | 21 +++++++++ zot/config.json | 13 ------ 7 files changed, 133 insertions(+), 57 deletions(-) create mode 100755 tests/data/build-test-data.sh create mode 100644 tests/zot/config.json delete mode 100644 zot/config.json diff --git a/.gitignore b/.gitignore index 7456785..df9f27c 100644 --- a/.gitignore +++ b/.gitignore @@ -163,4 +163,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -manifest-entry.json \ No newline at end of file +manifest-entry.json +tests/data/gardenlinux \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index ec30740..94bf17f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,29 +8,15 @@ from dotenv import load_dotenv -def write_zot_config(config_dict, file_path): - with open(file_path, "w") as config_file: - json.dump(config_dict, config_file, indent=4) - - @pytest.fixture(autouse=False, scope="function") def zot_session(): load_dotenv() print("start zot session") - zot_config = { - "distSpecVersion": "1.1.0", - "storage": {"rootDirectory": "output/registry/zot"}, - "http": {"address": "127.0.0.1", "port": "18081"}, - "log": {"level": "warn"}, - } - - with tempfile.NamedTemporaryFile(delete=False, suffix=".json") as temp_config_file: - write_zot_config(zot_config, temp_config_file.name) - zot_config_file_path = temp_config_file.name - - print(f"Spawning zot registry with config {zot_config_file_path}") + zot_config = json.load(open("tests/zot/config.json")) + + print(f"Spawning zot registry with config {zot_config}") zot_process = spawn_background_process( - f"zot serve {zot_config_file_path}", + f"zot serve {zot_config}", stdout=sys.stdout, stderr=sys.stderr, ) @@ -42,19 +28,17 @@ def zot_session(): if os.path.isdir("./output"): shutil.rmtree("./output") - if os.path.isfile(zot_config_file_path): - os.remove(zot_config_file_path) def pytest_sessionstart(session): - #call_command("./cert/gencert.sh") - print("pytest session started") - #call_command("./test-data/build-test-data.sh --dummy") + # call_command("./cert/gencert.sh") + print(" pytest session started") + call_command("./tests/data/build-test-data.sh --dummy") def pytest_sessionfinish(session): - print("pytest session finished") - #if os.path.isfile("./cert/oci-sign.crt"): + print(" pytest session finished") + # if os.path.isfile("./cert/oci-sign.crt"): # os.remove("./cert/oci-sign.crt") - #if os.path.isfile("./cert/oci-sign.key"): - # os.remove("./cert/oci-sign.key") \ No newline at end of file + # if os.path.isfile("./cert/oci-sign.key"): + # os.remove("./cert/oci-sign.key") diff --git a/tests/data/build-test-data.sh b/tests/data/build-test-data.sh new file mode 100755 index 0000000..8cfd1de --- /dev/null +++ b/tests/data/build-test-data.sh @@ -0,0 +1,85 @@ +#!/bin/bash +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +echo "This will take a while. Building for the following targets:" + +test_targets=( + "aws-gardener_prod" + "azure-gardener_prod" + "gcp-gardener_prod" + "openstack-gardener_prod" + "openstackbaremetal-gardener_prod" + "metal-kvm_dev" +) +test_arch=("amd64") +pushd $script_dir/gardenlinux +commit=$(git rev-parse --short=8 HEAD) +popd +fake_artifacts=( + "aws-gardener_prod-today-amd64-$commit.raw" + "aws-gardener_prod-today-arm64-$commit.raw" + "aws-gardener_prod-today-amd64-$commit.tar" + "aws-gardener_prod-today-arm64-$commit.tar" + "gcp-gardener_prod-today-amd64-$commit.tar.gz" + "gcp-gardener_prod-today-arm64-$commit.tar.gz" + "gcp-gardener_prod-today-amd64-$commit.gcpimage.tar.gz" + "gcp-gardener_prod-today-arm64-$commit.gcpimage.tar.gz" + "azure-gardener_prod-today-amd64-$commit.vhd" + "azure-gardener_prod-today-arm64-$commit.vhd" + "azure-gardener_prod-today-amd64-$commit.tar" + "azure-gardener_prod-today-arm64-$commit.tar" + "openstack-gardener_prod-today-amd64-$commit.qcow2" + "openstack-gardener_prod-today-arm64-$commit.qcow2" + "openstack-gardener_prod-today-amd64-$commit.vmdk" + "openstack-gardener_prod-today-arm64-$commit.vmdk" + "openstack-gardener_prod-today-amd64-$commit.tar" + "openstack-gardener_prod-today-arm64-$commit.tar" + "openstackbaremetal-gardener_prod-today-amd64-$commit.raw" + "openstackbaremetal-gardener_prod-today-arm64-$commit.raw" + "openstackbaremetal-gardener_prod-today-amd64-$commit.tar" + "openstackbaremetal-gardener_prod-today-arm64-$commit.tar" + "openstackbaremetal-gardener_prod-today-amd64-$commit.qcow2" + "openstackbaremetal-gardener_prod-today-arm64-$commit.qcow2" + "openstackbaremetal-gardener_prod-today-amd64-$commit.vmdk" + "openstackbaremetal-gardener_prod-today-arm64-$commit.vmdk" + "metal-kvm_dev-today-amd64-$commit.raw" + "metal-kvm_dev-today-arm64-$commit.raw" + "metal-kvm_dev-today-amd64-$commit.tar" + "metal-kvm_dev-today-arm64-$commit.tar" + ) + + +# Check if the --dummy flag is set +dummy_mode=false +if [[ "$1" == "--dummy" ]]; then + dummy_mode=true + echo "Dummy mode enabled. No actual builds will be performed." + for target in "${test_targets[@]}"; do + echo "$target (amd64 and arm64)" + done + else + read -p "Build targets listed above? (y/n): " confirm + if [[ "$confirm" != [yY] ]]; then + exit 1 + fi +fi + + + +if [ "$dummy_mode" = true ]; then + echo "Creating fake artifacts..." + mkdir -p $script_dir/gardenlinux/.build + for artifact in "${fake_artifacts[@]}"; do + echo "Creating fake artifact: $artifact" + touch "$script_dir/gardenlinux/.build/$artifact" # This simulates creating a fake artifact file + done + echo "Fake artifacts created." +else + pushd $script_dir/gardenlinux + for target in "${test_targets[@]}"; do + for arch in "${test_arch[@]}"; do + echo "Building $target-$arch..." + ./build "$target-$arch" + done + done + popd +fi diff --git a/tests/helper.py b/tests/helper.py index 8c0d864..be7a4a1 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -1,11 +1,6 @@ import subprocess import shlex -import os - -ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) -ZOT_CONFIG_FILE = f"/zot/config.json" - def spawn_background_process(cmd, stdout=None, stderr=None): args = shlex.split(cmd) @@ -24,4 +19,4 @@ def call_command(cmd): except subprocess.CalledProcessError as e: error_message = e.stderr.decode("utf-8") - return f"An error occurred: {error_message}" \ No newline at end of file + return f"An error occurred: {error_message}" diff --git a/tests/test_push_manifest.py b/tests/test_push_manifest.py index d54a916..31bdf70 100644 --- a/tests/test_push_manifest.py +++ b/tests/test_push_manifest.py @@ -1,12 +1,15 @@ import pytest from click.testing import CliRunner import sys + sys.path.append("src") + from glcli import cli -CONTAINER_NAME_ZOT_EXAMPLE = "127.0.0.1:18081/gardenlinux-example" -#GARDENLINUX_ROOT_DIR_EXAMPLE = "test-data/build-metal-gardener_prod" -TEST_DATA_DIR = "" + +CONTAINER_NAME_ZOT_EXAMPLE = "localhost:5000/gardenlinux" +GARDENLINUX_ROOT_DIR_EXAMPLE = "tests/data/gardenlinux/.build" + @pytest.mark.usefixtures("zot_session") @pytest.mark.parametrize( @@ -26,8 +29,6 @@ ("today", "metal-kvm_dev", "amd64"), ], ) - - def test_push_manifest(version, arch, cname): runner = CliRunner() result = runner.invoke( @@ -37,13 +38,15 @@ def test_push_manifest(version, arch, cname): "--container", CONTAINER_NAME_ZOT_EXAMPLE, "--version", - "1702.0", + version, # 1702.0 "--arch", - "amd64", + arch, # amd64 "--cname", - "metal-gardener_prod", + cname, # metal-gardener_prod "--dir", - #GARDENLINUX_ROOT_DIR_EXAMPLE + GARDENLINUX_ROOT_DIR_EXAMPLE, + "--insecure", + "True", ], catch_exceptions=False, ) @@ -56,4 +59,4 @@ def test_push_manifest(version, arch, cname): print(f"Output: {result.stderr}") except ValueError: print("No stderr captured.") - assert result.exit_code == 0 \ No newline at end of file + assert result.exit_code == 0 diff --git a/tests/zot/config.json b/tests/zot/config.json new file mode 100644 index 0000000..8d8e243 --- /dev/null +++ b/tests/zot/config.json @@ -0,0 +1,21 @@ +{ + "distSpecVersion": "1.1.0", + "storage": { + "rootDirectory": "output/registry/zot" + }, + "http": { + "address": "localhost", + "port": "8080" + }, + "log": { + "level": "warn" + }, + "extensions": { + "search": { + "enable": true + }, + "ui": { + "enable": true + } + } +} \ No newline at end of file diff --git a/zot/config.json b/zot/config.json deleted file mode 100644 index b9cf9d1..0000000 --- a/zot/config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "distSpecVersion": "1.1.0", - "storage": { - "rootDirectory": "output/registry/zot" - }, - "http": { - "address": "127.0.0.1", - "port": "8081" - }, - "log": { - "level": "warn" - } -} \ No newline at end of file From ba5a6ec07687d7340f61dc4e56b60182d3ed2e16 Mon Sep 17 00:00:00 2001 From: Paul Hildebrandt Date: Wed, 27 Nov 2024 23:00:35 +0100 Subject: [PATCH 3/7] cosign certs Signed-off-by: Paul Hildebrandt --- .gitignore | 1 + tests/cert/gencert.sh | 6 ++++++ tests/conftest.py | 19 ++++++++----------- tests/test_push_manifest.py | 8 +++++--- 4 files changed, 20 insertions(+), 14 deletions(-) create mode 100755 tests/cert/gencert.sh diff --git a/.gitignore b/.gitignore index df9f27c..0d378a3 100644 --- a/.gitignore +++ b/.gitignore @@ -164,4 +164,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ manifest-entry.json +digest tests/data/gardenlinux \ No newline at end of file diff --git a/tests/cert/gencert.sh b/tests/cert/gencert.sh new file mode 100755 index 0000000..7918236 --- /dev/null +++ b/tests/cert/gencert.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +CERT_NAME="$SCRIPT_DIR/oci-sign" + +openssl req -x509 -newkey rsa -pkeyopt rsa_keygen_bits:4096 -days 3650 -nodes -keyout $CERT_NAME.key -out $CERT_NAME.crt -subj "/CN=Garden Linux test signing key for oci" \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 94bf17f..e14d136 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,17 +1,14 @@ from helper import call_command, spawn_background_process import os -import tempfile import sys import shutil import json import pytest -from dotenv import load_dotenv @pytest.fixture(autouse=False, scope="function") def zot_session(): - load_dotenv() - print("start zot session") + print("Starting zot session") zot_config = json.load(open("tests/zot/config.json")) print(f"Spawning zot registry with config {zot_config}") @@ -22,7 +19,7 @@ def zot_session(): ) yield zot_process - print("clean up zot session") + print("Clean up zot session") zot_process.terminate() @@ -31,14 +28,14 @@ def zot_session(): def pytest_sessionstart(session): - # call_command("./cert/gencert.sh") - print(" pytest session started") + call_command("./tests/cert/gencert.sh") + print("pytest session started") call_command("./tests/data/build-test-data.sh --dummy") def pytest_sessionfinish(session): print(" pytest session finished") - # if os.path.isfile("./cert/oci-sign.crt"): - # os.remove("./cert/oci-sign.crt") - # if os.path.isfile("./cert/oci-sign.key"): - # os.remove("./cert/oci-sign.key") + if os.path.isfile("./tests/cert/oci-sign.crt"): + os.remove("./tests/cert/oci-sign.crt") + if os.path.isfile("./tests/cert/oci-sign.key"): + os.remove("./tests/cert/oci-sign.key") diff --git a/tests/test_push_manifest.py b/tests/test_push_manifest.py index 31bdf70..00edb4b 100644 --- a/tests/test_push_manifest.py +++ b/tests/test_push_manifest.py @@ -38,15 +38,17 @@ def test_push_manifest(version, arch, cname): "--container", CONTAINER_NAME_ZOT_EXAMPLE, "--version", - version, # 1702.0 + version, "--arch", - arch, # amd64 + arch, "--cname", - cname, # metal-gardener_prod + cname, "--dir", GARDENLINUX_ROOT_DIR_EXAMPLE, "--insecure", "True", + "--cosign_file", + "digest" ], catch_exceptions=False, ) From 7d9ce7cb35178eab619ad9994bf7670988a7d177 Mon Sep 17 00:00:00 2001 From: Paul Hildebrandt Date: Wed, 27 Nov 2024 23:01:05 +0100 Subject: [PATCH 4/7] cosign certs Signed-off-by: Paul Hildebrandt --- tests/test_push_manifest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_push_manifest.py b/tests/test_push_manifest.py index 00edb4b..62b41cb 100644 --- a/tests/test_push_manifest.py +++ b/tests/test_push_manifest.py @@ -48,7 +48,7 @@ def test_push_manifest(version, arch, cname): "--insecure", "True", "--cosign_file", - "digest" + "digest", ], catch_exceptions=False, ) From 4cc7dda9d5cce979903782bbed8625a147e9f323 Mon Sep 17 00:00:00 2001 From: Paul Hildebrandt Date: Wed, 27 Nov 2024 23:38:34 +0100 Subject: [PATCH 5/7] working e2e update index Signed-off-by: Paul Hildebrandt --- tests/test_update_index.py | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/test_update_index.py diff --git a/tests/test_update_index.py b/tests/test_update_index.py new file mode 100644 index 0000000..9023e5f --- /dev/null +++ b/tests/test_update_index.py @@ -0,0 +1,57 @@ +import pytest +from click.testing import CliRunner +import sys + +sys.path.append("src") + +from glcli import cli + + +CONTAINER_NAME_ZOT_EXAMPLE = "localhost:5000/gardenlinux" + + +@pytest.mark.usefixtures("zot_session") +@pytest.mark.parametrize( + "version, cname, arch", + [ + ("today", "aws-gardener_prod", "arm64"), + ("today", "aws-gardener_prod", "amd64"), + ("today", "gcp-gardener_prod", "arm64"), + ("today", "gcp-gardener_prod", "amd64"), + ("today", "azure-gardener_prod", "arm64"), + ("today", "azure-gardener_prod", "amd64"), + ("today", "openstack-gardener_prod", "arm64"), + ("today", "openstack-gardener_prod", "amd64"), + ("today", "openstackbaremetal-gardener_prod", "arm64"), + ("today", "openstackbaremetal-gardener_prod", "amd64"), + ("today", "metal-kvm_dev", "arm64"), + ("today", "metal-kvm_dev", "amd64"), + ], +) +def test_update_index(version, arch, cname): + runner = CliRunner() + result = runner.invoke( + cli, + [ + "update-index", + "--container", + CONTAINER_NAME_ZOT_EXAMPLE, + "--version", + version, + "--insecure", + "True", + "--manifest_file", + "manifest-entry.json", + ], + catch_exceptions=False, + ) + if result.exit_code != 0: + print(f"Exit Code: {result.exit_code}") + print(f"Output: {result.output}") + if result.exception: + print(result.exception) + try: + print(f"Output: {result.stderr}") + except ValueError: + print("No stderr captured.") + assert result.exit_code == 0 From e204e94d5a0797a975af0ae6630e32a83c56132c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCnch?= Date: Thu, 28 Nov 2024 11:08:07 +0100 Subject: [PATCH 6/7] status quo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Malte Münch --- tests/conftest.py | 3 +- tests/test_push_manifest.py | 41 +++++++++++++++++--------- tests/test_update_index.py | 57 ------------------------------------- tests/zot/config.json | 4 +-- 4 files changed, 31 insertions(+), 74 deletions(-) delete mode 100644 tests/test_update_index.py diff --git a/tests/conftest.py b/tests/conftest.py index e14d136..87807d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,8 +9,7 @@ @pytest.fixture(autouse=False, scope="function") def zot_session(): print("Starting zot session") - zot_config = json.load(open("tests/zot/config.json")) - + zot_config = "tests/zot/config.json" print(f"Spawning zot registry with config {zot_config}") zot_process = spawn_background_process( f"zot serve {zot_config}", diff --git a/tests/test_push_manifest.py b/tests/test_push_manifest.py index 62b41cb..f48ad28 100644 --- a/tests/test_push_manifest.py +++ b/tests/test_push_manifest.py @@ -16,20 +16,9 @@ "version, cname, arch", [ ("today", "aws-gardener_prod", "arm64"), - ("today", "aws-gardener_prod", "amd64"), - ("today", "gcp-gardener_prod", "arm64"), - ("today", "gcp-gardener_prod", "amd64"), - ("today", "azure-gardener_prod", "arm64"), - ("today", "azure-gardener_prod", "amd64"), - ("today", "openstack-gardener_prod", "arm64"), - ("today", "openstack-gardener_prod", "amd64"), - ("today", "openstackbaremetal-gardener_prod", "arm64"), - ("today", "openstackbaremetal-gardener_prod", "amd64"), - ("today", "metal-kvm_dev", "arm64"), - ("today", "metal-kvm_dev", "amd64"), ], ) -def test_push_manifest(version, arch, cname): +def test_push_manifest_and_index(version, arch, cname): runner = CliRunner() result = runner.invoke( cli, @@ -52,9 +41,35 @@ def test_push_manifest(version, arch, cname): ], catch_exceptions=False, ) + print(f"Output: {result.stdout_bytes}") + if result.exit_code != 0: + print(f"Exit Code: {result.exit_code}") + if result.exception: + print(result.exception) + try: + print(f"Output: {result.stderr}") + except ValueError: + print("No stderr captured.") + assert result.exit_code == 0 + + result = runner.invoke( + cli, + [ + "update-index", + "--container", + CONTAINER_NAME_ZOT_EXAMPLE, + "--version", + version, + "--insecure", + "True", + "--manifest_file", + "manifest-entry.json", + ], + catch_exceptions=False, + ) + print(f"Output: {result.output}") if result.exit_code != 0: print(f"Exit Code: {result.exit_code}") - print(f"Output: {result.output}") if result.exception: print(result.exception) try: diff --git a/tests/test_update_index.py b/tests/test_update_index.py deleted file mode 100644 index 9023e5f..0000000 --- a/tests/test_update_index.py +++ /dev/null @@ -1,57 +0,0 @@ -import pytest -from click.testing import CliRunner -import sys - -sys.path.append("src") - -from glcli import cli - - -CONTAINER_NAME_ZOT_EXAMPLE = "localhost:5000/gardenlinux" - - -@pytest.mark.usefixtures("zot_session") -@pytest.mark.parametrize( - "version, cname, arch", - [ - ("today", "aws-gardener_prod", "arm64"), - ("today", "aws-gardener_prod", "amd64"), - ("today", "gcp-gardener_prod", "arm64"), - ("today", "gcp-gardener_prod", "amd64"), - ("today", "azure-gardener_prod", "arm64"), - ("today", "azure-gardener_prod", "amd64"), - ("today", "openstack-gardener_prod", "arm64"), - ("today", "openstack-gardener_prod", "amd64"), - ("today", "openstackbaremetal-gardener_prod", "arm64"), - ("today", "openstackbaremetal-gardener_prod", "amd64"), - ("today", "metal-kvm_dev", "arm64"), - ("today", "metal-kvm_dev", "amd64"), - ], -) -def test_update_index(version, arch, cname): - runner = CliRunner() - result = runner.invoke( - cli, - [ - "update-index", - "--container", - CONTAINER_NAME_ZOT_EXAMPLE, - "--version", - version, - "--insecure", - "True", - "--manifest_file", - "manifest-entry.json", - ], - catch_exceptions=False, - ) - if result.exit_code != 0: - print(f"Exit Code: {result.exit_code}") - print(f"Output: {result.output}") - if result.exception: - print(result.exception) - try: - print(f"Output: {result.stderr}") - except ValueError: - print("No stderr captured.") - assert result.exit_code == 0 diff --git a/tests/zot/config.json b/tests/zot/config.json index 8d8e243..be931bf 100644 --- a/tests/zot/config.json +++ b/tests/zot/config.json @@ -5,7 +5,7 @@ }, "http": { "address": "localhost", - "port": "8080" + "port": "5000" }, "log": { "level": "warn" @@ -18,4 +18,4 @@ "enable": true } } -} \ No newline at end of file +} From c2fb42d799dc0a0ba23193328df0156d41222d59 Mon Sep 17 00:00:00 2001 From: Paul Hildebrandt Date: Thu, 28 Nov 2024 13:03:53 +0100 Subject: [PATCH 7/7] logging Signed-off-by: Paul Hildebrandt --- tests/conftest.py | 1 - tests/{test_push_manifest.py => test_e2e.py} | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) rename tests/{test_push_manifest.py => test_e2e.py} (91%) diff --git a/tests/conftest.py b/tests/conftest.py index 87807d5..a6b2629 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,6 @@ import os import sys import shutil -import json import pytest diff --git a/tests/test_push_manifest.py b/tests/test_e2e.py similarity index 91% rename from tests/test_push_manifest.py rename to tests/test_e2e.py index f48ad28..e64652f 100644 --- a/tests/test_push_manifest.py +++ b/tests/test_e2e.py @@ -1,6 +1,7 @@ import pytest from click.testing import CliRunner import sys +import logging sys.path.append("src") @@ -16,9 +17,11 @@ "version, cname, arch", [ ("today", "aws-gardener_prod", "arm64"), + ("today", "aws-gardener_prod", "amd64"), ], ) def test_push_manifest_and_index(version, arch, cname): + logger = logging.getLogger(__name__) runner = CliRunner() result = runner.invoke( cli, @@ -41,7 +44,7 @@ def test_push_manifest_and_index(version, arch, cname): ], catch_exceptions=False, ) - print(f"Output: {result.stdout_bytes}") + print(f"Output: {result.output}") if result.exit_code != 0: print(f"Exit Code: {result.exit_code}") if result.exception: @@ -52,6 +55,8 @@ def test_push_manifest_and_index(version, arch, cname): print("No stderr captured.") assert result.exit_code == 0 + logger.info("Pushed manifests") + result = runner.invoke( cli, [