Skip to content

Commit

Permalink
Community: Allow a better handle of Release Type
Browse files Browse the repository at this point in the history
This commit enhances the `release.type` definition by allowing it to be
null whenever `ga` or `beta` is not meant to be set.

With this change, the `release.type` behavior will be executed as
follow:

- If `--beta` is passed on cmd line or in the StArMap mappings it
  will set the value to "beta"

- Otherwise, if the value "ga" is set on StArMap mappings it will set
  `release.type` to "ga"

- Else: the `release.type` will be null and not used in the AMI name.

Refers to SPSTRAT-417
  • Loading branch information
JAVGan committed Oct 8, 2024
1 parent ebd2420 commit 169d66f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 18 deletions.
12 changes: 9 additions & 3 deletions src/pubtools/_marketplacesvm/tasks/community_push/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from starmap_client.models import Destination, Workflow
from typing_extensions import NotRequired

from pubtools._marketplacesvm.tasks.community_push.items import enrich_push_item
from pubtools._marketplacesvm.tasks.community_push.items import ReleaseType, enrich_push_item

from ...cloud_providers.aws import name_from_push_item
from ...services.rhsm import AwsRHSMClientService
Expand Down Expand Up @@ -305,11 +305,17 @@ def enrich_mapped_items(
for dest in mrobj.destinations:
pi = mapped_item.get_push_item_for_destination(dest)
log.debug("Mapped push item for %s: %s", storage_account, pi)
beta = self.args.beta or str(pi.release.type) == "beta"
r = dest.meta.get("release") or {}
r_type_str = str(r.get("type", "")).lower()
r_type_str = "beta" if self.args.beta else r_type_str
if r_type_str:
release_type = ReleaseType(r_type_str)
else:
release_type = None
epi = enrich_push_item(
pi,
dest,
beta=beta,
release_type=release_type,
require_bc=self._REQUIRE_BC,
billing_config=mapped_item.starmap_query_entity.billing_code_config,
)
Expand Down
18 changes: 13 additions & 5 deletions src/pubtools/_marketplacesvm/tasks/community_push/items.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from enum import Enum
from typing import Dict, Optional

from attrs import evolve
Expand All @@ -17,6 +18,13 @@
log = logging.getLogger("pubtools.marketplacesvm")


class ReleaseType(str, Enum):
"""Define the supported release type values."""

ga = "ga"
beta = "beta"


def _get_push_item_region_type(push_item: AmiPushItem, destination: Destination) -> AmiPushItem:
region, image_type = destination.destination.rsplit("-", 1)
return evolve(push_item, region=region, type=image_type)
Expand Down Expand Up @@ -122,7 +130,7 @@ def _fix_arm64_arch(push_item: AmiPushItem) -> AmiPushItem:
def enrich_push_item(
push_item: AmiPushItem,
destination: Destination,
beta: bool,
release_type: Optional[ReleaseType],
require_bc: bool = True,
billing_config: Optional[BILLING_CONFIG] = None,
) -> AmiPushItem:
Expand All @@ -134,8 +142,8 @@ def enrich_push_item(
The push item to enrich with the missing values
destination:
The destination with all required information to enrich the push item.
beta:
Whether the release type is "beta" or not ("ga")
release_type:
Whether the release type is "beta", "ga" or not set.
require_bc:
Whether the billing_codes are required (True) or not (False).
Defaults to True.
Expand All @@ -161,8 +169,8 @@ def enrich_push_item(
pi = _fix_arm64_arch(pi)

# Set the release type
rel_type = "beta" if beta else "ga"
rel = evolve(pi.release, type=rel_type)
r_type = release_type.value if release_type else None
rel = evolve(pi.release, type=r_type)
pi = evolve(pi, release=rel)

# Now we need to convert the "dest" from "List[Destination]" into "List[str]"
Expand Down
1 change: 1 addition & 0 deletions tests/community_push/test_community_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def test_do_community_push_overridden_destination(
},
"billing-code-config": starmap_ami_billing_config,
"cloud": "aws",
"meta": {"release": {"type": "ga"}},
"name": "sample-product",
"workflow": "community",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
[ DEBUG] Attempting to match billing rule sample-access to sample_product_test.raw type access
[ DEBUG] Matched billing rule sample-access for sample_product_test.raw
[ DEBUG] Billing codes for ami_pushitem: ['bp-63a5400a'] (Access2)
[ DEBUG] Enriched push item for aws_storage: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['fake-destination-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='test-build', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type='ga'), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='fake-destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Access2', codes=['bp-63a5400a']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ DEBUG] Enriched push item for aws_storage: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['fake-destination-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='test-build', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type=None), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='fake-destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Access2', codes=['bp-63a5400a']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ INFO] Adding push item "ami_pushitem" with destination "fake-destination-access" and type "access" to the queue.
[ INFO] Loading accounts from StArMap: ['first_account', 'second_account']
[ DEBUG] Loaded the following accounts as "accounts": ['first_account', 'second_account']
Expand Down Expand Up @@ -65,7 +65,7 @@
[ DEBUG] Attempting to match billing rule sample-access to sample_product_test.raw type access
[ DEBUG] Matched billing rule sample-access for sample_product_test.raw
[ DEBUG] Billing codes for ami_pushitem: ['bp-63a5400a'] (Access2)
[ DEBUG] Enriched push item for aws_storage: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['fake-destination2-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='test-build', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type='ga'), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='fake-destination2', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Access2', codes=['bp-63a5400a']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='anotherprovider', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ DEBUG] Enriched push item for aws_storage: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['fake-destination2-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='test-build', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type=None), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='fake-destination2', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Access2', codes=['bp-63a5400a']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='anotherprovider', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ INFO] Adding push item "ami_pushitem" with destination "fake-destination2-access" and type "access" to the queue.
[ INFO] Loading accounts from StArMap: ['third_account', 'fourth_account']
[ DEBUG] Loaded the following accounts as "accounts": ['third_account', 'fourth_account']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
[ WARNING] Missing information for the attribute ami_pushitem.access_endpoint_url, leaving it unset.
[ DEBUG] Mapped push item for aws_storage: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=[Destination(meta={}, id=None, architecture='x86_64', destination='fake-destination-access', overwrite=False, restrict_version=False, restrict_major=2, restrict_minor=2, provider='awstest', tags=None)], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='test-build', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type='ga'), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='hourly', region=None, virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=None, release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type=None, image_id=None, public_image=None, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ WARNING] BILLING CODES REQUIREMENT IS CURRENTLY DISABLED!
[ DEBUG] Enriched push item for aws_storage: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['fake-destination-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='test-build', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type='ga'), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='fake-destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=None, release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ DEBUG] Enriched push item for aws_storage: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['fake-destination-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='test-build', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type=None), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='fake-destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=None, release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ INFO] Adding push item "ami_pushitem" with destination "fake-destination-access" and type "access" to the queue.
[ WARNING] No accounts definition in StArMap, leaving the defaults from credentials.
[ WARNING] No sharing_accounts definition in StArMap, leaving the defaults from credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[ DEBUG] Attempting to match billing rule sample-access to sample_product_test.raw type access
[ DEBUG] Matched billing rule sample-access for sample_product_test.raw
[ DEBUG] Billing codes for ami_pushitem: ['bp-63a5400a'] (Access2)
[ DEBUG] Enriched push item for aws-na: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['new_aws-na_destination-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='sample-product', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type='ga'), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='new_aws-na_destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Access2', codes=['bp-63a5400a']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ DEBUG] Enriched push item for aws-na: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['new_aws-na_destination-access'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='sample-product', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type=None), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='access', region='new_aws-na_destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Access2', codes=['bp-63a5400a']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=False, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ INFO] Adding push item "ami_pushitem" with destination "new_aws-na_destination-access" and type "access" to the queue.
[ WARNING] No accounts definition in StArMap, leaving the defaults from credentials.
[ WARNING] No sharing_accounts definition in StArMap, leaving the defaults from credentials.
Expand Down Expand Up @@ -62,7 +62,7 @@
[ DEBUG] Matched billing rule sample-hourly for sample_product_test.raw
[ DEBUG] Attempting to match billing rule sample-access to sample_product_test.raw type hourly
[ DEBUG] Billing codes for ami_pushitem: ['bp-6fa54006'] (Hourly2)
[ DEBUG] Enriched push item for aws-emea: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['new_aws-emea_destination-hourly'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='sample-product', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type='ga'), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='hourly', region='new_aws-emea_destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Hourly2', codes=['bp-6fa54006']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=True, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ DEBUG] Enriched push item for aws-emea: AmiPushItem(name='ami_pushitem', state='PENDING', src='/foo/bar/sample_product_test.raw', dest=['new_aws-emea_destination-hourly'], md5sum=None, sha256sum=None, origin=None, build=None, build_info=KojiBuildInfo(name='sample-product', version='7.0', release='20230101', id=None), signing_key=None, release=AmiRelease(product='sample_product', date=datetime.datetime(2023, 12, 12, 0, 0), arch='x86_64', respin=1, version='7.0', base_product='sample_base', base_version='1.0', variant='variant', type=None), description='', boot_mode=None, marketplace_title_template=None, marketplace_name=None, type='hourly', region='new_aws-emea_destination', virtualization='hvm', volume='/dev/sda1', root_device=None, sriov_net_support=None, ena_support=None, uefi_support=None, billing_codes=AmiBillingCodes(name='Hourly2', codes=['bp-6fa54006']), release_notes=None, usage_instructions=None, recommended_instance_type=None, marketplace_entity_type='awstest', image_id=None, public_image=True, scanning_port=None, user_name=None, version_title=None, security_groups=[], access_endpoint_url=None)
[ INFO] Adding push item "ami_pushitem" with destination "new_aws-emea_destination-hourly" and type "hourly" to the queue.
[ WARNING] No accounts definition in StArMap, leaving the defaults from credentials.
[ WARNING] No sharing_accounts definition in StArMap, leaving the defaults from credentials.
Expand Down
Loading

0 comments on commit 169d66f

Please sign in to comment.