Skip to content

Commit

Permalink
test: add bootc_status to payload
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
richm committed Apr 22, 2024
1 parent d9a8b2c commit a180600
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions utils/payloads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import hashlib
import json
import os
import uuid
Expand Down Expand Up @@ -408,8 +409,14 @@ 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",
Expand Down Expand Up @@ -473,6 +480,22 @@ 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():
Expand Down Expand Up @@ -554,17 +577,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,
Expand Down

0 comments on commit a180600

Please sign in to comment.