Skip to content

Commit

Permalink
Add optional property "cloud_info" for VMIs (#637)
Browse files Browse the repository at this point in the history
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 introduced in
release-engineering/pubtools-marketplacesvm#71 ,
allowing the DeleteTask to have a more reliable way to retrieve the
provider/account information.

Refers to SPSTRAT-363

---------

Co-authored-by: Rohan McGovern <rmcgover@redhat.com>
  • Loading branch information
JAVGan and rohanpm authored Nov 7, 2024
1 parent 2b702ce commit 0f0d0c0
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/model/vmi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ Push items: VMI
.. autoclass:: pushsource.VMIRelease()
:members:

.. autoclass:: pushsource.VMICloudInfo()
:members:

.. autoclass:: pushsource.BootMode()
:members:
1 change: 1 addition & 0 deletions src/pushsource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
AmiBillingCodes,
AmiSecurityGroup,
VHDPushItem,
VMICloudInfo,
BootMode,
ErratumPushItem,
ErratumReference,
Expand Down
2 changes: 1 addition & 1 deletion src/pushsource/_impl/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
AmiSecurityGroup,
)
from .azure import VHDPushItem
from .vms import BootMode, VMIPushItem, VMIRelease
from .vms import BootMode, VMICloudInfo, VMIPushItem, VMIRelease
7 changes: 6 additions & 1 deletion src/pushsource/_impl/model/ami.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 VMICloudInfo, VMIRelease, VMIPushItem, BootMode


class AmiRelease(VMIRelease):
Expand Down Expand Up @@ -219,6 +219,11 @@ def _from_data(cls, data):
# base push item fields
"name": data["name"],
"build": data.get("build") or None,
"cloud_info": (
VMICloudInfo(**data.get("cloud_info"))
if data.get("cloud_info")
else None
),
"state": "PENDING",
"src": data.get("src") or None,
"dest": data.get("dest") or [],
Expand Down
27 changes: 27 additions & 0 deletions src/pushsource/_impl/model/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ def __repr__(self):
return f"{cls_name}.{self.name}"


@attr.s()
class VMICloudInfo(object):
"""Information on the cloud provider associated with a given push item.
Cloud provider information is only available for VMIs which have previously
been published to a cloud. It may be used to locate an existing VMI for
manipulation, such as metadata updates or deletion.
This library doesn't define any specific cloud provider names or aliases.
Generally, a user of this library is expected to use the information here
to look up cloud access details from a configuration file or other source.
"""

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."""
Expand Down Expand Up @@ -79,6 +99,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=VMICloudInfo,
default=None,
validator=optional((instance_of(VMICloudInfo))),
)
"""Cloud provider information, such as the provider's 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.
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami-bc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ items:
boot_mode: null
build: null
build_info: null
cloud_info: null
description: A sample image for testing
dest:
- dest1
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami-bootmode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ items:
boot_mode: uefi
build: null
build_info: null
cloud_info: null
description: A sample image for testing
dest:
- dest1
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami-uefi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ items:
boot_mode: null
build: null
build_info: null
cloud_info: null
description: A sample image for testing
dest:
- dest1
Expand Down
1 change: 1 addition & 0 deletions tests/baseline/cases/staged-simple-ami.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ items:
boot_mode: null
build: null
build_info: null
cloud_info: null
description: A sample image for testing
dest:
- dest1
Expand Down
5 changes: 5 additions & 0 deletions tests/baseline/cases/staged-simple-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ items:
name: rhel
release: '1'
version: '9.4'
cloud_info: null
description: build2 sample
dest:
- starmap
Expand Down Expand Up @@ -68,6 +69,7 @@ items:
name: rhel
release: '1'
version: '9.4'
cloud_info: null
description: build2 sample
dest:
- starmap
Expand Down Expand Up @@ -118,6 +120,7 @@ items:
name: rhel-ec2
release: '1'
version: '9.4'
cloud_info: null
description: build3 sample
dest:
- starmap
Expand Down Expand Up @@ -166,6 +169,7 @@ items:
name: rhel-ec2
release: '1'
version: '9.4'
cloud_info: null
description: build1 sample
dest:
- starmap
Expand Down Expand Up @@ -203,6 +207,7 @@ items:
name: rhel-ec2
release: '1'
version: '9.4'
cloud_info: null
description: build1 sample
dest:
- starmap
Expand Down
4 changes: 4 additions & 0 deletions tests/pub/data/100/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
],
"name": "Hourly2"
},
"cloud_info": {
"provider": "aws",
"account": "aws-emea"
},
"description": "Provided by Red Hat, Inc.",
"dest": [
"me-south-1-hourly"
Expand Down
4 changes: 4 additions & 0 deletions tests/pub/data/123456/clouds.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions tests/pub/data/123456/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
],
"name": "Hourly2"
},
"cloud_info": {
"provider": "aws",
"account": "aws-emea"
},
"description": "Provided by Red Hat, Inc.",
"dest": [
"sa-east-1-hourly"
Expand Down
12 changes: 12 additions & 0 deletions tests/pub/data/200/clouds.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -280,6 +288,10 @@
],
"name": "Hourly2"
},
"cloud_info": {
"provider": "aws",
"account": "aws-emea"
},
"boot_mode": null,
"build": "rhel-ec2-8.8-2175",
"build_info": {
Expand Down
8 changes: 8 additions & 0 deletions tests/pub/data/200/images.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
],
"name": "Hourly2"
},
"cloud_info": {
"provider": "aws",
"account": "aws-na"
},
"description": "Provided by Red Hat, Inc.",
"dest": [
"us-east-1-hourly"
Expand Down Expand Up @@ -48,6 +52,10 @@
],
"name": "Hourly2"
},
"cloud_info": {
"provider": "aws",
"account": "aws-emea"
},
"description": "Provided by Red Hat, Inc.",
"dest": [
"me-central-1-hourly"
Expand Down
10 changes: 10 additions & 0 deletions tests/pub/test_pub_amis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Source,
AmiSecurityGroup,
KojiBuildInfo,
VMICloudInfo,
)

DATAPATH = os.path.join(os.path.dirname(__file__), "data")
Expand Down Expand Up @@ -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=VMICloudInfo(provider="aws", account="aws-emea"),
signing_key=None,
release=AmiRelease(
product="SAP",
Expand Down Expand Up @@ -140,6 +142,7 @@ def test_get_ami_push_items_single_task_clouds(requests_mock):
release="2116",
id=None,
),
cloud_info=VMICloudInfo(provider="aws", account="aws-emea"),
release=AmiRelease(
product="RHEL-SAP",
date="20240717",
Expand Down Expand Up @@ -211,6 +214,7 @@ def test_get_ami_push_items_rhcos_task_cloud(requests_mock):
release="2116",
id=None,
),
cloud_info=VMICloudInfo(provider="aws", account="aws-na"),
release=AmiRelease(
product="RHEL-SAP",
date="20240717",
Expand Down Expand Up @@ -248,6 +252,7 @@ def test_get_ami_push_items_rhcos_task_cloud(requests_mock):
release="2116",
id=None,
),
cloud_info=VMICloudInfo(provider="aws", account="aws-emea"),
image_id="ami-test",
release=AmiRelease(
product="RHEL-SAP",
Expand Down Expand Up @@ -286,6 +291,7 @@ def test_get_ami_push_items_rhcos_task_cloud(requests_mock):
release="2175",
id=None,
),
cloud_info=VMICloudInfo(provider="aws", account="aws-emea"),
image_id="ami-test",
release=AmiRelease(
product="RHEL",
Expand Down Expand Up @@ -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=VMICloudInfo(provider="aws", account="aws-emea"),
signing_key=None,
release=AmiRelease(
product="SAP",
Expand Down Expand Up @@ -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=VMICloudInfo(provider="aws", account="aws-emea"),
signing_key=None,
release=AmiRelease(
product="SAP",
Expand Down Expand Up @@ -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=VMICloudInfo(provider="aws", account="aws-na"),
signing_key=None,
release=AmiRelease(
product="SAP",
Expand Down Expand Up @@ -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=VMICloudInfo(provider="aws", account="aws-emea"),
signing_key=None,
release=AmiRelease(
product="SAP",
Expand Down

0 comments on commit 0f0d0c0

Please sign in to comment.