Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharedImageGalleryTransformer: Take marketplace features #3643

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lisa/sut_orchestrator/azure/common.py
Original file line number Diff line number Diff line change
@@ -2481,7 +2481,7 @@ def check_or_create_gallery_image(
gallery_image_osstate: str,
gallery_image_hyperv_generation: int,
gallery_image_architecture: str,
gallery_image_securitytype: str,
gallery_image_features: Dict[str, Any],
) -> None:
try:
compute_client = get_compute_client(platform)
@@ -2513,12 +2513,13 @@ def check_or_create_gallery_image(
],
}

if gallery_image_securitytype:
if gallery_image_features:
image_post_body["features"] = [
{
"name": "SecurityType",
"value": gallery_image_securitytype,
"name": key,
"value": value,
}
for (key, value) in gallery_image_features.items()
]
operation = compute_client.gallery_images.begin_create_or_update(
gallery_resource_group_name,
42 changes: 41 additions & 1 deletion lisa/sut_orchestrator/azure/transformers.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@

from .common import (
AZURE_SHARED_RG_NAME,
AzureNodeSchema,
check_blob_exist,
check_or_create_gallery,
check_or_create_gallery_image,
@@ -565,6 +566,10 @@ class SigTransformerSchema(schema.Transformer):
),
),
)
# Marketplace image to take features from.
# Will override gallery_image_architecture,
# gallery_image_hyperv_generation, and gallery_image_securitytype
marketplace_source: str = field(default="")


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

# Get features from marketplace image if specified
features = self._get_image_features(platform, runbook.marketplace_source)
if features:
runbook.gallery_image_hyperv_generation = features.pop(
"hyper_v_generation", runbook.gallery_image_hyperv_generation
)
runbook.gallery_image_architecture = features.pop(
"architecture", runbook.gallery_image_architecture
)
elif runbook.gallery_image_securitytype:
features = {"SecurityType": runbook.gallery_image_securitytype}

(
gallery_image_publisher,
gallery_image_offer,
@@ -643,7 +660,7 @@ def _internal_run(self) -> Dict[str, Any]:
runbook.gallery_image_osstate,
runbook.gallery_image_hyperv_generation,
runbook.gallery_image_architecture,
runbook.gallery_image_securitytype,
features,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property bag style parameters are not validated by schema, it's hard to find out supported values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not passed in through the schema, it is collected automatically from the marketplace image. I believe all feature values for a marketplace image are supported for a SIG image.

)

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

self._log.info(f"SIG Url: {sig_url}")
return {self.__sig_name: sig_url}

def _get_image_features(
self, platform: AzurePlatform, marketplace: str
) -> Dict[str, Any]:
if not marketplace:
return {}
node_schema = AzureNodeSchema(marketplace_raw=marketplace)
if not node_schema.marketplace:
return {}
features = node_schema.marketplace._get_info(platform)

# Convert hyper_v_generation to int from form "V1", "V2"
if (
features.get("hyper_v_generation", None)
and features["hyper_v_generation"].strip("V").isdigit()
):
features["hyper_v_generation"] = int(
features["hyper_v_generation"].strip("V")
)
else:
features.pop("hyper_v_generation", None)

return features
Loading
Oops, something went wrong.