azure: maybe fix crashing on gallery creation
Some checks failed
/ test (push) Failing after 23s

Somewhat recently, Azure images started failing to upload, crashing when
calling azure_compute_client.gallery_images.begin_create_or_update with
a server-side error of "HttpResponseError: (InvalidParameter) Required
parameter 'galleryImageVersionName' is missing (null)."

It _seems_ like it no longer allows updating a gallery image (even if
there are no actual updates happening, it just declares it as it always
was) with features that don't include a version within that gallery
where the feature is first enabled.

Signed-off-by: Jeremy Cline <jeremycline@microsoft.com>
This commit is contained in:
Jeremy Cline 2026-06-10 12:33:44 -04:00
commit cbcb72860d
No known key found for this signature in database
2 changed files with 22 additions and 2 deletions

View file

@ -4,7 +4,7 @@ import os
import tempfile
from azure import identity as az_identity
from azure.core.exceptions import AzureError, ResourceExistsError
from azure.core.exceptions import AzureError, ResourceExistsError, ResourceNotFoundError
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.compute.models import (
Architecture,
@ -112,7 +112,20 @@ class Azure:
def azure_create_image_definition(
self, image: dict, ffrel: ff_release.Release, gallery_image_name: str
):
# Ensure the Gallery Image exists
# Check if the Gallery Image definition already exists because if we pass in
# GalleryImageFeatures for a pre-existing definition, I think it wants a non-null
# `starts_at_version` on them.
try:
self.azure_compute_client.gallery_images.get(
resource_group_name=self.conf["resource_group_name"],
gallery_name=self.conf["gallery_name"],
gallery_image_name=gallery_image_name,
)
_log.info("Azure Gallery Image %s exists; importing image", gallery_image_name)
return
except ResourceNotFoundError:
pass
features = [
GalleryImageFeature(name="IsAcceleratedNetworkSupported", value="true"),
GalleryImageFeature(name="DiskControllerTypes", value="NVMe,SCSI"),

View file

@ -6,6 +6,7 @@ from datetime import timedelta
from unittest import mock
import pytest
from azure.core.exceptions import ResourceNotFoundError
from azure.mgmt.compute.models import (
GalleryImage,
GalleryImageVersion,
@ -39,6 +40,9 @@ def test_gallery_name(fixtures_dir, azure_fm_conf, azure_env_vars, compose):
consumer = Uploader()
azure_handler = consumer.handlers["azure"]
azure_handler.azure_compute_client = mock.Mock()
azure_handler.azure_compute_client.gallery_images.get.side_effect = ResourceNotFoundError(
"Not found"
)
azure_handler.azure_blob_client = mock.Mock()
azure_handler.azure_blob_client.get_blob_client.return_value.exists.return_value = True
azure_handler.azure_cleanup_images = mock.Mock()
@ -142,6 +146,9 @@ def test_azure_messages(fixtures_dir, azure_fm_conf, azure_env_vars, expected_me
consumer = Uploader()
azure_handler = consumer.handlers["azure"]
azure_handler.azure_compute_client = mock.Mock()
azure_handler.azure_compute_client.gallery_images.get.side_effect = ResourceNotFoundError(
"Not found"
)
azure_handler.azure_blob_client = mock.Mock()
azure_handler.azure_blob_client.get_blob_client.return_value.exists.return_value = True
azure_handler.azure_cleanup_images = mock.Mock()