From b8e905cd4d4eac9960e0d819428118cadd1d0d6f Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Thu, 19 Sep 2019 22:27:34 +0800 Subject: [PATCH] Backport/2.9/62559 (#62570) * snapshot fix for backporting (#62559) (cherry picked from commit 054519920ef792fe91b1793240989308c10c5004) * changelog fragment --- ...zure-shared-gallery-specialized-images.yml | 2 ++ .../modules/cloud/azure/azure_rm_gallery.py | 2 +- .../cloud/azure/azure_rm_galleryimage.py | 2 +- .../azure/azure_rm_galleryimageversion.py | 23 ++++++++------ .../targets/azure_rm_gallery/tasks/main.yml | 30 +++++++++---------- 5 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 changelogs/fragments/62559-fixing-azure-shared-gallery-specialized-images.yml diff --git a/changelogs/fragments/62559-fixing-azure-shared-gallery-specialized-images.yml b/changelogs/fragments/62559-fixing-azure-shared-gallery-specialized-images.yml new file mode 100644 index 00000000000..76e0dbd56b3 --- /dev/null +++ b/changelogs/fragments/62559-fixing-azure-shared-gallery-specialized-images.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix support for Specialized images in Azure Shared Image Gallery \ No newline at end of file diff --git a/lib/ansible/modules/cloud/azure/azure_rm_gallery.py b/lib/ansible/modules/cloud/azure/azure_rm_gallery.py index a29ee0d447c..9c30f3723a0 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_gallery.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_gallery.py @@ -141,7 +141,7 @@ class AzureRMGalleries(AzureRMModuleBaseExt): self.body = {} self.query_parameters = {} - self.query_parameters['api-version'] = '2019-03-01' + self.query_parameters['api-version'] = '2019-07-01' self.header_parameters = {} self.header_parameters['Content-Type'] = 'application/json; charset=utf-8' diff --git a/lib/ansible/modules/cloud/azure/azure_rm_galleryimage.py b/lib/ansible/modules/cloud/azure/azure_rm_galleryimage.py index 539a4f46d33..c5a76d94ec3 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_galleryimage.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_galleryimage.py @@ -379,7 +379,7 @@ class AzureRMGalleryImages(AzureRMModuleBaseExt): self.body = {} self.query_parameters = {} - self.query_parameters['api-version'] = '2019-03-01' + self.query_parameters['api-version'] = '2019-07-01' self.header_parameters = {} self.header_parameters['Content-Type'] = 'application/json; charset=utf-8' diff --git a/lib/ansible/modules/cloud/azure/azure_rm_galleryimageversion.py b/lib/ansible/modules/cloud/azure/azure_rm_galleryimageversion.py index 1235b97c521..b21593a9456 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_galleryimageversion.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_galleryimageversion.py @@ -215,7 +215,8 @@ class AzureRMGalleryImageVersions(AzureRMModuleBaseExt): location=dict( type='str', updatable=False, - disposition='/' + disposition='/', + comparison='location' ), publishing_profile=dict( type='dict', @@ -227,7 +228,8 @@ class AzureRMGalleryImageVersions(AzureRMModuleBaseExt): options=dict( name=dict( type='str', - required=True + required=True, + comparison='location' ), regional_replica_count=dict( type='int', @@ -244,14 +246,14 @@ class AzureRMGalleryImageVersions(AzureRMModuleBaseExt): pattern=('/subscriptions/{subscription_id}/resourceGroups' '/{resource_group}/providers/Microsoft.Compute' '/images/{name}'), - disposition='source/managedImage/id' + comparison='ignore' ), snapshot=dict( type='raw', pattern=('/subscriptions/{subscription_id}/resourceGroups' '/{resource_group}/providers/Microsoft.Compute' '/snapshots/{name}'), - disposition='source/managedImage/id' + comparison='ignore' ), replica_count=dict( type='int', @@ -295,7 +297,7 @@ class AzureRMGalleryImageVersions(AzureRMModuleBaseExt): self.body = {} self.query_parameters = {} - self.query_parameters['api-version'] = '2019-03-01' + self.query_parameters['api-version'] = '2019-07-01' self.header_parameters = {} self.header_parameters['Content-Type'] = 'application/json; charset=utf-8' @@ -363,9 +365,13 @@ class AzureRMGalleryImageVersions(AzureRMModuleBaseExt): if not self.default_compare(modifiers, self.body, old_response, '', self.results): self.to_do = Actions.Update - # fix leftovers (if empty structures were left) - self.body.get('properties', {}).get('publishingProfile', {}).pop('snapshot', None) - self.body.get('properties', {}).get('publishingProfile', {}).pop('managed_image', None) + # fix for differences between version 2019-03-01 and 2019-07-01 + snapshot = self.body.get('properties', {}).get('publishingProfile', {}).pop('snapshot', None) + if snapshot is not None: + self.body['properties'].setdefault('storageProfile', {}).setdefault('osDiskImage', {}).setdefault('source', {})['id'] = snapshot + managed_image = self.body.get('properties', {}).get('publishingProfile', {}).pop('managed_image', None) + if managed_image: + self.body['properties'].setdefault('storageProfile', {}).setdefault('source', {})['id'] = managed_image if (self.to_do == Actions.Create) or (self.to_do == Actions.Update): self.log('Need to Create / Update the GalleryImageVersion instance') @@ -393,7 +399,6 @@ class AzureRMGalleryImageVersions(AzureRMModuleBaseExt): if response: self.results["id"] = response["id"] - self.results["old_response"] = response return self.results diff --git a/test/integration/targets/azure_rm_gallery/tasks/main.yml b/test/integration/targets/azure_rm_gallery/tasks/main.yml index 91c1998d523..85f1695a682 100644 --- a/test/integration/targets/azure_rm_gallery/tasks/main.yml +++ b/test/integration/targets/azure_rm_gallery/tasks/main.yml @@ -78,7 +78,7 @@ azure_rm_gallery: resource_group: "{{ resource_group }}" name: myGallery{{ rpfx }} - location: West US + location: eastus description: This is the gallery description. register: output @@ -90,7 +90,7 @@ azure_rm_gallery: resource_group: "{{ resource_group }}" name: myGallery{{ rpfx }} - location: West US + location: eastus description: This is the gallery description. register: output @@ -102,7 +102,7 @@ azure_rm_gallery: resource_group: "{{ resource_group }}" name: myGallery{{ rpfx }} - location: West US + location: eastus description: This is the gallery description - xxx. register: output @@ -130,7 +130,7 @@ resource_group: "{{ resource_group }}" gallery_name: myGallery{{ rpfx }} name: myImage - location: West US + location: eastus os_type: linux os_state: generalized identifier: @@ -149,7 +149,7 @@ resource_group: "{{ resource_group }}" gallery_name: myGallery{{ rpfx }} name: myImage - location: West US + location: eastus os_type: linux os_state: generalized identifier: @@ -168,7 +168,7 @@ resource_group: "{{ resource_group }}" gallery_name: myGallery{{ rpfx }} name: myImage - location: West US + location: eastus os_type: linux os_state: generalized identifier: @@ -205,16 +205,16 @@ gallery_name: myGallery{{ rpfx }} gallery_image_name: myImage name: 10.1.3 - location: West US + location: eastus publishing_profile: end_of_life_date: "2020-10-01t00:00:00+00:00" exclude_from_latest: yes replica_count: 3 storage_account_type: Standard_LRS target_regions: - - name: West US + - name: eastus regional_replica_count: 1 - - name: East US + - name: westus regional_replica_count: 2 storage_account_type: Standard_ZRS managed_image: @@ -232,16 +232,16 @@ gallery_name: myGallery{{ rpfx }} gallery_image_name: myImage name: 10.1.3 - location: West US + location: eastus publishing_profile: end_of_life_date: "2020-10-01t00:00:00+00:00" exclude_from_latest: yes replica_count: 3 storage_account_type: Standard_LRS target_regions: - - name: West US + - name: eastus regional_replica_count: 1 - - name: East US + - name: westus regional_replica_count: 2 storage_account_type: Standard_ZRS managed_image: @@ -259,16 +259,16 @@ gallery_name: myGallery{{ rpfx }} gallery_image_name: myImage name: 10.1.3 - location: West US + location: eastus publishing_profile: end_of_life_date: "2021-10-01t00:00:00+00:00" exclude_from_latest: yes replica_count: 3 storage_account_type: Standard_LRS target_regions: - - name: West US + - name: eastus regional_replica_count: 1 - - name: East US + - name: westus regional_replica_count: 2 storage_account_type: Standard_ZRS managed_image: