Skip to content

Commit 4222dba

Browse files
committed
Azure: Fix bug with security_type on ARM64
This commit fixes a bug on SKU building for Azure which prevents ARM64 images to be published. Bsically the `securityType` field may only be applied to `X86Gen2` image types when set, so this patch disables it for any different kind of image type.
1 parent 976c3d2 commit 4222dba

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

cloudpub/ms_azure/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ def get_skuid(arch):
281281
return plan_name
282282
return f"{plan_name}-{arch.lower()}"
283283

284+
def get_safe_security_type(image_type):
285+
# Arches which aren't x86Gen2 (like ARM64) doesn't work well with security type
286+
if image_type != "x64Gen2":
287+
return None
288+
return security_type
289+
284290
sku_mapping: Dict[str, str] = {}
285291
# Update the SKUs for each image in DiskVersions if needed
286292
for disk_version in disk_versions:
@@ -301,7 +307,7 @@ def get_skuid(arch):
301307

302308
# Return the expected SKUs list
303309
res = [
304-
VMISku.from_json({"image_type": k, "id": v, "security_type": security_type})
310+
VMISku.from_json({"image_type": k, "id": v, "security_type": get_safe_security_type(k)})
305311
for k, v in sku_mapping.items()
306312
]
307313
return sorted(res, key=attrgetter("id"))

tests/ms_azure/test_utils.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def test_update_existing_skus_x86_gen1_default(
379379
assert res == [
380380
VMISku.from_json(x)
381381
for x in [
382-
{"imageType": "x64Gen1", "skuId": "plan1", "securityType": ["trusted"]},
382+
{"imageType": "x64Gen1", "skuId": "plan1"},
383383
{"imageType": "x64Gen2", "skuId": "plan1-gen2", "securityType": ["trusted"]},
384384
]
385385
]
@@ -426,6 +426,40 @@ def test_update_existing_skus_x86_gen2_single(
426426
]
427427
]
428428

429+
def test_update_existing_skus_mixed_arches(
430+
self, gen1_image: Dict[str, Any], gen2_image: Dict[str, Any], arm_image: Dict[str, Any]
431+
) -> None:
432+
"""Ensure the SKUs are properly made for disk versions using x86 and ARM arches."""
433+
disk_versions = [
434+
DiskVersion.from_json(
435+
{
436+
"versionNumber": "2.0.0",
437+
"vmImages": [gen1_image, gen2_image, arm_image],
438+
"lifecycleState": "generallyAvailable",
439+
}
440+
)
441+
]
442+
skus = [
443+
VMISku.from_json(
444+
{"imageType": "x64Gen2", "skuId": "plan1", "securityType": ["trusted"]}
445+
)
446+
]
447+
res = update_skus(
448+
disk_versions=disk_versions,
449+
generation="V2",
450+
plan_name="plan1",
451+
old_skus=skus,
452+
)
453+
454+
assert res == [
455+
VMISku.from_json(x)
456+
for x in [
457+
{"imageType": "x64Gen2", "skuId": "plan1", "securityType": ["trusted"]},
458+
{"imageType": "arm64Gen2", "skuId": "plan1-arm64"},
459+
{"imageType": "x64Gen1", "skuId": "plan1-gen1"},
460+
]
461+
]
462+
429463
@pytest.mark.parametrize("generation", ["V1", "V2"])
430464
def test_update_existing_skus_arm64_single(
431465
self,

0 commit comments

Comments
 (0)