From 33d6a609ef026e6f073fef892602db5685bb912b Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 27 May 2024 16:54:57 +0200 Subject: [PATCH] Show all imagestreams in imagestream file New Python function is created so the imagestreams are shown always. This fixes PR https://github.com/sclorg/container-common-scripts/pull/256 Signed-off-by: Petr "Stone" Hracek --- show_all_imagestreams.py | 64 +++++++++++++++++++++++++++++++++++++ test-lib.sh | 5 ++- tests/check_imagestreams.sh | 5 +++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 show_all_imagestreams.py diff --git a/show_all_imagestreams.py b/show_all_imagestreams.py new file mode 100644 index 00000000..284986e5 --- /dev/null +++ b/show_all_imagestreams.py @@ -0,0 +1,64 @@ +#!/bin/env python3 + +# MIT License +# +# Copyright (c) 2018-2019 Red Hat, Inc. + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import json +import os + +from pathlib import Path +from typing import Dict, Any + +IMAGESTREAMS_DIR: str = "imagestreams" + + +class ShowAllImageStreams(object): + version: str = "" + + def __init__(self): + pass + + def load_json_file(self, filename: Path) -> Any: + with open(str(filename)) as f: + data = json.load(f) + isinstance(data, Dict) + return data + + def show_all_imagestreams(self): + p = Path(".") + json_files = p.glob(f"{IMAGESTREAMS_DIR}/*.json") + if not json_files: + print(f"No json files present in {IMAGESTREAMS_DIR}.") + return 0 + for f in json_files: + if os.environ.get("TARGET") in ("rhel7", "centos7") and "aarch64" in str(f): + print("Imagestream aarch64 is not supported on rhel7") + continue + json_dict = self.load_json_file(f) + print(f"Tags in the image stream {f}:") + for tag in json_dict["spec"]["tags"]: + print(f"- {tag['name']} -> {tag['from']['name']}") + + +if __name__ == "__main__": + isc = ShowAllImageStreams() + isc.show_all_imagestreams() diff --git a/test-lib.sh b/test-lib.sh index 355ea975..809602a3 100644 --- a/test-lib.sh +++ b/test-lib.sh @@ -1126,6 +1126,7 @@ ct_check_image_availability() { fi } + # ct_check_latest_imagestreams # ----------------------------- # Check if the latest version present in Makefile in the variable VERSIONS @@ -1147,9 +1148,11 @@ ct_check_latest_imagestreams() { [ -f "$latest_version/.exclude-$OS" ] && latest_version=$(grep '^VERSIONS' Makefile | rev | cut -d ' ' -f 2 | rev ) # Only test the imagestream once, when the version matches # ignore the SC warning, $VERSION is always available + + test_lib_dir=$(dirname "$(readlink -f "$0")") + python3 "${test_lib_dir}/show_all_imagestreams.py" # shellcheck disable=SC2153 if [ "$latest_version" == "$VERSION" ]; then - test_lib_dir=$(dirname "$(readlink -f "$0")") python3 "${test_lib_dir}/check_imagestreams.py" "$latest_version" else echo "Image version $VERSION is not latest, skipping ct_check_latest_imagestreams" diff --git a/tests/check_imagestreams.sh b/tests/check_imagestreams.sh index caef12ba..df8ad5ac 100755 --- a/tests/check_imagestreams.sh +++ b/tests/check_imagestreams.sh @@ -3,7 +3,12 @@ set -x check_imagestreams=$(dirname "$(readlink -f "$0")")/../check_imagestreams.py +show_all_imagestreams=$(dirname "$(readlink -f "$0")")/../show_all_imagestreams.py "${PYTHON-python3}" "$check_imagestreams" "2.5" test $? -eq 1 "${PYTHON-python3}" "$check_imagestreams" "2.4" test $? -eq 0 +echo "Check full is output" +output=$("${PYTHON-python3}" "$show_all_imagestreams") +test "${output#*"- latest -> 2.4"}" != "$output" && echo "latest found in the output" +test "${output#*"- 2.4 -> registry.redhat.io/rhscl/httpd-24-rhel7"}" != "$output" && echo "2.4 found in the output"