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 1d2af9b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/pubtools/_marketplacesvm/tasks/community_push/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,13 @@ 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(r.get("type", "")).lower()
beta = self.args.beta or r_type == "beta"
epi = enrich_push_item(
pi,
dest,
ga=r_type == "ga",
beta=beta,
require_bc=self._REQUIRE_BC,
billing_config=mapped_item.starmap_query_entity.billing_code_config,
Expand Down
12 changes: 10 additions & 2 deletions src/pubtools/_marketplacesvm/tasks/community_push/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _fix_arm64_arch(push_item: AmiPushItem) -> AmiPushItem:
def enrich_push_item(
push_item: AmiPushItem,
destination: Destination,
ga: bool,
beta: bool,
require_bc: bool = True,
billing_config: Optional[BILLING_CONFIG] = None,
Expand All @@ -134,8 +135,10 @@ 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.
ga:
Whether the release type is "ga" or not.
beta:
Whether the release type is "beta" or not ("ga")
Whether the release type is "beta" or not.
require_bc:
Whether the billing_codes are required (True) or not (False).
Defaults to True.
Expand All @@ -161,7 +164,12 @@ def enrich_push_item(
pi = _fix_arm64_arch(pi)

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

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 1d2af9b

Please sign in to comment.