Skip to content

Commit 01e5b5e

Browse files
committed
Differentiate platform and platforms in the GardenLinux canonical name
Signed-off-by: Tobias Wolf <[email protected]> On-behalf-of: SAP <[email protected]>
1 parent 1239276 commit 01e5b5e

File tree

4 files changed

+41
-28
lines changed

4 files changed

+41
-28
lines changed

src/gardenlinux/features/__main__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"commit_id",
2424
"features",
2525
"platform",
26+
"platforms",
2627
"flags",
2728
"flavor",
2829
"elements",
@@ -143,6 +144,7 @@ def main() -> None:
143144
"flavor",
144145
"graph",
145146
"platform",
147+
"platforms",
146148
):
147149
if args.type == "graph" or len(args.ignore) > 0:
148150
features_parser = Parser(gardenlinux_root, feature_dir_name)
@@ -255,13 +257,15 @@ def additional_filter_func(node):
255257
flavor, additional_filter_func=additional_filter_func
256258
)
257259
)
258-
elif output_type in ("platform", "elements", "flags"):
260+
elif output_type in ("platform", "platforms", "elements", "flags"):
259261
features_by_type = parser.filter_as_dict(
260262
flavor, additional_filter_func=additional_filter_func
261263
)
262264

263265
if output_type == "platform":
264266
print(features_by_type["platform"][0])
267+
if output_type == "platforms":
268+
print(",".join(features_by_type["platform"]))
265269
elif output_type == "elements":
266270
print(",".join(features_by_type["element"]))
267271
elif output_type == "flags":
@@ -290,12 +294,6 @@ def additional_filter_func(node):
290294
print(cname)
291295
elif output_type == "container_name":
292296
print(RE_CAMEL_CASE_SPLITTER.sub("\\1_\\2", cname_base).lower())
293-
elif output_type == "platform":
294-
print(features_by_type["platform"][0])
295-
elif output_type == "elements":
296-
print(",".join(features_by_type["element"]))
297-
elif output_type == "flags":
298-
print(",".join(features_by_type["flag"]))
299297
elif output_type == "graph":
300298
print(graph_as_mermaid_markup(flavor, graph))
301299

@@ -328,6 +326,8 @@ def print_output_from_cname(output_type: str, cname_instance: CName) -> None:
328326
elif output_type == "container_name":
329327
print(RE_CAMEL_CASE_SPLITTER.sub("\\1-\\2", cname_instance.flavor).lower())
330328
elif output_type == "platform":
329+
print(cname_instance.platform)
330+
elif output_type == "platforms":
331331
print(cname_instance.feature_set_platform)
332332
elif output_type == "elements":
333333
print(cname_instance.feature_set_element)

src/gardenlinux/features/cname.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, cname, arch=None, commit_hash=None, version=None):
5151
self._commit_id = None
5252
self._feature_elements_cached = None
5353
self._feature_flags_cached = None
54-
self._feature_platform_cached = None
54+
self._feature_platforms_cached = None
5555
self._feature_set_cached = None
5656
self._platform_variant_cached = None
5757

@@ -239,10 +239,10 @@ def feature_set_platform(self) -> str:
239239
:since: 1.0.0
240240
"""
241241

242-
if self._feature_platform_cached is not None:
243-
return self._feature_platform_cached
244-
245-
platforms = Parser().filter_as_dict(self.flavor)["platform"]
242+
if self._feature_platforms_cached is None:
243+
platforms = Parser().filter_as_dict(self.flavor)["platform"]
244+
else:
245+
platforms = self._feature_platforms_cached
246246

247247
if self._flag_multiple_platforms:
248248
return ",".join(platforms)
@@ -260,7 +260,15 @@ def platform(self) -> str:
260260
:since: 0.7.0
261261
"""
262262

263-
return self.feature_set_platform
263+
if self._feature_platforms_cached is None:
264+
platforms = Parser().filter_as_dict(self.flavor)["platform"]
265+
else:
266+
platforms = self._feature_platforms_cached
267+
268+
if not self._flag_multiple_platforms:
269+
assert len(platforms) < 2
270+
271+
return platforms[0]
264272

265273
@property
266274
def platform_variant(self) -> Optional[str]:
@@ -306,7 +314,8 @@ def release_metadata_string(self) -> str:
306314

307315
elements = ",".join(features["element"])
308316
flags = ",".join(features["flag"])
309-
platform = ",".join(features["platform"])
317+
platform = features["platform"][0]
318+
platforms = ",".join(features["platform"])
310319
platform_variant = self.platform_variant
311320

312321
if platform_variant is None:
@@ -323,9 +332,10 @@ def release_metadata_string(self) -> str:
323332
BUG_REPORT_URL="{GL_BUG_REPORT_URL}"
324333
GARDENLINUX_CNAME="{self.cname}"
325334
GARDENLINUX_FEATURES="{self.feature_set}"
326-
GARDENLINUX_FEATURES_PLATFORM="{platform}"
335+
GARDENLINUX_FEATURES_PLATFORMS="{platforms}"
327336
GARDENLINUX_FEATURES_ELEMENTS="{elements}"
328337
GARDENLINUX_FEATURES_FLAGS="{flags}"
338+
GARDENLINUX_PLATFORM="{platform}"
329339
GARDENLINUX_PLATFORM_VARIANT="{platform_variant}"
330340
GARDENLINUX_VERSION="{self.version}"
331341
GARDENLINUX_COMMIT_ID="{self.commit_id}"
@@ -384,7 +394,7 @@ def load_from_release_file(self, release_file: PathLike | str) -> None:
384394
"GARDENLINUX_FEATURES",
385395
"GARDENLINUX_FEATURES_ELEMENTS",
386396
"GARDENLINUX_FEATURES_FLAGS",
387-
"GARDENLINUX_FEATURES_PLATFORM",
397+
"GARDENLINUX_FEATURES_PLATFORMS",
388398
"GARDENLINUX_VERSION",
389399
):
390400
if not release_config.has_option(UNNAMED_SECTION, release_field):
@@ -439,9 +449,11 @@ def load_from_release_file(self, release_file: PathLike | str) -> None:
439449
.split(",")
440450
)
441451

442-
self._feature_platform_cached = release_config.get(
443-
UNNAMED_SECTION, "GARDENLINUX_FEATURES_PLATFORM"
444-
).strip("\"'")
452+
self._feature_platforms_cached = (
453+
release_config.get(UNNAMED_SECTION, "GARDENLINUX_FEATURES_PLATFORMS")
454+
.strip("\"'")
455+
.split(",")
456+
)
445457

446458
if release_config.has_option(UNNAMED_SECTION, "GARDENLINUX_PLATFORM_VARIANT"):
447459
self._platform_variant_cached = release_config.get(

tests/features/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ def generate_container_amd64_release_metadata(version, commit_hash):
1919
BUG_REPORT_URL="{GL_BUG_REPORT_URL}"
2020
GARDENLINUX_CNAME="container-amd64-{version}-{commit_hash}"
2121
GARDENLINUX_FEATURES="_slim,base,container"
22-
GARDENLINUX_FEATURES_PLATFORM="container"
22+
GARDENLINUX_FEATURES_PLATFORMS="container"
2323
GARDENLINUX_FEATURES_ELEMENTS="base"
2424
GARDENLINUX_FEATURES_FLAGS="_slim"
25+
GARDENLINUX_PLATFORM="container"
2526
GARDENLINUX_PLATFORM_VARIANT=""
2627
GARDENLINUX_VERSION="{version}"
2728
GARDENLINUX_COMMIT_ID="{commit_hash}"

tests/s3/test_s3_artifacts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
from gardenlinux.s3.s3_artifacts import S3Artifacts
1010

1111
RELEASE_DATA = """
12-
GARDENLINUX_CNAME = container-amd64-1234.1-abc123
13-
GARDENLINUX_VERSION = 1234.1
14-
GARDENLINUX_COMMIT_ID = abc123
15-
GARDENLINUX_COMMIT_ID_LONG = abc123long
16-
GARDENLINUX_FEATURES = _usi,_trustedboot
17-
GARDENLINUX_FEATURES_ELEMENTS =
18-
GARDENLINUX_FEATURES_FLAGS = _usi,_trustedboot
19-
GARDENLINUX_FEATURES_PLATFORM = container
12+
GARDENLINUX_CNAME="container-amd64-1234.1-abc123"
13+
GARDENLINUX_VERSION=1234.1
14+
GARDENLINUX_COMMIT_ID="abc123"
15+
GARDENLINUX_COMMIT_ID_LONG="abc123long"
16+
GARDENLINUX_FEATURES="_usi,_trustedboot"
17+
GARDENLINUX_FEATURES_ELEMENTS=
18+
GARDENLINUX_FEATURES_FLAGS="_usi,_trustedboot"
19+
GARDENLINUX_FEATURES_PLATFORMS="container"
2020
"""
2121

2222

0 commit comments

Comments
 (0)