From 3156cba26d2d6328827b3b37843e4a683c52f289 Mon Sep 17 00:00:00 2001 From: Jonathan Gangi Date: Wed, 6 Nov 2024 10:45:27 -0300 Subject: [PATCH] Add optional property "cloud_info" for VMIs This commit introduces a new optional property for all VMIPushItems named `VMICloudInformation` which stores the cloud's provider name and account alias into it. The goal of this change is to be able to parse the patched `clouds.json` with this new property, which was instroduced in pubtools-marketplacesvm#71, allowing the DeleteTask to have a more reliable way to retrieve the provider/account information. Refers to SPSTRAT-363 --- docs/model/vmi.rst | 3 +++ src/pushsource/__init__.py | 1 + src/pushsource/_impl/model/__init__.py | 2 +- src/pushsource/_impl/model/ami.py | 7 ++++++- src/pushsource/_impl/model/vms.py | 18 ++++++++++++++++++ tests/baseline/cases/staged-simple-ami-bc.yml | 1 + .../cases/staged-simple-ami-bootmode.yml | 1 + .../baseline/cases/staged-simple-ami-uefi.yml | 1 + tests/baseline/cases/staged-simple-ami.yml | 1 + tests/baseline/cases/staged-simple-cloud.yml | 5 +++++ tests/pub/data/100/images.json | 4 ++++ tests/pub/data/123456/clouds.json | 4 ++++ tests/pub/data/123456/images.json | 4 ++++ tests/pub/data/200/clouds.json | 12 ++++++++++++ tests/pub/data/200/images.json | 8 ++++++++ tests/pub/test_pub_amis.py | 10 ++++++++++ 16 files changed, 80 insertions(+), 2 deletions(-) diff --git a/docs/model/vmi.rst b/docs/model/vmi.rst index 95c6f5e3..6f4e4a8d 100644 --- a/docs/model/vmi.rst +++ b/docs/model/vmi.rst @@ -7,5 +7,8 @@ Push items: VMI .. autoclass:: pushsource.VMIRelease() :members: +.. autoclass:: pushsource.VMICloudInformation() + :members: + .. autoclass:: pushsource.BootMode() :members: diff --git a/src/pushsource/__init__.py b/src/pushsource/__init__.py index 4c7d24ff..0e99a804 100644 --- a/src/pushsource/__init__.py +++ b/src/pushsource/__init__.py @@ -26,6 +26,7 @@ AmiBillingCodes, AmiSecurityGroup, VHDPushItem, + VMICloudInformation, BootMode, ErratumPushItem, ErratumReference, diff --git a/src/pushsource/_impl/model/__init__.py b/src/pushsource/_impl/model/__init__.py index 5a9eff3c..e2d026f0 100644 --- a/src/pushsource/_impl/model/__init__.py +++ b/src/pushsource/_impl/model/__init__.py @@ -30,4 +30,4 @@ AmiSecurityGroup, ) from .azure import VHDPushItem -from .vms import BootMode, VMIPushItem, VMIRelease +from .vms import BootMode, VMICloudInformation, VMIPushItem, VMIRelease diff --git a/src/pushsource/_impl/model/ami.py b/src/pushsource/_impl/model/ami.py index 1b9facbb..e6374cac 100644 --- a/src/pushsource/_impl/model/ami.py +++ b/src/pushsource/_impl/model/ami.py @@ -2,7 +2,7 @@ from .. import compat_attr as attr from .conv import instance_of_str, instance_of, optional_str, optional -from .vms import VMIRelease, VMIPushItem, BootMode +from .vms import VMICloudInformation, VMIRelease, VMIPushItem, BootMode class AmiRelease(VMIRelease): @@ -219,6 +219,11 @@ def _from_data(cls, data): # base push item fields "name": data["name"], "build": data.get("build") or None, + "cloud_info": ( + VMICloudInformation(**data.get("cloud_info")) + if data.get("cloud_info") + else None + ), "state": "PENDING", "src": data.get("src") or None, "dest": data.get("dest") or [], diff --git a/src/pushsource/_impl/model/vms.py b/src/pushsource/_impl/model/vms.py index babc223a..b748244f 100644 --- a/src/pushsource/_impl/model/vms.py +++ b/src/pushsource/_impl/model/vms.py @@ -24,6 +24,17 @@ def __repr__(self): return f"{cls_name}.{self.name}" +@attr.s() +class VMICloudInformation(object): + """Inform the cloud provider's name and account alias of a given push item.""" + + provider = attr.ib(type=str, validator=instance_of_str) + """The cloud provider's name, e.g.: "aws".""" + + account = attr.ib(type=str, validator=instance_of_str) + """The cloud provider's account alias, e.g.: "aws-na".""" + + @attr.s() class VMIRelease(object): """Release metadata associated with a VM image.""" @@ -79,6 +90,13 @@ class VMIPushItem(PushItem): boot_mode = attr.ib(type=BootMode, default=None, validator=optional(in_(BootMode))) """Boot mode supported by the image (if known): uefi, legacy, or hybrid (uefi + legacy).""" + cloud_info = attr.ib( + type=VMICloudInformation, + default=None, + validator=optional((instance_of(VMICloudInformation))), + ) + """Cloud provider information of its short name and account alias.""" + marketplace_title_template = attr.ib(type=str, default=None, validator=optional_str) """The template is of the form used by ``str.format``, with available keywords being all of the documented fields on ``VMIRelease`` and ``AMIRelease`` classes. diff --git a/tests/baseline/cases/staged-simple-ami-bc.yml b/tests/baseline/cases/staged-simple-ami-bc.yml index 786737b8..b25457bf 100644 --- a/tests/baseline/cases/staged-simple-ami-bc.yml +++ b/tests/baseline/cases/staged-simple-ami-bc.yml @@ -18,6 +18,7 @@ items: boot_mode: null build: null build_info: null + cloud_info: null description: A sample image for testing dest: - dest1 diff --git a/tests/baseline/cases/staged-simple-ami-bootmode.yml b/tests/baseline/cases/staged-simple-ami-bootmode.yml index 93773356..35fac5e7 100644 --- a/tests/baseline/cases/staged-simple-ami-bootmode.yml +++ b/tests/baseline/cases/staged-simple-ami-bootmode.yml @@ -14,6 +14,7 @@ items: boot_mode: uefi build: null build_info: null + cloud_info: null description: A sample image for testing dest: - dest1 diff --git a/tests/baseline/cases/staged-simple-ami-uefi.yml b/tests/baseline/cases/staged-simple-ami-uefi.yml index 2af935b6..38035717 100644 --- a/tests/baseline/cases/staged-simple-ami-uefi.yml +++ b/tests/baseline/cases/staged-simple-ami-uefi.yml @@ -14,6 +14,7 @@ items: boot_mode: null build: null build_info: null + cloud_info: null description: A sample image for testing dest: - dest1 diff --git a/tests/baseline/cases/staged-simple-ami.yml b/tests/baseline/cases/staged-simple-ami.yml index 6560c097..166ba53d 100644 --- a/tests/baseline/cases/staged-simple-ami.yml +++ b/tests/baseline/cases/staged-simple-ami.yml @@ -14,6 +14,7 @@ items: boot_mode: null build: null build_info: null + cloud_info: null description: A sample image for testing dest: - dest1 diff --git a/tests/baseline/cases/staged-simple-cloud.yml b/tests/baseline/cases/staged-simple-cloud.yml index 58ddb9d6..ce459c15 100644 --- a/tests/baseline/cases/staged-simple-cloud.yml +++ b/tests/baseline/cases/staged-simple-cloud.yml @@ -18,6 +18,7 @@ items: name: rhel release: '1' version: '9.4' + cloud_info: null description: build2 sample dest: - starmap @@ -68,6 +69,7 @@ items: name: rhel release: '1' version: '9.4' + cloud_info: null description: build2 sample dest: - starmap @@ -118,6 +120,7 @@ items: name: rhel-ec2 release: '1' version: '9.4' + cloud_info: null description: build3 sample dest: - starmap @@ -166,6 +169,7 @@ items: name: rhel-ec2 release: '1' version: '9.4' + cloud_info: null description: build1 sample dest: - starmap @@ -203,6 +207,7 @@ items: name: rhel-ec2 release: '1' version: '9.4' + cloud_info: null description: build1 sample dest: - starmap diff --git a/tests/pub/data/100/images.json b/tests/pub/data/100/images.json index eb16f651..68688f98 100644 --- a/tests/pub/data/100/images.json +++ b/tests/pub/data/100/images.json @@ -7,6 +7,10 @@ ], "name": "Hourly2" }, + "cloud_info": { + "provider": "aws", + "account": "aws-emea" + }, "description": "Provided by Red Hat, Inc.", "dest": [ "me-south-1-hourly" diff --git a/tests/pub/data/123456/clouds.json b/tests/pub/data/123456/clouds.json index cbd1bd54..25f79a4f 100644 --- a/tests/pub/data/123456/clouds.json +++ b/tests/pub/data/123456/clouds.json @@ -8,6 +8,10 @@ "release": "2116", "version": "8.8" }, + "cloud_info": { + "provider": "aws", + "account": "aws-emea" + }, "description": "Provided by Red Hat, Inc.", "dest": [ "test-dest" diff --git a/tests/pub/data/123456/images.json b/tests/pub/data/123456/images.json index c7803496..ee8dc7b1 100644 --- a/tests/pub/data/123456/images.json +++ b/tests/pub/data/123456/images.json @@ -7,6 +7,10 @@ ], "name": "Hourly2" }, + "cloud_info": { + "provider": "aws", + "account": "aws-emea" + }, "description": "Provided by Red Hat, Inc.", "dest": [ "sa-east-1-hourly" diff --git a/tests/pub/data/200/clouds.json b/tests/pub/data/200/clouds.json index 48aad6c8..72e3b87a 100644 --- a/tests/pub/data/200/clouds.json +++ b/tests/pub/data/200/clouds.json @@ -8,6 +8,10 @@ "release": "2116", "version": "8.8" }, + "cloud_info": { + "provider": "aws", + "account": "aws-na" + }, "description": "Provided by Red Hat, Inc.", "dest": [ "test-dest" @@ -145,6 +149,10 @@ "release": "2116", "version": "8.8" }, + "cloud_info": { + "provider": "aws", + "account": "aws-emea" + }, "description": "Provided by Red Hat, Inc.", "dest": [ "test-dest2" @@ -280,6 +288,10 @@ ], "name": "Hourly2" }, + "cloud_info": { + "provider": "aws", + "account": "aws-emea" + }, "boot_mode": null, "build": "rhel-ec2-8.8-2175", "build_info": { diff --git a/tests/pub/data/200/images.json b/tests/pub/data/200/images.json index 272c2750..31e367dd 100644 --- a/tests/pub/data/200/images.json +++ b/tests/pub/data/200/images.json @@ -7,6 +7,10 @@ ], "name": "Hourly2" }, + "cloud_info": { + "provider": "aws", + "account": "aws-na" + }, "description": "Provided by Red Hat, Inc.", "dest": [ "us-east-1-hourly" @@ -48,6 +52,10 @@ ], "name": "Hourly2" }, + "cloud_info": { + "provider": "aws", + "account": "aws-emea" + }, "description": "Provided by Red Hat, Inc.", "dest": [ "me-central-1-hourly" diff --git a/tests/pub/test_pub_amis.py b/tests/pub/test_pub_amis.py index bd26d139..8ebf895d 100644 --- a/tests/pub/test_pub_amis.py +++ b/tests/pub/test_pub_amis.py @@ -13,6 +13,7 @@ Source, AmiSecurityGroup, KojiBuildInfo, + VMICloudInformation, ) DATAPATH = os.path.join(os.path.dirname(__file__), "data") @@ -55,6 +56,7 @@ def test_get_ami_push_items_single_task(requests_mock): origin="/fake/path/aws/", build=None, build_info=None, + cloud_info=VMICloudInformation(provider="aws", account="aws-emea"), signing_key=None, release=AmiRelease( product="SAP", @@ -140,6 +142,7 @@ def test_get_ami_push_items_single_task_clouds(requests_mock): release="2116", id=None, ), + cloud_info=VMICloudInformation(provider="aws", account="aws-emea"), release=AmiRelease( product="RHEL-SAP", date="20240717", @@ -211,6 +214,7 @@ def test_get_ami_push_items_rhcos_task_cloud(requests_mock): release="2116", id=None, ), + cloud_info=VMICloudInformation(provider="aws", account="aws-na"), release=AmiRelease( product="RHEL-SAP", date="20240717", @@ -248,6 +252,7 @@ def test_get_ami_push_items_rhcos_task_cloud(requests_mock): release="2116", id=None, ), + cloud_info=VMICloudInformation(provider="aws", account="aws-emea"), image_id="ami-test", release=AmiRelease( product="RHEL-SAP", @@ -286,6 +291,7 @@ def test_get_ami_push_items_rhcos_task_cloud(requests_mock): release="2175", id=None, ), + cloud_info=VMICloudInformation(provider="aws", account="aws-emea"), image_id="ami-test", release=AmiRelease( product="RHEL", @@ -344,6 +350,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock): origin="/fake/path/aws", build=None, build_info=None, + cloud_info=VMICloudInformation(provider="aws", account="aws-emea"), signing_key=None, release=AmiRelease( product="SAP", @@ -378,6 +385,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock): origin="/fake/path/aws/", build=None, build_info=None, + cloud_info=VMICloudInformation(provider="aws", account="aws-emea"), signing_key=None, release=AmiRelease( product="SAP", @@ -427,6 +435,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock): origin="/fake/path/aws/", build=None, build_info=None, + cloud_info=VMICloudInformation(provider="aws", account="aws-na"), signing_key=None, release=AmiRelease( product="SAP", @@ -469,6 +478,7 @@ def test_get_ami_push_items_multiple_tasks(requests_mock): origin="/fake/path/aws/", build=None, build_info=None, + cloud_info=VMICloudInformation(provider="aws", account="aws-emea"), signing_key=None, release=AmiRelease( product="SAP",