mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
Release 3.0.2
This commit is contained in:
54 files changed
+4007
-374
No files matched your search
@@ -0,0 +1,187 @@
|
||||
#!/bin/sh
|
||||
# Read-only support metadata. No network requests, logs or credential collection.
|
||||
# Process-tree cleanup is best effort; deliberately daemonized probes can escape it.
|
||||
umask 077
|
||||
LC_ALL=C
|
||||
export LC_ALL
|
||||
GP_DIAGNOSTICS_HOME=$(printf '%s' "${HOME:-}" | tr '\000-\037\177' ' ')
|
||||
export GP_DIAGNOSTICS_HOME
|
||||
client_version= client_path= auth_path= gui_path= output=
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--help) printf '%s\n' 'Usage: sh collect-diagnostics.sh [--output PATH]' 'Collect local support metadata; review before sharing. No sudo required.'; exit 0 ;;
|
||||
--output|--client-version|--client-path|--auth-path|--gui-path)
|
||||
[ "$#" -ge 2 ] || { printf '%s\n' 'Missing option value' >&2; exit 2; }
|
||||
case "$1" in
|
||||
--output) output=$2 ;; --client-version) client_version=$2 ;;
|
||||
--client-path) client_path=$2 ;; --auth-path) auth_path=$2 ;; --gui-path) gui_path=$2 ;;
|
||||
esac
|
||||
shift 2 ;;
|
||||
*) printf '%s\n' 'Unknown option' >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$output" ]; then
|
||||
set -C
|
||||
exec 3> "$output" || exit 1
|
||||
set +C
|
||||
exec 1>&3
|
||||
fi
|
||||
work=$(mktemp -d "${TMPDIR:-/tmp}/gp-diagnostics.XXXXXXXX") || exit 1
|
||||
chmod 700 "$work" || exit 1
|
||||
active= timer=
|
||||
# Use a fixed PID/PPID snapshot, never full process arguments.
|
||||
stop_tree() {
|
||||
tree_root=$1
|
||||
ps -axo pid=,ppid= > "$work/tree.$tree_root" 2>/dev/null || :
|
||||
tree_pids=$(awk -v root="$tree_root" '
|
||||
{parent[$1]=$2} END {
|
||||
marked[root]=1
|
||||
for (i=0;i<100;i++) {changed=0; for (pid in parent) if (marked[parent[pid]] && !marked[pid]) {marked[pid]=1; changed=1} if (!changed) break}
|
||||
for (pid in marked) if (marked[pid] && pid != root) print pid
|
||||
}' "$work/tree.$tree_root")
|
||||
# Stop descendants before the direct child: reaping the child must not race
|
||||
# cancellation of a watchdog which is still terminating descendants.
|
||||
for tree_pid in $tree_pids; do kill -TERM "$tree_pid" 2>/dev/null || :; done
|
||||
for tree_pid in $tree_pids; do kill -KILL "$tree_pid" 2>/dev/null || :; done
|
||||
kill -TERM "$tree_root" 2>/dev/null || :
|
||||
kill -KILL "$tree_root" 2>/dev/null || :
|
||||
}
|
||||
cleanup() {
|
||||
[ -z "$active" ] || { stop_tree "$active"; wait "$active" 2>/dev/null || :; }
|
||||
[ -z "$timer" ] || { stop_tree "$timer"; wait "$timer" 2>/dev/null || :; }
|
||||
rm -rf "$work"
|
||||
}
|
||||
trap cleanup 0
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM HUP
|
||||
emit() {
|
||||
# HOME is matched literally, never used as a regular expression.
|
||||
[ "$2" = ok ] || { printf '%s: %s: \n' "$1" "$2"; return; }
|
||||
clean=$(printf '%s' "$3" | tr '\000-\037\177' ' ' | awk '
|
||||
BEGIN {home=ENVIRON["GP_DIAGNOSTICS_HOME"]}
|
||||
{text=$0; result=""; while (length(home)>0 && (pos=index(text,home))>0) {
|
||||
tail=substr(text,pos+length(home)); result=result substr(text,1,pos-1)
|
||||
if (tail=="" || substr(tail,1,1)=="/") result=result "~"; else result=result home
|
||||
text=tail
|
||||
} text=result text; printf "%s",substr(text,1,500)}')
|
||||
printf '%s: %s: %s\n' "$1" "$2" "$clean"
|
||||
}
|
||||
probe() {
|
||||
probe_status= probe_value=
|
||||
if ! command -v "$1" >/dev/null 2>&1; then probe_status=unavailable; return; fi
|
||||
rm -f "$work/timed"
|
||||
# ulimit -f is POSIX and limits stdout's regular file to at most 64 KiB.
|
||||
(trap - 0 INT TERM HUP; ulimit -f 64; exec "$@") < /dev/null > "$work/out" 2>/dev/null &
|
||||
active=$!
|
||||
(
|
||||
trap - 0 INT TERM HUP
|
||||
watchdog_sleep=
|
||||
trap '[ -z "$watchdog_sleep" ] || { kill "$watchdog_sleep" 2>/dev/null || :; wait "$watchdog_sleep" 2>/dev/null || :; }; exit' TERM HUP INT
|
||||
sleep 3 &
|
||||
watchdog_sleep=$!
|
||||
wait "$watchdog_sleep"
|
||||
: > "$work/timed"
|
||||
stop_tree "$active"
|
||||
) 2>/dev/null &
|
||||
timer=$!
|
||||
if wait "$active" 2>/dev/null; then probe_status=ok; else probe_status=failed; fi
|
||||
active=
|
||||
# Cancel immediately; a process-tree snapshot here could itself cross the
|
||||
# timeout deadline after a successful probe. The watchdog reaps its sleep.
|
||||
kill -TERM "$timer" 2>/dev/null || :
|
||||
wait "$timer" 2>/dev/null || :
|
||||
timer=
|
||||
if [ "$probe_status" = failed ] && [ -f "$work/timed" ]; then probe_status=timed_out; fi
|
||||
if [ "$probe_status" != timed_out ]; then probe_value=$(cat "$work/out"); fi
|
||||
}
|
||||
field_probe() { field_key=$1; shift; probe "$@"; emit "$field_key" "$probe_status" "$probe_value"; }
|
||||
emit schema_version ok 1
|
||||
probe uname -s
|
||||
os=$probe_value
|
||||
emit os "$probe_status" "$os"
|
||||
field_probe kernel uname -r
|
||||
field_probe architecture uname -m
|
||||
probe id -u
|
||||
case "$probe_status:$probe_value" in ok:0) emit execution_user ok root ;; ok:*) emit execution_user ok normal_user ;; *) emit execution_user "$probe_status" '' ;; esac
|
||||
if [ -n "${SSH_CONNECTION:-}${SSH_CLIENT:-}${SSH_TTY:-}" ]; then emit ssh_session ok yes; else emit ssh_session ok no; fi
|
||||
case "$os" in
|
||||
Linux)
|
||||
if [ -r /etc/os-release ]; then
|
||||
probe awk -F= '$1=="PRETTY_NAME" {value=substr($0,index($0,"=")+1); if (value ~ /^".*"$/ || value ~ /^\047.*\047$/) value=substr(value,2,length(value)-2); print value; exit}' /etc/os-release
|
||||
if [ "$probe_status" = ok ] && [ -z "$probe_value" ]; then probe_status=unavailable; fi
|
||||
emit os_version "$probe_status" "$probe_value"
|
||||
else emit os_version unavailable ''; fi
|
||||
probe systemd-detect-virt
|
||||
if [ "$probe_status" = failed ] && [ "$probe_value" = none ]; then probe_status=ok; fi
|
||||
emit virtualization "$probe_status" "$probe_value" ;;
|
||||
Darwin) field_probe os_version sw_vers -productVersion; emit virtualization unavailable '' ;;
|
||||
FreeBSD|OpenBSD) field_probe os_version uname -r; field_probe virtualization sysctl -n kern.vm_guest ;;
|
||||
*) emit os_version unavailable ''; emit virtualization unavailable '' ;;
|
||||
esac
|
||||
# Helpers accept only known safe version switches. Never invoke GUI binaries.
|
||||
[ -n "$client_path" ] || client_path=$(command -v gpclient 2>/dev/null || :)
|
||||
[ -n "$auth_path" ] || auth_path=$(command -v gpauth 2>/dev/null || :)
|
||||
[ -n "$gui_path" ] || gui_path=$(command -v gpgui 2>/dev/null || :)
|
||||
if [ "$os" = Darwin ]; then
|
||||
bundle=/Applications/GP\ Connect.app/Contents
|
||||
gui_bundle=
|
||||
case "$gui_path" in *.app/Contents/MacOS/*) gui_bundle=${gui_path%/MacOS/*}; bundle=$gui_bundle ;; esac
|
||||
[ -n "$client_path" ] || { [ ! -x "$bundle/Helpers/gpclient" ] || client_path=$bundle/Helpers/gpclient; }
|
||||
[ -n "$auth_path" ] || { [ ! -x "$bundle/Helpers/gpauth" ] || auth_path=$bundle/Helpers/gpauth; }
|
||||
[ -n "$gui_path" ] || { [ ! -d "$bundle" ] || { gui_path=$bundle/MacOS/gpgui; gui_bundle=$bundle; }; }
|
||||
fi
|
||||
for component in gpclient gpauth gpgui; do
|
||||
case "$component" in gpclient) location=$client_path ;; gpauth) location=$auth_path ;; gpgui) location=$gui_path ;; esac
|
||||
if [ -n "$location" ]; then emit "${component}_path" ok "$location"; else emit "${component}_path" unavailable ''; fi
|
||||
done
|
||||
if [ -n "$client_version" ]; then emit gpclient_version ok "$client_version"; elif [ -n "$client_path" ]; then field_probe gpclient_version "$client_path" --version; else emit gpclient_version unavailable ''; fi
|
||||
if [ -n "$auth_path" ]; then field_probe gpauth_version "$auth_path" --version; else emit gpauth_version unavailable ''; fi
|
||||
if [ "$os" = Darwin ] && [ -n "$gui_bundle" ]; then
|
||||
field_probe gpgui_version /usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$gui_bundle/Info.plist"
|
||||
else
|
||||
emit gpgui_version unavailable ''
|
||||
fi
|
||||
case "$os" in
|
||||
Darwin) emit display_protocol not_applicable ''; probe system_profiler SPDisplaysDataType; graphics_value=$(printf '%s\n' "$probe_value" | awk '/Chipset Model:/ {print}'); emit graphics "$probe_status" "$graphics_value" ;;
|
||||
*)
|
||||
if [ -n "${WAYLAND_DISPLAY:-}" ]; then emit display_protocol ok wayland; elif [ -n "${DISPLAY:-}" ]; then emit display_protocol ok x11; else emit display_protocol unset ''; fi
|
||||
case "$os" in
|
||||
Linux) probe lspci -nnk; graphics_status=$probe_status; graphics_value=$(printf '%s\n' "$probe_value" | awk '/^[^ \t]/ {show=($0 ~ /VGA|3D controller|Display controller/)} show {print}') ;;
|
||||
FreeBSD) probe pciconf -lv; graphics_status=$probe_status; graphics_value=$(printf '%s\n' "$probe_value" | awk '/^[^ \t]/ {show=($0 ~ /^vgapci/)} show {print}') ;;
|
||||
OpenBSD) probe pcidump; graphics_status=$probe_status; graphics_value=$(printf '%s\n' "$probe_value" | awk '/VGA|Display|Graphics/ {print}') ;;
|
||||
*) graphics_status=not_applicable; graphics_value= ;;
|
||||
esac
|
||||
emit graphics "$graphics_status" "$graphics_value" ;;
|
||||
esac
|
||||
case "$os" in
|
||||
Linux)
|
||||
if command -v pacman >/dev/null 2>&1; then probe pacman -Q webkit2gtk-4.1 gtk3 mesa nvidia-utils nvidia-open nvidia egl-wayland
|
||||
elif command -v dpkg-query >/dev/null 2>&1; then probe dpkg-query -W '-f=${binary:Package} ${Version}\n' 'libwebkit2gtk*' 'libgtk-3-0*' 'libegl-mesa*' 'libgl1-mesa*' 'nvidia-driver*' 'libnvidia-egl-wayland*'
|
||||
elif command -v rpm >/dev/null 2>&1; then probe rpm -q webkit2gtk4.1 gtk3 mesa-dri-drivers mesa-libEGL xorg-x11-drv-nvidia egl-wayland
|
||||
else probe_status=unavailable; probe_value=; fi
|
||||
probe_value=$(printf '%s\n' "$probe_value" | awk '$1 ~ /^(webkit2gtk|libwebkit2gtk|gtk3|libgtk-3|mesa|libegl-mesa|libgl1-mesa|nvidia|xorg-x11-drv-nvidia|egl-wayland|libnvidia-egl-wayland)/ && $0 !~ /not installed|no packages found|unknown package/ {print}')
|
||||
[ -z "$probe_value" ] || probe_status=ok
|
||||
emit graphics_packages "$probe_status" "$probe_value"
|
||||
;;
|
||||
FreeBSD) probe pkg query -a '%n %v'; package_value=$(printf '%s\n' "$probe_value" | awk '$1 ~ /^(webkit2-gtk3|webkit2-gtk_41|gtk3|mesa-dri|nvidia-driver)(-|$)/'); emit graphics_packages "$probe_status" "$package_value" ;;
|
||||
OpenBSD) probe pkg_info -a; package_value=$(printf '%s\n' "$probe_value" | awk '$1 ~ /^(webkitgtk|webkitgtk41|gtk\+3|mesa|nvidia)-/'); emit graphics_packages "$probe_status" "$package_value" ;;
|
||||
*) emit graphics_packages not_applicable '' ;;
|
||||
esac
|
||||
# Desktop binaries are not launched: version information comes from package metadata.
|
||||
case "$os" in
|
||||
Linux)
|
||||
if command -v pacman >/dev/null 2>&1; then probe pacman -Q plasma-workspace hyprland sway gnome-shell cosmic-comp
|
||||
elif command -v dpkg-query >/dev/null 2>&1; then probe dpkg-query -W '-f=${binary:Package} ${Version}\n' plasma-workspace hyprland sway gnome-shell cosmic-comp
|
||||
elif command -v rpm >/dev/null 2>&1; then probe rpm -q plasma-workspace hyprland sway gnome-shell cosmic-comp
|
||||
else probe_status=unavailable; probe_value=; fi
|
||||
probe_value=$(printf '%s\n' "$probe_value" | awk '$1 ~ /^(plasma-workspace|hyprland|sway|gnome-shell|cosmic-comp)/ && $0 !~ /not installed|no packages found|unknown package/ {print}')
|
||||
[ -z "$probe_value" ] || probe_status=ok
|
||||
emit desktop_version "$probe_status" "$probe_value" ;;
|
||||
FreeBSD) probe pkg query -a '%n %v'; package_value=$(printf '%s\n' "$probe_value" | awk '$1 ~ /^(plasma6-plasma-workspace|hyprland|sway|gnome-shell)(-|$)/'); emit desktop_version "$probe_status" "$package_value" ;;
|
||||
OpenBSD) probe pkg_info -a; package_value=$(printf '%s\n' "$probe_value" | awk '$1 ~ /^(plasma|hyprland|sway|gnome-shell)-/'); emit desktop_version "$probe_status" "$package_value" ;;
|
||||
*) emit desktop_version not_applicable '' ;;
|
||||
esac
|
||||
for name in XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE DESKTOP_SESSION WEBKIT_DISABLE_DMABUF_RENDERER WEBKIT_DISABLE_COMPOSITING_MODE LIBGL_ALWAYS_SOFTWARE __NV_DISABLE_EXPLICIT_SYNC GDK_BACKEND GDK_GL; do
|
||||
eval 'present=${'"$name"'+yes}; value=${'"$name"'-}'
|
||||
if [ "$present" = yes ]; then emit "env.$name" ok "$value"; else emit "env.$name" unset ''; fi
|
||||
done
|
||||
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Restrict distribution submissions to the targets selected for this rollout."""
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from urllib.parse import quote, urlencode
|
||||
from urllib.request import Request, urlopen
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
def request(url, data=None):
|
||||
headers = {"User-Agent": "gp-release-target-selector", "Cache-Control": "no-cache"}
|
||||
if data is not None:
|
||||
credentials = f"{os.environ['OBS_USERNAME']}:{os.environ['OBS_PASSWORD']}"
|
||||
headers["Authorization"] = "Basic " + base64.b64encode(credentials.encode()).decode()
|
||||
headers["Content-Type"] = "application/xml"
|
||||
method = "PUT" if data is not None else "GET"
|
||||
with urlopen(Request(url, data=data, headers=headers, method=method), timeout=30) as response:
|
||||
return response.read()
|
||||
|
||||
|
||||
def selection(values, available):
|
||||
if not values:
|
||||
values = sorted(available)
|
||||
if not values or len(values) != len(set(values)):
|
||||
raise ValueError("Select at least one target, without duplicates")
|
||||
unknown = set(values) - set(available)
|
||||
if unknown:
|
||||
raise ValueError(f"Unknown targets: {', '.join(sorted(unknown))}; available: {', '.join(sorted(available))}")
|
||||
return sorted(values)
|
||||
|
||||
|
||||
def copr(args):
|
||||
if args.build_id:
|
||||
if args.build_id <= 0:
|
||||
raise ValueError("Copr build ID must be positive")
|
||||
build = json.loads(request(f"https://copr.fedorainfracloud.org/api_3/build/{args.build_id}"))
|
||||
if build["ownername"] != args.owner or build["projectname"] != args.project:
|
||||
raise ValueError("Copr build belongs to another project")
|
||||
available = build["chroots"]
|
||||
else:
|
||||
query = urlencode({"ownername": args.owner, "projectname": args.project})
|
||||
project = json.loads(request(f"https://copr.fedorainfracloud.org/api_3/project?{query}"))
|
||||
available = project["chroot_repos"]
|
||||
if any(not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9_.-]*", name) for name in available):
|
||||
raise ValueError("Copr returned an invalid chroot name")
|
||||
distros = selection(args.distros, {chroot.rsplit("-", 1)[0] for chroot in available})
|
||||
return sorted(chroot for chroot in available if chroot.rsplit("-", 1)[0] in distros)
|
||||
|
||||
|
||||
def obs_results(project, package):
|
||||
query = urlencode({"package": package, "view": "status"})
|
||||
root = ET.fromstring(request(f"https://api.opensuse.org/public/build/{project}/_result?{query}"))
|
||||
return {f"{result.get('repository')}/{result.get('arch')}": result.find("status").get("code")
|
||||
for result in root if result.find("status") is not None}
|
||||
|
||||
|
||||
def obs_metadata(metadata, targets):
|
||||
# Keep publication flags for unselected targets so their existing binaries stay available.
|
||||
build = metadata.find("build")
|
||||
if build is None:
|
||||
build = ET.SubElement(metadata, "build")
|
||||
build.clear()
|
||||
ET.SubElement(build, "disable")
|
||||
publish = metadata.find("publish")
|
||||
if publish is None:
|
||||
publish = ET.SubElement(metadata, "publish")
|
||||
for target in targets:
|
||||
repo, arch = target.split("/")
|
||||
attributes = {"repository": repo, "arch": arch}
|
||||
ET.SubElement(build, "enable", attributes)
|
||||
for flag in list(publish):
|
||||
if flag.attrib == attributes:
|
||||
publish.remove(flag)
|
||||
ET.SubElement(publish, "enable", attributes)
|
||||
return metadata
|
||||
|
||||
|
||||
def obs(args):
|
||||
project = quote(args.project, safe=":")
|
||||
package = quote(args.package, safe="")
|
||||
project_metadata = ET.fromstring(request(f"https://api.opensuse.org/public/source/{project}/_meta"))
|
||||
available = {f"{repo.get('name')}/{arch.text}" for repo in project_metadata.findall("repository")
|
||||
for arch in repo.findall("arch")}
|
||||
states = obs_results(project, package)
|
||||
active = {target for target, state in states.items() if state not in {"disabled", "excluded"}}
|
||||
if args.repositories:
|
||||
repositories = selection(args.repositories, {target.split("/")[0] for target in available})
|
||||
targets = sorted(target for target in available if target.split("/")[0] in repositories)
|
||||
else:
|
||||
targets = selection(sorted(active), available)
|
||||
if args.verify_only:
|
||||
if set(targets) != active:
|
||||
raise ValueError("OBS enabled targets differ from the requested verification selection; no flags changed")
|
||||
elif args.repositories:
|
||||
# Do not let an already-running unselected build publish during a rollout change.
|
||||
busy = {target for target in active - set(targets)
|
||||
if states[target] not in {"succeeded", "failed", "broken", "unresolvable"}}
|
||||
if busy:
|
||||
raise ValueError(f"Unselected OBS targets are still active: {', '.join(sorted(busy))}; wait before changing selection")
|
||||
url = f"https://api.opensuse.org/source/{project}/{package}/_meta"
|
||||
public_url = f"https://api.opensuse.org/public/source/{project}/{package}/_meta"
|
||||
metadata = ET.fromstring(request(public_url))
|
||||
updated = obs_metadata(metadata, targets)
|
||||
request(url, ET.tostring(updated, encoding="utf-8"))
|
||||
# Confirm the scheduler applied the allowlist before committing new source.
|
||||
deadline = time.monotonic() + 120
|
||||
while True:
|
||||
states = obs_results(project, package)
|
||||
active = {target for target, state in states.items() if state not in {"disabled", "excluded"}}
|
||||
if active == set(targets):
|
||||
break
|
||||
if time.monotonic() >= deadline:
|
||||
raise ValueError("OBS target flags have not taken effect; source was not uploaded; flags remain selected")
|
||||
time.sleep(5)
|
||||
args.output.write_text(json.dumps(targets) + "\n")
|
||||
return targets
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
commands = parser.add_subparsers(dest="service", required=True)
|
||||
copr_parser = commands.add_parser("copr")
|
||||
copr_parser.add_argument("--distros", type=str.split, default=[])
|
||||
copr_parser.add_argument("--owner", default="yuezk")
|
||||
copr_parser.add_argument("--project", default="globalprotect-openconnect")
|
||||
copr_parser.add_argument("--build-id", type=int)
|
||||
obs_parser = commands.add_parser("obs")
|
||||
obs_parser.add_argument("--repositories", type=str.split, default=[])
|
||||
obs_parser.add_argument("--project", default="home:yuezk")
|
||||
obs_parser.add_argument("--package", default="globalprotect-openconnect")
|
||||
obs_parser.add_argument("--verify-only", action="store_true")
|
||||
obs_parser.add_argument("--output", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
targets = {"copr": copr, "obs": obs}[args.service](args)
|
||||
except (ValueError, KeyError, OSError, ET.ParseError) as error:
|
||||
print(str(error), file=sys.stderr)
|
||||
return 1
|
||||
message = f"Selected {args.service} targets: {' '.join(targets)}"
|
||||
print(message)
|
||||
if output := os.environ.get("GITHUB_OUTPUT"):
|
||||
with open(output, "a") as file:
|
||||
file.write(f"targets={' '.join(targets)}\n")
|
||||
if summary := os.environ.get("GITHUB_STEP_SUMMARY"):
|
||||
with open(summary, "a") as file:
|
||||
file.write(message + "\n")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,200 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
|
||||
collector=$root/scripts/collect-diagnostics.sh
|
||||
fixtures=$(mktemp -d "${TMPDIR:-/tmp}/gp-diagnostics-tests.XXXXXXXX")
|
||||
trap 'rm -rf "$fixtures"' 0
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM HUP
|
||||
mkdir "$fixtures/bin"
|
||||
for tool in sh awk tr cat chmod mktemp rm ps sleep; do
|
||||
ln -s "$(command -v "$tool")" "$fixtures/bin/$tool"
|
||||
done
|
||||
cat > "$fixtures/bin/uname" <<'MOCK'
|
||||
#!/bin/sh
|
||||
case "$1" in
|
||||
-s) printf '%s\n' "$TEST_OS" ;;
|
||||
-m) printf '%s\n' fixture-architecture ;;
|
||||
-r)
|
||||
case "${TEST_PROBE:-}" in
|
||||
timeout)
|
||||
sh -c 'trap "" TERM; echo $$ > "$TEST_CHILD_PID"; while :; do sleep 1; done' &
|
||||
wait ;;
|
||||
flood) awk 'BEGIN {while (1) print "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}' ;;
|
||||
*) printf '%s\n' fixture-kernel ;;
|
||||
esac ;;
|
||||
esac
|
||||
MOCK
|
||||
cat > "$fixtures/bin/id" <<'MOCK'
|
||||
#!/bin/sh
|
||||
printf '%s\n' 1000
|
||||
MOCK
|
||||
cat > "$fixtures/bin/gpclient" <<'MOCK'
|
||||
#!/bin/sh
|
||||
[ "$1" = --version ] || exit 2
|
||||
printf '%s\n' 'gpclient 2.6.5'
|
||||
MOCK
|
||||
cat > "$fixtures/bin/gpauth" <<'MOCK'
|
||||
#!/bin/sh
|
||||
[ "$1" = --version ] || exit 2
|
||||
printf '%s\n' 'gpauth 2.6.5'
|
||||
MOCK
|
||||
cat > "$fixtures/bin/gpgui" <<'MOCK'
|
||||
#!/bin/sh
|
||||
printf '%s\n' 'GUI WAS LAUNCHED' > "$TEST_GUI_MARKER"
|
||||
exit 1
|
||||
MOCK
|
||||
cat > "$fixtures/bin/lspci" <<'MOCK'
|
||||
#!/bin/sh
|
||||
cat <<'DATA'
|
||||
00:00.0 Host bridge: OMIT-BRIDGE
|
||||
00:01.0 VGA compatible controller: Fixture GPU
|
||||
Kernel driver in use: fixture-driver
|
||||
00:02.0 Network controller: OMIT-NETWORK
|
||||
Kernel driver in use: OMIT-NETWORK-DRIVER
|
||||
DATA
|
||||
MOCK
|
||||
cat > "$fixtures/bin/pciconf" <<'MOCK'
|
||||
#!/bin/sh
|
||||
cat <<'DATA'
|
||||
vgapci0@pci0:0:1:0: class=0x030000
|
||||
device = 'BSD Fixture GPU'
|
||||
nic0@pci0:0:2:0: class=0x020000
|
||||
device = 'OMIT-NETWORK'
|
||||
DATA
|
||||
MOCK
|
||||
cat > "$fixtures/bin/pcidump" <<'MOCK'
|
||||
#!/bin/sh
|
||||
printf '%s\n' '0:1:0: VGA Fixture GPU' '0:2:0: OMIT-NETWORK'
|
||||
MOCK
|
||||
cat > "$fixtures/bin/system_profiler" <<'MOCK'
|
||||
#!/bin/sh
|
||||
printf '%s\n' ' Chipset Model: Fixture Mac GPU' ' Serial Number: OMIT-SERIAL'
|
||||
MOCK
|
||||
cat > "$fixtures/bin/sw_vers" <<'MOCK'
|
||||
#!/bin/sh
|
||||
printf '%s\n' fixture-macos-version
|
||||
MOCK
|
||||
cat > "$fixtures/bin/sysctl" <<'MOCK'
|
||||
#!/bin/sh
|
||||
printf '%s\n' kvm
|
||||
MOCK
|
||||
cat > "$fixtures/bin/systemd-detect-virt" <<'MOCK'
|
||||
#!/bin/sh
|
||||
if [ "${TEST_PROBE:-}" = baremetal ]; then printf '%s\n' none; exit 1; fi
|
||||
printf '%s\n' kvm
|
||||
MOCK
|
||||
cat > "$fixtures/bin/pkg" <<'MOCK'
|
||||
#!/bin/sh
|
||||
[ "$1" = query ] && [ "$2" = -a ] || exit 2
|
||||
printf '%s\n' 'webkit2-gtk_41 2.52.6' 'gtk3 3.24.52' 'mesa-dri 26.2.4' 'hyprland 0.56.2' 'plasma6-plasma-workspace 6.4.4' 'private-package 1.0'
|
||||
MOCK
|
||||
cat > "$fixtures/bin/pkg_info" <<'MOCK'
|
||||
#!/bin/sh
|
||||
[ "$1" = -a ] || exit 2
|
||||
printf '%s\n' 'webkitgtk41-2.52.6 WebKitGTK browser engine' 'gtk+3-3.24.52 GTK3 toolkit' 'sway-1.11 Wayland compositor' 'private-package-1.0 Do not collect'
|
||||
MOCK
|
||||
chmod +x "$fixtures/bin/"*
|
||||
run() {
|
||||
env PATH="$fixtures/bin" HOME="$fixtures/home[regex]" TMPDIR="$fixtures" \
|
||||
TEST_OS="$1" TEST_PROBE="${2:-}" TEST_CHILD_PID="$fixtures/child.pid" \
|
||||
TEST_GUI_MARKER="$fixtures/gui-launched" \
|
||||
PRIVATE_SECRET=OMIT-SECRET DISPLAY=OMIT-DISPLAY WAYLAND_DISPLAY=OMIT-SOCKET \
|
||||
DBUS_SESSION_BUS_ADDRESS=OMIT-DBUS SSH_CONNECTION=OMIT-SSH \
|
||||
XDG_CURRENT_DESKTOP='KDE' DESKTOP_SESSION="$fixtures/home[regex]/desktop" \
|
||||
sh "$collector" --client-version embedded-version --client-path "$fixtures/home[regex]/gpclient" > "$fixtures/report"
|
||||
}
|
||||
assert_contains() {
|
||||
awk -v text="$1" 'index($0,text) {found=1} END {exit !found}' "$fixtures/report" || { printf 'Missing: %s\n' "$1" >&2; cat "$fixtures/report" >&2; exit 1; }
|
||||
}
|
||||
for os in Linux FreeBSD OpenBSD Darwin; do
|
||||
run "$os"
|
||||
assert_contains "os: ok: $os"
|
||||
assert_contains 'gpclient_version: ok: embedded-version'
|
||||
assert_contains 'gpclient_path: ok: ~/gpclient'
|
||||
assert_contains 'env.DESKTOP_SESSION: ok: ~/desktop'
|
||||
assert_contains 'env.XDG_CURRENT_DESKTOP: ok: KDE'
|
||||
assert_contains 'ssh_session: ok: yes'
|
||||
awk 'index($0,"OMIT-") {exit 1} END {if (NR != 28) exit 1}' "$fixtures/report"
|
||||
[ ! -e "$fixtures/gui-launched" ]
|
||||
awk 'index($0,"private-package") {exit 1}' "$fixtures/report"
|
||||
case "$os" in
|
||||
Linux) assert_contains 'Fixture GPU'; assert_contains 'fixture-driver' ;;
|
||||
FreeBSD) assert_contains 'BSD Fixture GPU'; assert_contains 'graphics_packages: ok: webkit2-gtk_41 2.52.6'; assert_contains 'desktop_version: ok: hyprland 0.56.2 plasma6-plasma-workspace 6.4.4' ;;
|
||||
OpenBSD) assert_contains 'VGA Fixture GPU'; assert_contains 'graphics_packages: ok: webkitgtk41-2.52.6'; assert_contains 'desktop_version: ok: sway-1.11' ;;
|
||||
Darwin) assert_contains 'Fixture Mac GPU'; assert_contains 'display_protocol: not_applicable:' ;;
|
||||
esac
|
||||
printf 'PASS: %s fixture selection and privacy\n' "$os"
|
||||
done
|
||||
env PATH="$fixtures/bin" TEST_OS=Darwin TEST_GUI_MARKER="$fixtures/gui-launched" \
|
||||
sh "$collector" --client-version fixture --gui-path "$fixtures/bin/gpgui" > "$fixtures/report"
|
||||
assert_contains "gpgui_path: ok: $fixtures/bin/gpgui"
|
||||
assert_contains 'gpgui_version: unavailable:'
|
||||
[ ! -e "$fixtures/gui-launched" ]
|
||||
printf '%s\n' 'PASS: nonbundle GUI path never borrows another installed app version'
|
||||
# Successful probes must cancel their watchdog before doing any process-tree
|
||||
# traversal. A slow snapshot used to let a finished probe become timed_out.
|
||||
mv "$fixtures/bin/ps" "$fixtures/real-ps"
|
||||
cat > "$fixtures/bin/ps" <<'MOCK'
|
||||
#!/bin/sh
|
||||
sleep 4
|
||||
exit 1
|
||||
MOCK
|
||||
chmod +x "$fixtures/bin/ps"
|
||||
run Linux
|
||||
assert_contains 'os: ok: Linux'
|
||||
assert_contains 'kernel: ok: fixture-kernel'
|
||||
assert_contains 'graphics: ok:'
|
||||
rm "$fixtures/bin/ps"
|
||||
mv "$fixtures/real-ps" "$fixtures/bin/ps"
|
||||
printf '%s\n' 'PASS: successful watchdog cancellation does not wait for process snapshots'
|
||||
run Linux baremetal
|
||||
assert_contains 'virtualization: ok: none'
|
||||
printf '%s\n' 'PASS: bare-metal virtualization status'
|
||||
long_value=$(awk 'BEGIN {for (i=0;i<700;i++) printf "x"; printf "\nsecond\tline"}')
|
||||
env PATH="$fixtures/bin" TEST_OS=Linux XDG_CURRENT_DESKTOP="$long_value" \
|
||||
sh "$collector" --client-version fixture > "$fixtures/report"
|
||||
awk 'index($0,"env.XDG_CURRENT_DESKTOP: ok: ")==1 {if (length($0)-length("env.XDG_CURRENT_DESKTOP: ok: ")>500) exit 1; found=1} END {if (NR!=28 || !found) exit 1}' "$fixtures/report"
|
||||
printf '%s\n' 'PASS: control flattening and value cap'
|
||||
# No internal version supplied: old installations use their safe --version switch.
|
||||
env PATH="$fixtures/bin" TEST_OS=Linux sh "$collector" > "$fixtures/report"
|
||||
assert_contains 'gpclient_version: ok: gpclient 2.6.5'
|
||||
printf '%s\n' 'PASS: standalone version discovery'
|
||||
run Linux timeout
|
||||
assert_contains 'kernel: timed_out:'
|
||||
child=$(cat "$fixtures/child.pid")
|
||||
# A reaped-or-zombie descendant is no longer running; some init implementations
|
||||
# do not promptly reap an orphan after its parent is killed.
|
||||
state=$(ps -p "$child" -o stat= 2>/dev/null || :)
|
||||
case "$state" in ''|Z*) ;; *) printf 'Descendant still running: %s\n' "$state" >&2; exit 1 ;; esac
|
||||
printf '%s\n' 'PASS: timeout and descendant termination'
|
||||
run Linux flood
|
||||
assert_contains 'kernel: failed:'
|
||||
[ "$(wc -c < "$fixtures/report")" -lt 65536 ]
|
||||
printf '%s\n' 'PASS: output flood is bounded'
|
||||
rm -f "$fixtures/child.pid"
|
||||
env PATH="$fixtures/bin" TEST_OS=Linux TEST_PROBE=timeout TEST_CHILD_PID="$fixtures/child.pid" \
|
||||
sh "$collector" > "$fixtures/interrupted" 2>/dev/null &
|
||||
collector_pid=$!
|
||||
for attempt in 1 2 3 4 5; do [ ! -f "$fixtures/child.pid" ] || break; sleep 1; done
|
||||
[ -f "$fixtures/child.pid" ]
|
||||
kill -TERM "$collector_pid"
|
||||
if wait "$collector_pid"; then exit 1; fi
|
||||
child=$(cat "$fixtures/child.pid")
|
||||
state=$(ps -p "$child" -o stat= 2>/dev/null || :)
|
||||
case "$state" in ''|Z*) ;; *) printf 'Interrupted descendant still running: %s\n' "$state" >&2; exit 1 ;; esac
|
||||
printf '%s\n' 'PASS: interruption terminates descendants'
|
||||
mv "$fixtures/bin/gpauth" "$fixtures/gpauth"
|
||||
run Linux
|
||||
assert_contains 'gpauth_version: unavailable:'
|
||||
mv "$fixtures/gpauth" "$fixtures/bin/gpauth"
|
||||
printf '%s\n' 'PASS: missing optional helper'
|
||||
|
||||
env PATH="$fixtures/bin" TEST_OS=Linux sh "$collector" --output "$fixtures/saved" >/dev/null
|
||||
cp "$fixtures/saved" "$fixtures/original"
|
||||
if env PATH="$fixtures/bin" TEST_OS=Linux sh "$collector" --output "$fixtures/saved" >/dev/null 2>&1; then exit 1; fi
|
||||
cmp "$fixtures/saved" "$fixtures/original"
|
||||
sh "$collector" --help > "$fixtures/help"
|
||||
[ -s "$fixtures/help" ]
|
||||
if sh "$collector" --unknown >/dev/null 2>&1; then exit 1; fi
|
||||
printf '%s\n' 'PASS: output refuses overwrite, help, argument validation'
|
||||
@@ -0,0 +1,72 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).parents[1] / "verify-docker-publication.sh"
|
||||
AMD64 = "sha256:" + "a" * 64
|
||||
ARM64 = "sha256:" + "b" * 64
|
||||
INDEX = "sha256:" + "c" * 64
|
||||
|
||||
|
||||
def manifest(digest, architecture):
|
||||
platform_os = "unknown" if architecture == "unknown" else "linux"
|
||||
return {"digest": digest, "platform": {"os": platform_os, "architecture": architecture}}
|
||||
|
||||
|
||||
class DockerPublicationTests(unittest.TestCase):
|
||||
def run_verifier(self, images, source_index=True, selection="all"):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
digests = root / "digests"
|
||||
digests.mkdir()
|
||||
(digests / (INDEX if source_index else AMD64)[7:]).touch()
|
||||
if selection == "all":
|
||||
(digests / ARM64[7:]).touch()
|
||||
responses = {
|
||||
"example/image:3.0.1": {"manifests": images},
|
||||
"example/image@" + INDEX: {"manifests": [manifest(AMD64, "amd64"), manifest("sha256:attestation", "unknown")]},
|
||||
"example/image@" + AMD64: {"config": {}},
|
||||
"example/image@" + ARM64: {"config": {}},
|
||||
}
|
||||
(root / "responses.json").write_text(json.dumps(responses))
|
||||
docker = root / "docker"
|
||||
docker.write_text("#!/usr/bin/env python3\nimport json, os, sys\n"
|
||||
"print(json.dumps(json.load(open(os.environ['RESPONSES']))[sys.argv[4]]))\n")
|
||||
docker.chmod(0o755)
|
||||
sleep = root / "sleep"
|
||||
sleep.write_text("#!/bin/sh\nexit 0\n")
|
||||
sleep.chmod(0o755)
|
||||
env = {**os.environ, "PATH": str(root) + os.pathsep + os.environ["PATH"],
|
||||
"RESPONSES": str(root / "responses.json")}
|
||||
return subprocess.run(["bash", str(SCRIPT), "example/image:3.0.1", str(digests), selection],
|
||||
env=env, capture_output=True, text=True)
|
||||
|
||||
def test_attested_sources_match_the_published_platform_digests(self):
|
||||
result = self.run_verifier([manifest(AMD64, "amd64"), manifest(ARM64, "arm64"),
|
||||
manifest("sha256:attestation", "unknown")])
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_missing_architecture_cannot_pass(self):
|
||||
result = self.run_verifier([manifest(AMD64, "amd64")])
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("did not match", result.stderr)
|
||||
|
||||
def test_another_build_of_same_platforms_cannot_pass(self):
|
||||
result = self.run_verifier([manifest("sha256:" + "d" * 64, "amd64"), manifest(ARM64, "arm64")])
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
|
||||
def test_unselected_platform_cannot_pass(self):
|
||||
result = self.run_verifier([manifest(AMD64, "amd64"), manifest(ARM64, "arm64"),
|
||||
manifest("sha256:extra", "riscv64")])
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
|
||||
def test_selected_single_architecture_is_supported(self):
|
||||
result = self.run_verifier([manifest(AMD64, "amd64")], source_index=False, selection="x86_64")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,120 @@
|
||||
import argparse
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
spec = importlib.util.spec_from_file_location("selector", Path(__file__).parents[1] / "select-publication-targets.py")
|
||||
selector = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(selector)
|
||||
|
||||
|
||||
class SelectionTests(unittest.TestCase):
|
||||
def test_unknown_and_duplicate_targets_fail(self):
|
||||
for values in (["typo"], ["fedora-44", "fedora-44"]):
|
||||
with self.assertRaises(ValueError):
|
||||
selector.selection(values, {"fedora-44", "fedora-45"})
|
||||
|
||||
def test_obs_metadata_uses_authenticated_put_without_authenticating_public_reads(self):
|
||||
response = MagicMock()
|
||||
response.__enter__.return_value.read.return_value = b"ok"
|
||||
with patch.object(selector, "urlopen", return_value=response) as opening, \
|
||||
patch.dict(selector.os.environ, {"OBS_USERNAME": "test", "OBS_PASSWORD": "test"}):
|
||||
selector.request("https://api.opensuse.org/source/project/package/_meta", b"<package/>")
|
||||
upload = opening.call_args.args[0]
|
||||
self.assertEqual(upload.get_method(), "PUT")
|
||||
self.assertIsNotNone(upload.get_header("Authorization"))
|
||||
selector.request("https://api.opensuse.org/public/source/project/package/_meta")
|
||||
public = opening.call_args.args[0]
|
||||
self.assertEqual(public.get_method(), "GET")
|
||||
self.assertIsNone(public.get_header("Authorization"))
|
||||
|
||||
def test_copr_expands_selected_distro_to_all_its_configured_architectures(self):
|
||||
args = argparse.Namespace(owner="yuezk", project="globalprotect-openconnect",
|
||||
distros=["fedora-44"], build_id=None)
|
||||
response = json.dumps({"chroot_repos": {"fedora-44-aarch64": "url", "fedora-44-x86_64": "url",
|
||||
"fedora-45-x86_64": "url"}}).encode()
|
||||
with patch.object(selector, "request", return_value=response):
|
||||
self.assertEqual(selector.copr(args), ["fedora-44-aarch64", "fedora-44-x86_64"])
|
||||
args.distros = ["fedora-typo"]
|
||||
with self.assertRaisesRegex(ValueError, "Unknown targets"):
|
||||
selector.copr(args)
|
||||
|
||||
def test_copr_recovery_uses_original_build_targets_even_if_project_changed(self):
|
||||
args = argparse.Namespace(owner="yuezk", project="globalprotect-openconnect", distros=[], build_id=42)
|
||||
response = json.dumps({"ownername": args.owner, "projectname": args.project,
|
||||
"chroots": ["fedora-43-x86_64"]}).encode()
|
||||
with patch.object(selector, "request", return_value=response) as request:
|
||||
self.assertEqual(selector.copr(args), ["fedora-43-x86_64"])
|
||||
self.assertIn("/build/42", request.call_args.args[0])
|
||||
|
||||
|
||||
class OBSSelectionTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.directory.cleanup)
|
||||
self.args = argparse.Namespace(project="home:yuezk", package="globalprotect-openconnect",
|
||||
repositories=["16.0"], verify_only=False,
|
||||
output=Path(self.directory.name) / "targets.json")
|
||||
self.targets = ["16.0/aarch64", "16.0/x86_64"]
|
||||
self.project = b'''<project><repository name="16.0"><arch>x86_64</arch><arch>aarch64</arch></repository>
|
||||
<repository name="15.6"><arch>x86_64</arch><arch>aarch64</arch></repository></project>'''
|
||||
self.package = b'''<package><title>Keep me</title><build><disable repository="old"/></build>
|
||||
<publish><disable repository="old"/><disable repository="16.0" arch="x86_64"/></publish>
|
||||
<useforbuild><disable arch="armv7l"/></useforbuild></package>'''
|
||||
|
||||
def test_metadata_changes_build_allowlist_but_keeps_other_publication_flags(self):
|
||||
metadata = selector.obs_metadata(ET.fromstring(self.package), self.targets)
|
||||
self.assertEqual(metadata.findtext("title"), "Keep me")
|
||||
self.assertIsNotNone(metadata.find("build/disable"))
|
||||
self.assertEqual([flag.attrib for flag in metadata.findall("build/enable")],
|
||||
[{"repository": "16.0", "arch": "aarch64"},
|
||||
{"repository": "16.0", "arch": "x86_64"}])
|
||||
self.assertEqual(metadata.find("publish/disable").attrib, {"repository": "old"})
|
||||
self.assertEqual(len(metadata.findall("publish/disable")), 1)
|
||||
self.assertEqual(metadata.find("useforbuild/disable").get("arch"), "armv7l")
|
||||
|
||||
def test_selection_is_applied_before_source_can_be_uploaded(self):
|
||||
before = {"16.0/x86_64": "succeeded", "16.0/aarch64": "succeeded",
|
||||
"15.6/x86_64": "succeeded", "15.6/aarch64": "succeeded"}
|
||||
after = {"16.0/x86_64": "succeeded", "16.0/aarch64": "succeeded",
|
||||
"15.6/x86_64": "disabled", "15.6/aarch64": "disabled"}
|
||||
with patch.object(selector, "request", side_effect=[self.project, self.package, b"ok"]) as request, \
|
||||
patch.object(selector, "obs_results", side_effect=[before, after]):
|
||||
selector.obs(self.args)
|
||||
self.assertEqual(json.loads(self.args.output.read_text()), self.targets)
|
||||
self.assertIn("/source/home:yuezk/globalprotect-openconnect/_meta", request.call_args.args[0])
|
||||
uploaded = ET.fromstring(request.call_args.args[1])
|
||||
self.assertEqual({flag.get("arch") for flag in uploaded.findall("build/enable")}, {"x86_64", "aarch64"})
|
||||
|
||||
def test_busy_unselected_target_prevents_mutation(self):
|
||||
states = {"16.0/x86_64": "succeeded", "16.0/aarch64": "succeeded", "15.6/aarch64": "building"}
|
||||
with patch.object(selector, "request", return_value=self.project) as request, \
|
||||
patch.object(selector, "obs_results", return_value=states):
|
||||
with self.assertRaisesRegex(ValueError, "still active"):
|
||||
selector.obs(self.args)
|
||||
self.assertEqual(request.call_count, 1)
|
||||
|
||||
def test_verify_only_does_not_mutate_to_hide_an_unselected_build(self):
|
||||
self.args.verify_only = True
|
||||
states = {"16.0/x86_64": "succeeded", "16.0/aarch64": "succeeded", "15.6/aarch64": "succeeded"}
|
||||
with patch.object(selector, "request", return_value=self.project) as request, \
|
||||
patch.object(selector, "obs_results", return_value=states):
|
||||
with self.assertRaisesRegex(ValueError, "differ"):
|
||||
selector.obs(self.args)
|
||||
self.assertEqual(request.call_count, 1)
|
||||
|
||||
def test_empty_selection_preserves_current_flags(self):
|
||||
self.args.repositories = []
|
||||
states = {"16.0/x86_64": "succeeded", "16.0/aarch64": "disabled"}
|
||||
with patch.object(selector, "request", return_value=self.project) as request, \
|
||||
patch.object(selector, "obs_results", return_value=states):
|
||||
self.assertEqual(selector.obs(self.args), ["16.0/x86_64"])
|
||||
self.assertEqual(request.call_count, 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,176 @@
|
||||
import argparse
|
||||
import gzip
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from urllib.error import HTTPError
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
spec = importlib.util.spec_from_file_location("publication", Path(__file__).parents[1] / "wait-for-publication.py")
|
||||
publication = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(publication)
|
||||
|
||||
|
||||
def arguments(**values):
|
||||
return argparse.Namespace(owner="yuezk", project="globalprotect-openconnect",
|
||||
package="globalprotect-openconnect", version="3.0.1", revision="1", **values)
|
||||
|
||||
|
||||
class RepositoryTests(unittest.TestCase):
|
||||
def test_debian_index_requires_exact_version_and_architecture(self):
|
||||
content = b"Package: globalprotect-openconnect\nVersion: 3.0.1-ppa1\nArchitecture: arm64\n\n"
|
||||
self.assertTrue(publication.deb_present(content, "globalprotect-openconnect", "3.0.1-ppa1", "arm64"))
|
||||
self.assertFalse(publication.deb_present(content, "globalprotect-openconnect", "3.0.1", "arm64"))
|
||||
self.assertFalse(publication.deb_present(content, "globalprotect-openconnect", "3.0.1-ppa1", "amd64"))
|
||||
|
||||
def test_rpm_metadata_is_verified_before_parsing(self):
|
||||
primary = gzip.compress(b'<metadata xmlns="http://linux.duke.edu/metadata/common"/>')
|
||||
digest = hashlib.sha256(primary).hexdigest()
|
||||
repomd = ET.fromstring(f'''<repomd xmlns="http://linux.duke.edu/metadata/repo">
|
||||
<data type="primary"><location href="repodata/primary.xml.gz"/>
|
||||
<checksum type="sha256">{digest}</checksum></data></repomd>''')
|
||||
with patch.object(publication, "xml", return_value=repomd), patch.object(publication, "fetch", return_value=primary):
|
||||
self.assertEqual(publication.rpm_packages("https://repo").tag, "{http://linux.duke.edu/metadata/common}metadata")
|
||||
with patch.object(publication, "xml", return_value=repomd), patch.object(publication, "fetch", return_value=b"corrupt"):
|
||||
with self.assertRaises(publication.Pending):
|
||||
publication.rpm_packages("https://repo")
|
||||
|
||||
def test_copr_same_version_from_another_build_does_not_pass(self):
|
||||
primary = ET.fromstring('''<metadata xmlns="http://linux.duke.edu/metadata/common"><package>
|
||||
<name>globalprotect-openconnect</name><arch>x86_64</arch><version ver="3.0.1" rel="1.fc44"/>
|
||||
<location href="011106217-globalprotect-openconnect/package.rpm"/></package></metadata>''')
|
||||
with patch.object(publication, "rpm_packages", return_value=primary):
|
||||
params = ("https://repo", "globalprotect-openconnect", "3.0.1", "x86_64", lambda release: True)
|
||||
self.assertTrue(publication.rpm_present(*params, build_id=11106217))
|
||||
self.assertFalse(publication.rpm_present(*params, build_id=11106218))
|
||||
|
||||
|
||||
class LaunchpadTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.checker = publication.PPA(arguments(series="noble", architectures=["amd64", "arm64"]))
|
||||
self.checker.source = "https://api/sourcepub/1"
|
||||
self.builds = [{"arch_tag": arch, "buildstate": "Successfully built", "web_link": f"https://build/{arch}"}
|
||||
for arch in ("amd64", "arm64")]
|
||||
|
||||
def test_green_builds_do_not_mean_repository_is_published(self):
|
||||
with patch.object(publication, "api", return_value={"status": "Published"}), \
|
||||
patch.object(publication, "collection", return_value=self.builds), \
|
||||
patch.object(publication, "fetch", return_value=gzip.compress(b"")):
|
||||
with self.assertRaisesRegex(publication.Pending, "Waiting for 3.0.1"):
|
||||
self.checker.check()
|
||||
|
||||
def test_missing_architecture_does_not_pass(self):
|
||||
self.builds = self.builds[:1]
|
||||
with patch.object(publication, "api", return_value={"status": "Published"}), \
|
||||
patch.object(publication, "collection", return_value=self.builds), \
|
||||
patch.object(publication, "deb_present", return_value=True), \
|
||||
patch.object(publication, "fetch", return_value=gzip.compress(b"")):
|
||||
with self.assertRaisesRegex(publication.Pending, "arm64"):
|
||||
self.checker.check()
|
||||
|
||||
def test_failed_build_reports_external_url(self):
|
||||
self.builds[0]["buildstate"] = "Dependency wait"
|
||||
with patch.object(publication, "api", return_value={"status": "Published"}), \
|
||||
patch.object(publication, "collection", return_value=self.builds):
|
||||
with self.assertRaisesRegex(publication.Failed, "https://build/amd64"):
|
||||
self.checker.check()
|
||||
|
||||
|
||||
class OBSTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.directory.cleanup)
|
||||
files = Path(self.directory.name) / "files"
|
||||
files.mkdir()
|
||||
(files / "package.spec").write_bytes(b"spec")
|
||||
args = arguments(files=files)
|
||||
args.project = "home:yuezk"
|
||||
self.checker = publication.OBS(args)
|
||||
digest = hashlib.md5(b"spec").hexdigest()
|
||||
self.source = f'<directory rev="74" srcmd5="new"><entry name="package.spec" md5="{digest}"/></directory>'
|
||||
self.results = '''<resultlist><result repository="16.0" arch="x86_64" state="published">
|
||||
<status code="succeeded"/></result><result repository="disabled" arch="x86_64">
|
||||
<status code="disabled"/></result></resultlist>'''
|
||||
|
||||
def test_previous_green_build_history_is_not_current_publication(self):
|
||||
responses = [self.source, self.results, '<buildinfo><srcmd5>new</srcmd5></buildinfo>',
|
||||
'<buildhistory><entry srcmd5="old" versrel="3.0.1-1"/></buildhistory>']
|
||||
with patch.object(publication, "xml", side_effect=[ET.fromstring(value) for value in responses]):
|
||||
with self.assertRaisesRegex(publication.Pending, "build history"):
|
||||
self.checker.check()
|
||||
|
||||
def test_current_revision_with_published_metadata_passes(self):
|
||||
responses = [self.source, self.results, '<buildinfo><srcmd5>new</srcmd5></buildinfo>',
|
||||
'<buildhistory><entry srcmd5="new" versrel="3.0.1-1"/></buildhistory>']
|
||||
with patch.object(publication, "xml", side_effect=[ET.fromstring(value) for value in responses]), \
|
||||
patch.object(publication, "rpm_present", return_value=True):
|
||||
self.assertIn("1 targets", self.checker.check())
|
||||
|
||||
def test_source_changed_during_wait_fails(self):
|
||||
self.checker.source = "old"
|
||||
with patch.object(publication, "xml", return_value=ET.fromstring(self.source)):
|
||||
with self.assertRaisesRegex(publication.Failed, "source changed"):
|
||||
self.checker.check()
|
||||
|
||||
def test_no_enabled_targets_cannot_pass(self):
|
||||
with patch.object(publication, "xml", side_effect=[ET.fromstring(self.source), ET.fromstring("<resultlist/>")]):
|
||||
with self.assertRaisesRegex(publication.Failed, "no enabled"):
|
||||
self.checker.check()
|
||||
|
||||
def test_enabled_target_outside_selection_fails(self):
|
||||
path = Path(self.directory.name) / "targets.json"
|
||||
path.write_text(json.dumps(["16.0/aarch64"]))
|
||||
self.checker.args.targets_file = path
|
||||
self.checker.targets = {("16.0", "aarch64")}
|
||||
with patch.object(publication, "xml", side_effect=[ET.fromstring(self.source), ET.fromstring(self.results)]):
|
||||
with self.assertRaisesRegex(publication.Failed, "unselected targets"):
|
||||
self.checker.check()
|
||||
|
||||
def test_selected_target_disabled_fails(self):
|
||||
self.checker.targets = {("disabled", "x86_64")}
|
||||
with patch.object(publication, "xml", side_effect=[ET.fromstring(self.source), ET.fromstring(self.results)]):
|
||||
with self.assertRaisesRegex(publication.Failed, "selected target.*disabled"):
|
||||
self.checker.check()
|
||||
|
||||
|
||||
class CoprTests(unittest.TestCase):
|
||||
def test_unselected_chroot_cannot_be_hidden_by_verification(self):
|
||||
checker = publication.Copr(arguments(build_id=42, chroots=["fedora-44-x86_64"]))
|
||||
build = {"ownername": "yuezk", "projectname": "globalprotect-openconnect",
|
||||
"chroots": ["fedora-44-x86_64", "fedora-44-aarch64"]}
|
||||
with patch.object(publication, "api", return_value=build):
|
||||
with self.assertRaisesRegex(publication.Failed, "targets differ"):
|
||||
checker.check()
|
||||
|
||||
def test_build_from_another_project_fails(self):
|
||||
checker = publication.Copr(arguments(build_id=42))
|
||||
with patch.object(publication, "api", return_value={"ownername": "other", "projectname": "other"}):
|
||||
with self.assertRaisesRegex(publication.Failed, "another project"):
|
||||
checker.check()
|
||||
|
||||
def test_failed_build_reports_id_and_url(self):
|
||||
checker = publication.Copr(arguments(build_id=42))
|
||||
with patch.object(publication, "api", return_value={"ownername": "yuezk", "projectname": "globalprotect-openconnect", "state": "failed"}):
|
||||
with self.assertRaisesRegex(publication.Failed, "/build/42/"):
|
||||
checker.check()
|
||||
|
||||
|
||||
class WaitTests(unittest.TestCase):
|
||||
def test_transient_error_then_publication(self):
|
||||
with patch.object(publication.time, "sleep"), patch.object(publication.time, "monotonic", return_value=0):
|
||||
callback = unittest.mock.Mock(side_effect=[HTTPError("https://api", 503, "", {}, None), "published"])
|
||||
self.assertEqual(publication.wait(callback, 60, 5), "published")
|
||||
|
||||
def test_timeout_reports_last_external_status(self):
|
||||
with patch.object(publication.time, "monotonic", side_effect=[0, 61]):
|
||||
callback = unittest.mock.Mock(side_effect=publication.Pending("build 42 is running"))
|
||||
with self.assertRaisesRegex(publication.Failed, "build 42 is running"):
|
||||
publication.wait(callback, 60, 5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Usage: verify-docker-publication.sh <image:tag> <digest-directory> <all|x86_64|arm64>
|
||||
set -euo pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
image_ref=${1:?Image reference is required}
|
||||
digest_directory=${2:?Digest directory is required}
|
||||
architecture=${3:?Architecture selection is required}
|
||||
image=${image_ref%:*}
|
||||
digests=("$digest_directory"/*)
|
||||
case "$architecture" in
|
||||
all) expected='["linux/amd64","linux/arm64"]' ;;
|
||||
x86_64) expected='["linux/amd64"]' ;;
|
||||
arm64) expected='["linux/arm64"]' ;;
|
||||
*) echo "Invalid architecture selection: $architecture" >&2; exit 1 ;;
|
||||
esac
|
||||
[[ ${#digests[@]} -eq $(jq length <<<"$expected") ]]
|
||||
|
||||
# Buildx can return an OCI index per architecture when provenance is enabled.
|
||||
# Compare the contained image digests, excluding attestation manifests.
|
||||
source_digests=()
|
||||
for file in "${digests[@]}"; do
|
||||
digest="$(basename "$file")"
|
||||
[[ "$digest" =~ ^[0-9a-f]{64}$ ]]
|
||||
source="$(docker buildx imagetools inspect "$image@sha256:$digest" --raw)"
|
||||
if jq -e '.manifests' <<<"$source" >/dev/null; then
|
||||
images="$(jq -r '.manifests[] | select(.platform.os == "linux" and
|
||||
(.platform.architecture == "amd64" or .platform.architecture == "arm64")) | .digest' <<<"$source")"
|
||||
[[ -n "$images" ]]
|
||||
while IFS= read -r image_digest; do
|
||||
source_digests+=("$image_digest")
|
||||
done <<< "$images"
|
||||
else
|
||||
source_digests+=("sha256:$digest")
|
||||
fi
|
||||
done
|
||||
sources="$(printf '%s\n' "${source_digests[@]}" | jq -R . | jq -s 'sort | unique')"
|
||||
|
||||
for _ in {1..20}; do
|
||||
if manifest="$(docker buildx imagetools inspect "$image_ref" --raw)" &&
|
||||
jq -e --argjson expected "$expected" --argjson sources "$sources" '
|
||||
[.manifests[] | select(.platform.os == "linux")] as $images |
|
||||
([$images[] | .platform.os + "/" + .platform.architecture] | sort) == ($expected | sort) and
|
||||
([$images[].digest] | sort | unique) == $sources
|
||||
' <<<"$manifest" >/dev/null; then
|
||||
echo "Verified $image_ref: $expected"
|
||||
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
|
||||
echo "Verified $image_ref: $expected" >> "$GITHUB_STEP_SUMMARY"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
sleep 15
|
||||
done
|
||||
echo "Docker publication did not match the expected architectures and build digests: $image_ref" >&2
|
||||
exit 1
|
||||
@@ -0,0 +1,324 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Wait for an exact release to build and appear in public package repositories."""
|
||||
|
||||
import argparse
|
||||
import bz2
|
||||
import gzip
|
||||
import hashlib
|
||||
import json
|
||||
import lzma
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.parse import quote, urlencode, urljoin
|
||||
from urllib.request import Request, urlopen
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
class Pending(Exception):
|
||||
"""The external build or repository is not ready yet."""
|
||||
|
||||
|
||||
class Failed(Exception):
|
||||
"""The requested publication failed or was superseded."""
|
||||
|
||||
|
||||
def fetch(url):
|
||||
request = Request(url, headers={"Cache-Control": "no-cache", "User-Agent": "gp-release-verifier"})
|
||||
with urlopen(request, timeout=30) as response:
|
||||
return response.read()
|
||||
|
||||
|
||||
def api(url, **parameters):
|
||||
if parameters:
|
||||
url += "?" + urlencode(parameters)
|
||||
return json.loads(fetch(url))
|
||||
|
||||
|
||||
def collection(url, **parameters):
|
||||
result = api(url, **parameters)
|
||||
entries = result["entries"]
|
||||
while result.get("next_collection_link"):
|
||||
result = api(result["next_collection_link"])
|
||||
entries.extend(result["entries"])
|
||||
return entries
|
||||
|
||||
|
||||
def xml(url):
|
||||
return ET.fromstring(fetch(url))
|
||||
|
||||
|
||||
def unpack(data, name):
|
||||
if name.endswith(".gz"):
|
||||
return gzip.decompress(data)
|
||||
if name.endswith(".xz"):
|
||||
return lzma.decompress(data)
|
||||
if name.endswith(".bz2"):
|
||||
return bz2.decompress(data)
|
||||
if name.endswith(".zst"):
|
||||
return subprocess.run(["zstd", "--decompress", "--stdout"], input=data,
|
||||
check=True, capture_output=True).stdout
|
||||
return data
|
||||
|
||||
|
||||
def check_digest(data, algorithm, expected):
|
||||
if not expected or hashlib.new(algorithm, data).hexdigest() != expected:
|
||||
raise Pending("Repository metadata checksum does not match yet")
|
||||
|
||||
|
||||
def rpm_packages(base_url):
|
||||
"""Read primary metadata through repomd, verifying its advertised checksum."""
|
||||
namespace = {"repo": "http://linux.duke.edu/metadata/repo"}
|
||||
metadata = xml(base_url + "/repodata/repomd.xml")
|
||||
primary = metadata.find("repo:data[@type='primary']", namespace)
|
||||
if primary is None:
|
||||
raise Pending(f"No primary repository metadata at {base_url}")
|
||||
location = primary.find("repo:location", namespace).get("href")
|
||||
checksum = primary.find("repo:checksum", namespace)
|
||||
content = fetch(urljoin(base_url + "/", location))
|
||||
check_digest(content, checksum.get("type"), checksum.text)
|
||||
return ET.fromstring(unpack(content, location))
|
||||
|
||||
|
||||
def rpm_present(base_url, package, version, arch, release_matches, build_id=None):
|
||||
namespace = {"rpm": "http://linux.duke.edu/metadata/common"}
|
||||
for entry in rpm_packages(base_url).findall("rpm:package", namespace):
|
||||
info = entry.find("rpm:version", namespace)
|
||||
location = entry.find("rpm:location", namespace).get("href")
|
||||
if (entry.findtext("rpm:name", namespaces=namespace) != package or
|
||||
entry.findtext("rpm:arch", namespaces=namespace) != arch or
|
||||
info.get("ver") != version or not release_matches(info.get("rel", ""))):
|
||||
continue
|
||||
if build_id is not None and not re.search(rf"(?:^|/)0*{build_id}-", location):
|
||||
continue
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def deb_present(content, package, version, arch):
|
||||
for paragraph in content.decode().split("\n\n"):
|
||||
fields = dict(line.split(": ", 1) for line in paragraph.splitlines()
|
||||
if ": " in line and not line.startswith(" "))
|
||||
if (fields.get("Package") == package and fields.get("Version") == version and
|
||||
fields.get("Architecture") in {arch, "all"}):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class PPA:
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
self.archive = f"https://api.launchpad.net/1.0/~{args.owner}/+archive/ubuntu/{args.project}"
|
||||
self.series = f"https://api.launchpad.net/1.0/ubuntu/{args.series}"
|
||||
self.source = None
|
||||
|
||||
def check(self):
|
||||
args = self.args
|
||||
if self.source is None:
|
||||
sources = collection(self.archive, **{
|
||||
"ws.op": "getPublishedSources", "source_name": args.package,
|
||||
"exact_match": "true", "version": args.version, "distro_series": self.series,
|
||||
})
|
||||
sources = [source for source in sources if source["source_package_version"] == args.version]
|
||||
if not sources:
|
||||
raise Pending(f"Waiting for source acceptance: {args.series} {args.version}")
|
||||
self.source = sources[0]["self_link"]
|
||||
print(f"Launchpad source: {self.source}", flush=True)
|
||||
source = api(self.source)
|
||||
if source["status"] in {"Deleted", "Superseded", "Obsolete"}:
|
||||
raise Failed(f"Launchpad source is {source['status']}: {self.source}")
|
||||
builds = collection(self.source, **{"ws.op": "getBuilds"})
|
||||
states = {build["arch_tag"]: build for build in builds}
|
||||
for arch in args.architectures:
|
||||
build = states.get(arch)
|
||||
if build is None:
|
||||
raise Pending(f"Waiting for Launchpad {arch} build: {self.source}")
|
||||
state = build["buildstate"]
|
||||
link = build["web_link"]
|
||||
if state in {"Failed to build", "Dependency wait", "Chroot problem", "Build for superseded Source",
|
||||
"Failed to upload", "Cancelled"}:
|
||||
raise Failed(f"Launchpad {arch}: {state}; {link}")
|
||||
if state != "Successfully built":
|
||||
raise Pending(f"Launchpad {arch}: {state}; {link}")
|
||||
for arch in args.architectures:
|
||||
link = states[arch]["web_link"]
|
||||
base = f"https://ppa.launchpadcontent.net/{args.owner}/{args.project}/ubuntu"
|
||||
url = f"{base}/dists/{args.series}/main/binary-{arch}/Packages.gz"
|
||||
if not deb_present(gzip.decompress(fetch(url)), args.package, args.version, arch):
|
||||
raise Pending(f"Waiting for {args.version} in {url}; build {link}")
|
||||
return f"PPA {args.series}: {args.version} published for {', '.join(args.architectures)}; {self.source}"
|
||||
|
||||
|
||||
class OBS:
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
self.source_url = (f"https://api.opensuse.org/public/source/{quote(args.project, safe=':')}/"
|
||||
f"{args.package}")
|
||||
self.source = None
|
||||
self.targets = None
|
||||
if getattr(args, "targets_file", None):
|
||||
targets = json.loads(args.targets_file.read_text())
|
||||
if not targets or any(not isinstance(target, str) or target.count("/") != 1 for target in targets):
|
||||
raise Failed("Invalid OBS target selection file")
|
||||
self.targets = {tuple(target.split("/")) for target in targets}
|
||||
|
||||
def check(self):
|
||||
args = self.args
|
||||
source = xml(self.source_url)
|
||||
if self.source is None:
|
||||
# Bind the waiter to the uploaded files, not whichever revision is currently green.
|
||||
remote = {entry.get("name"): entry.get("md5") for entry in source.findall("entry")}
|
||||
for file in args.files.iterdir():
|
||||
if file.is_file() and remote.get(file.name) != hashlib.md5(file.read_bytes()).hexdigest():
|
||||
raise Failed(f"OBS uploaded source does not match {file.name}: {self.source_url}")
|
||||
self.source = source.get("srcmd5")
|
||||
if not self.source:
|
||||
raise Failed("OBS source has no srcmd5")
|
||||
print(f"OBS revision {source.get('rev')} ({self.source}): {self.source_url}", flush=True)
|
||||
elif source.get("srcmd5") != self.source:
|
||||
raise Failed(f"OBS source changed during verification: {self.source_url}")
|
||||
|
||||
results = xml(f"https://api.opensuse.org/public/build/{quote(args.project, safe=':')}/_result"
|
||||
f"?{urlencode({'package': args.package, 'view': 'status'})}")
|
||||
targets = {(result.get("repository"), result.get("arch")): result for result in results}
|
||||
active = {target for target, result in targets.items()
|
||||
if result.find("status") is not None and
|
||||
result.find("status").get("code") not in {"disabled", "excluded"}}
|
||||
if getattr(args, "targets_file", None) and active - self.targets:
|
||||
raise Failed("OBS enabled unselected targets during publication: " +
|
||||
", ".join(f"{repo}/{arch}" for repo, arch in sorted(active - self.targets)))
|
||||
if self.targets is None:
|
||||
self.targets = active
|
||||
if not self.targets:
|
||||
raise Failed("OBS has no enabled build targets")
|
||||
for repo, arch in sorted(self.targets):
|
||||
result = targets.get((repo, arch))
|
||||
if result is None or result.find("status") is None:
|
||||
raise Failed(f"OBS target disappeared: {repo}/{arch}")
|
||||
state = result.find("status").get("code")
|
||||
build_url = f"https://api.opensuse.org/public/build/{quote(args.project, safe=':')}/{repo}/{arch}/{args.package}"
|
||||
if state in {"disabled", "excluded"}:
|
||||
raise Failed(f"OBS selected target {repo}/{arch}: {state}; {build_url}")
|
||||
info = xml(build_url + "/_buildinfo")
|
||||
if info.findtext("srcmd5") != self.source:
|
||||
raise Pending(f"Waiting for OBS revision {self.source}: {repo}/{arch}; {build_url}")
|
||||
if state in {"failed", "unresolvable", "broken", "disabled", "excluded"}:
|
||||
raise Failed(f"OBS {repo}/{arch}: {state}; {build_url}/_log")
|
||||
if state != "succeeded" or result.get("state") != "published":
|
||||
raise Pending(f"OBS {repo}/{arch}: build {state}, repository {result.get('state')}; {build_url}")
|
||||
history = xml(build_url + "/_history")
|
||||
entries = history.findall("entry")
|
||||
if not entries or entries[-1].get("srcmd5") != self.source:
|
||||
raise Pending(f"Waiting for successful OBS build history: {repo}/{arch}")
|
||||
if entries[-1].get("versrel") != f"{args.version}-{args.revision}":
|
||||
raise Failed(f"OBS built an unexpected version: {repo}/{arch}")
|
||||
project_path = args.project.replace(":", ":/")
|
||||
public = f"https://download.opensuse.org/repositories/{project_path}/{repo}"
|
||||
pattern = rf"(?:[A-Za-z0-9_]+\.)?{re.escape(args.revision)}\.\d+"
|
||||
if not rpm_present(public, args.package, args.version, arch,
|
||||
lambda release: re.fullmatch(pattern, release) is not None):
|
||||
raise Pending(f"Waiting for OBS {args.version}-{args.revision} in {public} ({arch})")
|
||||
return f"OBS revision {self.source}: {len(self.targets)} targets built and published; {self.source_url}"
|
||||
|
||||
|
||||
class Copr:
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
self.build_url = f"https://copr.fedorainfracloud.org/api_3/build/{args.build_id}"
|
||||
|
||||
def check(self):
|
||||
args = self.args
|
||||
build = api(self.build_url)
|
||||
link = f"https://copr.fedorainfracloud.org/coprs/{args.owner}/{args.project}/build/{args.build_id}/"
|
||||
if build["ownername"] != args.owner or build["projectname"] != args.project:
|
||||
raise Failed(f"Copr build belongs to another project: {link}")
|
||||
if getattr(args, "chroots", None) and set(build["chroots"]) != set(args.chroots):
|
||||
raise Failed(f"Copr build targets differ from the requested selection: {link}")
|
||||
if build["state"] in {"failed", "canceled", "cancelled", "skipped"}:
|
||||
raise Failed(f"Copr build {build['state']}: {link}")
|
||||
if build["state"] != "succeeded":
|
||||
raise Pending(f"Copr build {build['state']}: {link}")
|
||||
if build["source_package"]["version"] != f"{args.version}-{args.revision}":
|
||||
raise Failed(f"Copr build version does not match requested release: {link}")
|
||||
if build["source_package"]["name"] != args.package or not build["chroots"]:
|
||||
raise Failed(f"Unexpected Copr package or empty target list: {link}")
|
||||
for chroot in build["chroots"]:
|
||||
status = api(f"https://copr.fedorainfracloud.org/api_3/build-chroot/{args.build_id}/{chroot}")
|
||||
if status["state"] in {"failed", "canceled", "cancelled", "skipped"}:
|
||||
raise Failed(f"Copr {chroot}: {status['state']}; {link}")
|
||||
if status["state"] != "succeeded":
|
||||
raise Pending(f"Copr {chroot}: {status['state']}; {link}")
|
||||
base = build["repo_url"].rstrip("/") + "/" + chroot
|
||||
arch = chroot.rsplit("-", 1)[1]
|
||||
if not rpm_present(base, args.package, args.version, arch,
|
||||
lambda release: release == args.revision or release.startswith(args.revision + "."),
|
||||
build_id=args.build_id):
|
||||
raise Pending(f"Waiting for Copr build {args.build_id} in {base}")
|
||||
return f"Copr build {args.build_id}: {len(build['chroots'])} targets built and published; {link}"
|
||||
|
||||
|
||||
def wait(check, timeout, interval):
|
||||
deadline = time.monotonic() + timeout
|
||||
last_message = None
|
||||
while True:
|
||||
try:
|
||||
return check()
|
||||
except HTTPError as error:
|
||||
if error.code != 404 and error.code != 429 and error.code < 500:
|
||||
raise Failed(f"Publication API returned HTTP {error.code}: {error.url}") from error
|
||||
message = f"Waiting after HTTP {error.code}: {error.url}"
|
||||
except (Pending, URLError, TimeoutError) as error:
|
||||
message = str(error)
|
||||
if message != last_message:
|
||||
print(message, flush=True)
|
||||
last_message = message
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
raise Failed(f"Publication timed out after {timeout}s: {message}")
|
||||
time.sleep(min(interval, remaining))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--timeout", type=int, default=10800, help="Maximum wait in seconds")
|
||||
parser.add_argument("--interval", type=int, default=60, help="Poll interval in seconds")
|
||||
subparsers = parser.add_subparsers(dest="service", required=True)
|
||||
for name, implementation in (("ppa", PPA), ("obs", OBS), ("copr", Copr)):
|
||||
subparser = subparsers.add_parser(name)
|
||||
subparser.set_defaults(implementation=implementation)
|
||||
subparser.add_argument("--owner", default="yuezk")
|
||||
subparser.add_argument("--project", default="home:yuezk" if name == "obs" else "globalprotect-openconnect")
|
||||
subparser.add_argument("--package", default="globalprotect-openconnect")
|
||||
subparser.add_argument("--version", required=True)
|
||||
if name == "ppa":
|
||||
subparser.add_argument("--series", required=True)
|
||||
subparser.add_argument("--architectures", nargs="+", default=["amd64", "arm64"])
|
||||
else:
|
||||
subparser.add_argument("--revision", default="1")
|
||||
if name == "obs":
|
||||
subparser.add_argument("--files", type=Path, required=True)
|
||||
subparser.add_argument("--targets-file", type=Path)
|
||||
if name == "copr":
|
||||
subparser.add_argument("--build-id", type=int, required=True)
|
||||
subparser.add_argument("--chroots", nargs="+")
|
||||
args = parser.parse_args()
|
||||
if args.timeout <= 0 or args.interval <= 0:
|
||||
parser.error("timeout and interval must be positive")
|
||||
try:
|
||||
result = wait(args.implementation(args).check, args.timeout, args.interval)
|
||||
except (Failed, ValueError, OSError, ET.ParseError, subprocess.CalledProcessError) as error:
|
||||
print(str(error), file=sys.stderr)
|
||||
return 1
|
||||
print(result)
|
||||
if summary := os.environ.get("GITHUB_STEP_SUMMARY"):
|
||||
with open(summary, "a", encoding="utf-8") as file:
|
||||
file.write(result + "\n")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user