Skip to content

Commit 863c23f

Browse files
committed
Azure: Fix bug on update_skus
This commit fixes the decision criteria to return the existing SKUs instead of creating new ones on `update_skus`. The old command was trying to infer the number of the disk images for each version, which is not the correct way of doing this nor was properly working. The new criteria is the following: 1. The private method _all_skus_present will evaluate which image types are already declared in the SKUs 2. If there's a disk versino which contains an image which declares a type not already present in the SKUs it will return `False`, indicating the need to generate the new SKUs and `True` otherwise. Refers to SPSTRAT-514 Signed-off-by: Jonathan Gangi <[email protected]>
1 parent 1dca922 commit 863c23f

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

cloudpub/ms_azure/utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,16 @@ def prepare_vm_images(
262262
return [VMImageDefinition.from_json(json_gen1)]
263263

264264

265-
def _len_vm_images(disk_versions: List[DiskVersion]) -> int:
266-
count = 0
267-
for disk_version in disk_versions:
268-
count = count + len(disk_version.vm_images)
269-
return count
265+
def _all_skus_present(old_skus: List[VMISku], disk_versions: List[DiskVersion]) -> bool:
266+
image_types = set()
267+
for sku in old_skus:
268+
image_types.add(sku.image_type)
269+
270+
for dv in disk_versions:
271+
for img in dv.vm_images:
272+
if img.image_type not in image_types:
273+
return False
274+
return True
270275

271276

272277
def _build_skus(
@@ -352,7 +357,7 @@ def update_skus(
352357

353358
# If we have SKUs for each image we don't need to update them as they're already
354359
# properly set.
355-
if len(old_skus) == _len_vm_images(disk_versions):
360+
if _all_skus_present(old_skus, disk_versions):
356361
return old_skus
357362

358363
# Update SKUs to create the alternate gen.

tests/ms_azure/test_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,34 @@ def test_update_existing_skus_arm64_single(
484484
]
485485
]
486486

487+
@pytest.mark.parametrize("generation", ["V1", "V2"])
488+
def test_update_skus_return_existing_unconventional_naming(
489+
self,
490+
generation: str,
491+
technical_config_obj: VMIPlanTechConfig,
492+
) -> None:
493+
"""Ensure the existing SKUs are returned even if they doesn't present expected namings."""
494+
skus = [
495+
VMISku.from_json(x)
496+
for x in [
497+
{"imageType": "x64Gen2", "skuId": "differentNaming"},
498+
{"imageType": "x64Gen1", "skuId": "gen1GotDifferentNaming"},
499+
]
500+
]
501+
res = update_skus(
502+
disk_versions=technical_config_obj.disk_versions,
503+
generation=generation,
504+
plan_name="plan1",
505+
old_skus=skus,
506+
)
507+
assert res == [
508+
VMISku.from_json(x)
509+
for x in [
510+
{"imageType": "x64Gen2", "skuId": "differentNaming", "securityType": None},
511+
{"imageType": "x64Gen1", "skuId": "gen1GotDifferentNaming"},
512+
]
513+
]
514+
487515
def test_create_disk_version_from_scratch_x86(
488516
self,
489517
disk_version_obj: DiskVersion,

0 commit comments

Comments
 (0)