Skip to content

Commit 8ab65b5

Browse files
Updated Set-AzAutomationModule to use PUT call while updating modules with specific versions (#16505)
* used put call * update * fix for failed test * fixing build errors * error message * Update ChangeLog.md * Update ChangeLog.md * fix * updated changelog * update
1 parent 218d3ef commit 8ab65b5

File tree

4 files changed

+58
-31
lines changed

4 files changed

+58
-31
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#### Az.Automation
3232
* Fixed example in reference doc for 'Remove-AzAutomationHybridWorkerGroup'
33+
* Updated 'Set-AzAutomationModule' to use PUT call while updating modules with specific versions [#12552]
3334

3435
#### Az.CloudService
3536
* General availability of 'Az.CloudService' module

src/Automation/Automation.Test/SessionRecords/Commands.Automation.Test.ModuleTests/SetModule.json

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@
210210
{
211211
"RequestUri": "/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/modules/Pester?api-version=2020-01-13-preview",
212212
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDIyYjZjNjEtOTViMC00MjEzLWIzYmUtNzI4MjMxNWRmNzFkL3Jlc291cmNlR3JvdXBzL3RvLWRlbGV0ZS0wMS9wcm92aWRlcnMvTWljcm9zb2Z0LkF1dG9tYXRpb24vYXV0b21hdGlvbkFjY291bnRzL2Zicy1hYS0wMS9tb2R1bGVzL1Blc3Rlcj9hcGktdmVyc2lvbj0yMDIwLTAxLTEzLXByZXZpZXc=",
213-
"RequestMethod": "PATCH",
214-
"RequestBody": "{\r\n \"properties\": {\r\n \"contentLink\": {\r\n \"uri\": \"https://devopsgallerystorage.blob.core.windows.net/packages/pester.3.0.3.nupkg\",\r\n \"version\": \"87920157-3e80-4877-97e3-95cc514a76f5\"\r\n }\r\n },\r\n \"name\": \"Pester\",\r\n \"tags\": {}\r\n}",
213+
"RequestMethod": "PUT",
214+
"RequestBody": "{\r\n \"properties\": {\r\n \"contentLink\": {\r\n \"uri\": \"https://devopsgallerystorage.blob.core.windows.net/packages/pester.3.0.3.nupkg\"\r\n }\r\n },\r\n \"name\": \"Pester\"\r\n}",
215215
"RequestHeaders": {
216216
"x-ms-client-request-id": [
217-
"b68fd72b-c8f2-4f64-b0c8-137573c6ca1b"
217+
"73c64f74-c38d-4f9f-80af-ebf709079776"
218218
],
219219
"Accept-Language": [
220220
"en-US"
221221
],
222222
"User-Agent": [
223-
"FxVersion/4.6.29916.01",
223+
"FxVersion/4.6.29812.02",
224224
"OSName/Windows",
225225
"OSVersion/Microsoft.Windows.10.0.19042.",
226226
"Microsoft.Azure.Management.Automation.AutomationClient/3.8.3.0"
@@ -229,7 +229,7 @@
229229
"application/json; charset=utf-8"
230230
],
231231
"Content-Length": [
232-
"246"
232+
"173"
233233
]
234234
},
235235
"ResponseHeaders": {
@@ -239,8 +239,17 @@
239239
"Pragma": [
240240
"no-cache"
241241
],
242+
"Location": [
243+
"https://management.azure.com/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/modules/Pester?api-version=2020-01-13-preview"
244+
],
242245
"x-ms-request-id": [
243-
"b68fd72b-c8f2-4f64-b0c8-137573c6ca1b"
246+
"73c64f74-c38d-4f9f-80af-ebf709079776"
247+
],
248+
"x-ms-location": [
249+
"https://management.azure.com/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/modules/Pester?api-version=2020-01-13-preview"
250+
],
251+
"ocp-location": [
252+
"https://management.azure.com/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/modules/Pester?api-version=2020-01-13-preview"
244253
],
245254
"Strict-Transport-Security": [
246255
"max-age=31536000; includeSubDomains"
@@ -255,22 +264,22 @@
255264
"ASP.NET"
256265
],
257266
"x-ms-ratelimit-remaining-subscription-writes": [
258-
"1196"
267+
"1199"
259268
],
260269
"x-ms-correlation-request-id": [
261-
"4e721b99-17ac-49fc-9e3e-ea629d272ec9"
270+
"515c208f-d328-4a8c-b7d3-56d82577ea4c"
262271
],
263272
"x-ms-routing-request-id": [
264-
"CENTRALINDIA:20210421T143439Z:4e721b99-17ac-49fc-9e3e-ea629d272ec9"
273+
"CENTRALINDIA:20210404T063905Z:515c208f-d328-4a8c-b7d3-56d82577ea4c"
265274
],
266275
"X-Content-Type-Options": [
267276
"nosniff"
268277
],
269278
"Date": [
270-
"Wed, 21 Apr 2021 14:34:39 GMT"
279+
"Sun, 04 Apr 2021 06:39:05 GMT"
271280
],
272281
"Content-Length": [
273-
"560"
282+
"548"
274283
],
275284
"Content-Type": [
276285
"application/json; charset=utf-8"
@@ -279,8 +288,8 @@
279288
"-1"
280289
]
281290
},
282-
"ResponseBody": "{\r\n \"id\": \"/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/modules/Pester\",\r\n \"name\": \"Pester\",\r\n \"type\": \"Microsoft.Automation/AutomationAccounts/Modules\",\r\n \"location\": \"eastus\",\r\n \"tags\": {},\r\n \"etag\": null,\r\n \"properties\": {\r\n \"isGlobal\": false,\r\n \"version\": \"3.0.3\",\r\n \"sizeInBytes\": 74921,\r\n \"activityCount\": 0,\r\n \"creationTime\": \"2021-04-21T19:27:14.4733333+05:30\",\r\n \"lastModifiedTime\": \"2021-04-21T19:29:46.1566667+05:30\",\r\n \"error\": {\r\n \"code\": null,\r\n \"message\": null\r\n },\r\n \"provisioningState\": \"Creating\",\r\n \"isComposite\": false\r\n }\r\n}",
283-
"StatusCode": 200
291+
"ResponseBody": "{\r\n \"id\": \"/subscriptions/422b6c61-95b0-4213-b3be-7282315df71d/resourceGroups/to-delete-01/providers/Microsoft.Automation/automationAccounts/fbs-aa-01/modules/Pester\",\r\n \"name\": \"Pester\",\r\n \"type\": \"Microsoft.Automation/AutomationAccounts/Modules\",\r\n \"location\": \"eastus\",\r\n \"tags\": {},\r\n \"etag\": null,\r\n \"properties\": {\r\n \"isGlobal\": false,\r\n \"version\": null,\r\n \"sizeInBytes\": 0,\r\n \"activityCount\": 0,\r\n \"creationTime\": \"2021-04-04T12:09:04.93+05:30\",\r\n \"lastModifiedTime\": \"2021-04-04T12:09:04.9633333+05:30\",\r\n \"error\": {\r\n \"code\": null,\r\n \"message\": null\r\n },\r\n \"provisioningState\": \"Creating\",\r\n \"isComposite\": false\r\n }\r\n}",
292+
"StatusCode": 201
284293
}
285294
],
286295
"Names": {},

src/Automation/Automation/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* `New-AzAutomationSchedule` allows defnining StartTime with offsets.
22+
* Fixed bug: Updated 'Set-AzAutomationModule' to use PUT call while updating modules with specific versions [#12552]
2223

2324
## Version 1.7.2
2425
* Fixed example in reference doc for `Remove-AzAutomationHybridWorkerGroup`

src/Automation/Automation/Common/AutomationPSClient.cs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -388,28 +388,44 @@ public IEnumerable<Module> ListModules(string resourceGroupName, string automati
388388
public Module UpdateModule(string resourceGroupName, string automationAccountName, string name,
389389
Uri contentLinkUri, string contentLinkVersion)
390390
{
391-
var moduleModel =
391+
try
392+
{
393+
var moduleModel =
392394
this.automationManagementClient.Module.Get(resourceGroupName, automationAccountName, name);
393-
if (contentLinkUri != null)
395+
if (contentLinkUri != null)
396+
{
397+
var updateModule = this.automationManagementClient.Module.CreateOrUpdate(resourceGroupName,
398+
automationAccountName,
399+
name,
400+
new AutomationManagement.Models.ModuleCreateOrUpdateParameters()
401+
{
402+
Name = name,
403+
ContentLink = new AutomationManagement.Models.ContentLink()
404+
{
405+
Uri = contentLinkUri.ToString(),
406+
ContentHash = null,
407+
Version =
408+
(String.IsNullOrWhiteSpace(contentLinkVersion))
409+
? Guid.NewGuid().ToString()
410+
: contentLinkVersion
411+
},
412+
});
413+
}
414+
var updatedModule =
415+
this.automationManagementClient.Module.Get(resourceGroupName, automationAccountName, name);
416+
return new Module(resourceGroupName, automationAccountName, updatedModule);
417+
}
418+
catch (ErrorResponseException cloudException)
394419
{
395-
var moduleUpdateParameters = new AutomationManagement.Models.ModuleUpdateParameters();
396-
397-
moduleUpdateParameters.Name = name;
398-
moduleUpdateParameters.ContentLink = new AutomationManagement.Models.ContentLink();
399-
moduleUpdateParameters.ContentLink.Uri = contentLinkUri.ToString();
400-
moduleUpdateParameters.ContentLink.Version =
401-
(String.IsNullOrWhiteSpace(contentLinkVersion))
402-
? Guid.NewGuid().ToString()
403-
: contentLinkVersion;
420+
if (cloudException.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
421+
{
422+
throw new ResourceNotFoundException(typeof(Module),
423+
string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, name));
404424

405-
moduleUpdateParameters.Tags = moduleModel.Tags;
425+
}
406426

407-
this.automationManagementClient.Module.Update(resourceGroupName, automationAccountName, name,
408-
moduleUpdateParameters);
409-
}
410-
var updatedModule =
411-
this.automationManagementClient.Module.Get(resourceGroupName, automationAccountName, name);
412-
return new Module(resourceGroupName, automationAccountName, updatedModule);
427+
throw;
428+
}
413429
}
414430

415431
public void DeleteModule(string resourceGroupName, string automationAccountName, string name)

0 commit comments

Comments
 (0)