Skip to content

Commit 8fea0e7

Browse files
committed
SharedImageGalleryTransformer: Take marketplace features
If a SIG is created from a marketplace image, you can provide the source image instead of specifying all of the features, hyper-v gen, and architecture individually.
1 parent 40c5a99 commit 8fea0e7

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

lisa/sut_orchestrator/azure/common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ def check_or_create_gallery_image(
24802480
gallery_image_osstate: str,
24812481
gallery_image_hyperv_generation: int,
24822482
gallery_image_architecture: str,
2483-
gallery_image_securitytype: str,
2483+
gallery_image_features: Dict[str, Any],
24842484
) -> None:
24852485
try:
24862486
compute_client = get_compute_client(platform)
@@ -2512,12 +2512,13 @@ def check_or_create_gallery_image(
25122512
],
25132513
}
25142514

2515-
if gallery_image_securitytype:
2515+
if gallery_image_features:
25162516
image_post_body["features"] = [
25172517
{
2518-
"name": "SecurityType",
2519-
"value": gallery_image_securitytype,
2518+
"name": key,
2519+
"value": value,
25202520
}
2521+
for (key, value) in gallery_image_features.items()
25212522
]
25222523
operation = compute_client.gallery_images.begin_create_or_update(
25232524
gallery_resource_group_name,

lisa/sut_orchestrator/azure/transformers.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from .common import (
2929
AZURE_SHARED_RG_NAME,
30+
AzureNodeSchema,
3031
check_blob_exist,
3132
check_or_create_gallery,
3233
check_or_create_gallery_image,
@@ -565,6 +566,10 @@ class SigTransformerSchema(schema.Transformer):
565566
),
566567
),
567568
)
569+
# Marketplace image to take features from.
570+
# Will override gallery_image_architecture,
571+
# gallery_image_hyperv_generation, and gallery_image_securitytype
572+
marketplace_source: str = field(default="")
568573

569574

570575
class SharedGalleryImageTransformer(Transformer):
@@ -607,6 +612,18 @@ def _internal_run(self) -> Dict[str, Any]:
607612
raise_error=True,
608613
)
609614

615+
# Get features from marketplace image if specified
616+
features = self._get_image_features(platform, runbook.marketplace_source)
617+
if features:
618+
runbook.gallery_image_hyperv_generation = features.pop(
619+
"hyper_v_generation", runbook.gallery_image_hyperv_generation
620+
)
621+
runbook.gallery_image_architecture = features.pop(
622+
"architecture", runbook.gallery_image_architecture
623+
)
624+
elif runbook.gallery_image_securitytype:
625+
features = {"SecurityType": runbook.gallery_image_securitytype}
626+
610627
(
611628
gallery_image_publisher,
612629
gallery_image_offer,
@@ -643,7 +660,7 @@ def _internal_run(self) -> Dict[str, Any]:
643660
runbook.gallery_image_osstate,
644661
runbook.gallery_image_hyperv_generation,
645662
runbook.gallery_image_architecture,
646-
runbook.gallery_image_securitytype,
663+
features,
647664
)
648665

649666
check_or_create_gallery_image_version(
@@ -670,3 +687,26 @@ def _internal_run(self) -> Dict[str, Any]:
670687

671688
self._log.info(f"SIG Url: {sig_url}")
672689
return {self.__sig_name: sig_url}
690+
691+
def _get_image_features(
692+
self, platform: AzurePlatform, marketplace: str
693+
) -> Dict[str, Any]:
694+
if not marketplace:
695+
return {}
696+
node_schema = AzureNodeSchema(marketplace_raw=marketplace)
697+
if not node_schema.marketplace:
698+
return {}
699+
features = node_schema.marketplace._get_info(platform)
700+
701+
# Convert hyper_v_generation to int from form "V1", "V2"
702+
if (
703+
features.get("hyper_v_generation", None)
704+
and features["hyper_v_generation"].strip("V").isdigit()
705+
):
706+
features["hyper_v_generation"] = int(
707+
features["hyper_v_generation"].strip("V")
708+
)
709+
else:
710+
features.pop("hyper_v_generation", None)
711+
712+
return features

0 commit comments

Comments
 (0)