From b6e60855fd5efaabf9a160216e0de001aa900b21 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Mon, 1 Apr 2024 14:07:54 -0600 Subject: [PATCH] test: add bootc_status to payload Allow adding hosts for testing with bootc_status information. When using `make run_inv_mq_service_test_producer`, you can now provide the following environment variables to add `bootc_status` fields to the `system_profile`: * `BOOTC_BOOTED_IMAGE` * `BOOTC_STAGED_IMAGE` * `BOOTC_ROLLBACK_IMAGE` Example: ```bash BOOTC_BOOTED_IMAGE=quay.io/my_org/my_repo:a_tag \ BOOTC_STAGED_IMAGE=quay.io/my_org/my_repo:a_new_tag \ BOOTC_ROLLBACK_IMAGE=quay.io/my_org/my_repo:a_previous_tag \ make run_inv_mq_service_test_producer ``` This will cause the payload to have a `bootc_status` field, and the return value from an api query of system_profile will look like this: ```json ... "bootc_status": { "booted": { "image": "quay.io/my_org/my_repo:a_tag", "image_digest": "sha256:c7f7cbd......" }, "staged": { "image": "quay.io/my_org/my_repo:a_new_tag", "image_digest": "sha256:a28b09c......" }, "rollback": { "image": "quay.io/my_org/my_repo:a_previous_tag", "image_digest": "sha256:fd99cb0......" } } ``` The sha256 digest value is calculated from the image name, so that way the same image name will have the same digest value. Signed-off-by: Rich Megginson --- utils/payloads.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/utils/payloads.py b/utils/payloads.py index c16e5b3778..438c7fbca9 100644 --- a/utils/payloads.py +++ b/utils/payloads.py @@ -1,4 +1,5 @@ import base64 +import hashlib import json import os import uuid @@ -408,8 +409,13 @@ def rpm_list(): ] +IS_EDGE = os.environ.get("IS_EDGE", False) +BOOTC_BOOTED_IMAGE = os.environ.get("BOOTC_BOOTED_IMAGE") +BOOTC_STAGED_IMAGE = os.environ.get("BOOTC_STAGED_IMAGE") +BOOTC_ROLLBACK_IMAGE = os.environ.get("BOOTC_ROLLBACK_IMAGE") + def create_system_profile(): - return { + system_profile = { "owner_id": "1b36b20f-7fa0-4454-a6d2-008294e06378", "rhc_client_id": "044e36dc-4e2b-4e69-8948-9c65a7bf4976", "rhc_config_state": "044e36dc-4e2b-4e69-8948-9c65a7bf4976", @@ -473,6 +479,18 @@ def create_system_profile(): "operating_system": {"name": "RHEL", "major": 8, "minor": 1}, "system_update_method": "yum", # "dnf, rpm-ostree, yum" } + if IS_EDGE: + system_profile["host_type"] = "edge" + bootc_status = {} + for img_type, img in (("booted", BOOTC_BOOTED_IMAGE), ("staged", BOOTC_STAGED_IMAGE), ("rollback", BOOTC_ROLLBACK_IMAGE)): + if img: + input = img_type + img + hashstr = f"sha256:{hashlib.sha256(input.encode('utf-8')).hexdigest()}" + bootc_status[img_type] = {"image": img, "image_digest": hashstr} + if bootc_status: + system_profile["bootc_status"] = bootc_status + print("system_profile " + str(system_profile)) + return system_profile def build_rhsm_payload(): @@ -554,17 +572,11 @@ def random_uuid(): return str(uuid.uuid4()) -IS_EDGE = os.environ.get("IS_EDGE", False) - - def build_host_chunk(): org_id = os.environ.get("INVENTORY_HOST_ACCOUNT", IDENTITY["org_id"]) fqdn = random_uuid()[:6] + ".foo.redhat.com" system_profile = create_system_profile() - if IS_EDGE: - system_profile["host_type"] = "edge" - payload = { "bios_uuid": random_uuid(), "org_id": org_id,