koji-compose.py: print only compose ID to STDOUT
Modify the `tools/koji-compose.py` script to print all log messages to STDERR and to print only the Koji compose ID to STDOUT. This way, the caller of the script can easily get the ID of the compose created by the script and use it later.
This commit is contained in:
parent
de72b36ddd
commit
9c13f267dc
1 changed files with 14 additions and 13 deletions
|
|
@ -56,40 +56,41 @@ def compose_request(distro, koji, arch):
|
|||
|
||||
def main(distro, arch):
|
||||
cr = compose_request(distro, "https://localhost:4343/kojihub", arch)
|
||||
print(json.dumps(cr))
|
||||
print(json.dumps(cr), file=sys.stderr)
|
||||
|
||||
r = requests.post("https://localhost/api/image-builder-composer/v2/compose", json=cr,
|
||||
cert=("/etc/osbuild-composer/worker-crt.pem", "/etc/osbuild-composer/worker-key.pem"),
|
||||
verify="/etc/osbuild-composer/ca-crt.pem")
|
||||
if r.status_code != 201:
|
||||
print("Failed to create compose")
|
||||
print(r.text)
|
||||
print("Failed to create compose", file=sys.stderr)
|
||||
print(r.text, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(r.text)
|
||||
print(r.text, file=sys.stderr)
|
||||
compose_id = r.json()["id"]
|
||||
print(compose_id)
|
||||
|
||||
while True:
|
||||
r = requests.get(f"https://localhost/api/image-builder-composer/v2/composes/{compose_id}",
|
||||
cert=("/etc/osbuild-composer/worker-crt.pem", "/etc/osbuild-composer/worker-key.pem"),
|
||||
verify="/etc/osbuild-composer/ca-crt.pem")
|
||||
if r.status_code != 200:
|
||||
print("Failed to get compose status")
|
||||
print(r.text)
|
||||
print("Failed to get compose status", file=sys.stderr)
|
||||
print(r.text, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
status = r.json()["status"]
|
||||
print(status)
|
||||
print(status, file=sys.stderr)
|
||||
if status == "success":
|
||||
print("Compose worked!")
|
||||
print(r.text)
|
||||
print("Compose worked!", file=sys.stderr)
|
||||
print(r.text, file=sys.stderr)
|
||||
break
|
||||
elif status == "failure":
|
||||
print("compose failed!")
|
||||
print(r.text)
|
||||
print("compose failed!", file=sys.stderr)
|
||||
print(r.text, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
elif status != "pending" and status != "running":
|
||||
print(f"unexpected status: {status}")
|
||||
print(r.text)
|
||||
print(f"unexpected status: {status}", file=sys.stderr)
|
||||
print(r.text, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
time.sleep(10)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue