Skip to content

Commit 07e5186

Browse files
committed
Add attribute "marketplace_title" to VMIRelease
This commit introduces a new optional parameter on `VMIPushItem` model called `marketplace_title_template` which is going to be used in conjunction with `VMIPushItem.marketplace_title` property by the pubtool as the marketplace "version title" whenever it's set, by overriding the usual version title which the pubtool was going to compute. This is required for some layered products which requires a specialized templating title instead of the one generated by the pubtool. With this, it will be possible to transport the template via the VMIPushItem from the source to the pubtooling which will format it into the apropriate value for the marketaplace. Refers to SPSTRAT-116
1 parent d9ab92c commit 07e5186

File tree

9 files changed

+60
-1
lines changed

9 files changed

+60
-1
lines changed

src/pushsource/_impl/model/ami.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ def _from_data(cls, data):
220220
"scanning_port": data.get("scanning_port") or None,
221221
"user_name": data.get("user_name") or None,
222222
"version_title": data.get("version_title") or None,
223+
"marketplace_title_template": data.get("marketplace_title_template")
224+
or None,
223225
"security_groups": [
224226
AmiSecurityGroup._from_data(security_group)
225227
for security_group in (data.get("security_groups") or [])

src/pushsource/_impl/model/vms.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from .base import PushItem
55
from .. import compat_attr as attr
6+
from attr import asdict
67
from .conv import datestr, instance_of_str, instance_of, optional_str, optional, in_
78

89

@@ -74,6 +75,22 @@ class VMIPushItem(PushItem):
7475
boot_mode = attr.ib(type=BootMode, default=None, validator=optional(in_(BootMode)))
7576
"""Boot mode supported by the image (if known): uefi, legacy, or hybrid (uefi + legacy)."""
7677

78+
marketplace_title_template = attr.ib(type=str, default=None, validator=optional_str)
79+
"""The template is of the form used by ``str.format``, with available keywords being all of
80+
the documented fields on ``VMIRelease`` and ``AMIRelease`` classes.
81+
82+
It's used by the property `marketplace_title` to format it as the marketplace title."""
83+
84+
@property
85+
def marketplace_title(self) -> str:
86+
"""The marketplace title which is used for some certain layared products.
87+
88+
It's built from the `marketplace_title_template` by formatting it with the proper values.
89+
"""
90+
if not self.marketplace_title_template or not self.release:
91+
return ""
92+
return self.marketplace_title_template.format(**asdict(self.release))
93+
7794
@release.validator
7895
def __validate_release(self, attribute, value): # pylint: disable=unused-argument
7996
# Strict (unidiomatic) type check ensures that subclasses

src/pushsource/_impl/schema/staged-schema.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ definitions:
135135
$ref: "#/definitions/optional_string"
136136
version_title:
137137
$ref: "#/definitions/optional_string"
138+
marketplace_title_template:
139+
$ref: "#/definitions/optional_string"
138140
security_groups:
139141
type:
140142
- array

tests/baseline/cases/staged-simple-ami-bc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ items:
2323
ena_support: true
2424
image_id: null
2525
marketplace_entity_type: AMIProduct
26+
marketplace_title_template: null
2627
md5sum: null
2728
name: fake-image.raw
2829
origin: {{ src_dir }}/tests/staged/data/simple_ami_with_bc

tests/baseline/cases/staged-simple-ami-bootmode.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ items:
1919
ena_support: true
2020
image_id: null
2121
marketplace_entity_type: null
22+
marketplace_title_template: null
2223
md5sum: null
2324
name: fake-image.raw
2425
origin: {{ src_dir }}/tests/staged/data/simple_ami_with_bootmode

tests/baseline/cases/staged-simple-ami-uefi.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ items:
1919
ena_support: true
2020
image_id: null
2121
marketplace_entity_type: null
22+
marketplace_title_template: null
2223
md5sum: null
2324
name: fake-image.raw
2425
origin: {{ src_dir }}/tests/staged/data/simple_ami_with_uefi

tests/baseline/cases/staged-simple-ami.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ items:
1919
ena_support: true
2020
image_id: null
2121
marketplace_entity_type: null
22+
marketplace_title_template: null
2223
md5sum: null
2324
name: fake-image.raw
2425
origin: {{ src_dir }}/tests/staged/data/simple_ami

tests/model/test_vmi.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pytest import raises
22

3-
from pushsource import VMIRelease
3+
from pushsource import VMIRelease, VMIPushItem
44

55

66
def test_invalidate_datestr():
@@ -9,3 +9,36 @@ def test_invalidate_datestr():
99
VMIRelease(product="myprod", arch="x86_64", respin=1, date="not-a-real-date")
1010

1111
assert "can't parse 'not-a-real-date' as a date" in str(exc_info.value)
12+
13+
14+
def test_marketplace_title():
15+
"""Ensure the marketplace_title is properly formed from the template."""
16+
17+
release = VMIRelease(
18+
product="myprod", arch="x86_64", version="7.0", respin=1, date="20240101"
19+
)
20+
21+
# Template provided
22+
template = r"Test {product} {arch} {version} - success"
23+
pi = VMIPushItem(
24+
description="mydescription",
25+
name="myname",
26+
marketplace_title_template=template,
27+
release=release,
28+
)
29+
assert pi.marketplace_title == "Test myprod x86_64 7.0 - success"
30+
31+
# No template provided
32+
pi = VMIPushItem(
33+
description="mydescription",
34+
name="myname",
35+
release=release,
36+
)
37+
assert pi.marketplace_title == ""
38+
39+
# No release provided
40+
pi = VMIPushItem(
41+
description="mydescription",
42+
name="myname",
43+
)
44+
assert pi.marketplace_title == ""

tests/staged/data/simple_ami/staged.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ payload:
2525
virtualization: hvm
2626
volume: gp2
2727
public_image: true
28+
marketplace_title_template: "Test {product} - {date}"

0 commit comments

Comments
 (0)