From c057307c2693d440e744702d0698a6511760ec46 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 26 Apr 2024 10:54:25 +0800 Subject: [PATCH] Support LRO rehydration for compute (#43613) --- eng/Packages.Data.props | 2 +- .../CHANGELOG.md | 8 +- .../Azure.ResourceManager.Compute/assets.json | 2 +- .../tests/Scenario/LroRehydrationTests.cs | 87 +++++++++++++++++++ .../tests/Scenario/LroRehydrationTests.cs | 10 +-- 5 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/LroRehydrationTests.cs diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index d2c94d623a7ac..975f551650cf2 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -130,7 +130,7 @@ - + diff --git a/sdk/compute/Azure.ResourceManager.Compute/CHANGELOG.md b/sdk/compute/Azure.ResourceManager.Compute/CHANGELOG.md index a7299120b5d4a..3ad20f49098f0 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/CHANGELOG.md +++ b/sdk/compute/Azure.ResourceManager.Compute/CHANGELOG.md @@ -1,15 +1,15 @@ # Release History -## 1.5.0-beta.1 (Unreleased) +## 1.5.0-beta.1 (2024-04-25) ### Features Added -### Breaking Changes - -### Bugs Fixed +- Support long-running operation rehydration. ### Other Changes +- Upgraded dependent `Azure.ResourceManager` to 1.11.1. + ## 1.4.0 (2024-02-21) ### Features Added diff --git a/sdk/compute/Azure.ResourceManager.Compute/assets.json b/sdk/compute/Azure.ResourceManager.Compute/assets.json index 4b76ec0c70562..c9374327cafb6 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/assets.json +++ b/sdk/compute/Azure.ResourceManager.Compute/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/compute/Azure.ResourceManager.Compute", - "Tag": "net/compute/Azure.ResourceManager.Compute_f8b8dc8333" + "Tag": "net/compute/Azure.ResourceManager.Compute_4ea1853447" } diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/LroRehydrationTests.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/LroRehydrationTests.cs new file mode 100644 index 0000000000000..c989f5d933b17 --- /dev/null +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/Scenario/LroRehydrationTests.cs @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Compute.Models; +using Azure.ResourceManager.Compute.Tests.Helpers; +using NUnit.Framework; + +namespace Azure.ResourceManager.Compute.Tests.Scenario +{ + [ClientTestFixture(true, "2022-08-01")] + public class LroRehydrationTests : VirtualMachineScaleSetTestBase + { + public LroRehydrationTests(bool isAsync, string apiVersion) + : base(isAsync, AvailabilitySetResource.ResourceType, apiVersion) + { + } + + [TestCase] + [RecordedTest] + public async Task CreateOrUpdate() + { + var collection = await GetVirtualMachineScaleSetCollectionAsync(); + var vmssName = Recording.GenerateAssetName("testVMSS-"); + var vnet = await CreateBasicDependenciesOfVirtualMachineScaleSetAsync(); + var input = ResourceDataHelper.GetBasicLinuxVirtualMachineScaleSetData(DefaultLocation, vmssName, GetSubnetId(vnet)); + + input.VirtualMachineProfile.ExtensionProfile = new VirtualMachineScaleSetExtensionProfile() + { + Extensions = + { + new VirtualMachineScaleSetExtensionData("TestExt") + { + AutoUpgradeMinorVersion = true, + EnableAutomaticUpgrade = false, + Settings = BinaryData.FromObjectAsJson(new {}), + ProtectedSettings = BinaryData.FromObjectAsJson(new + { + commandToExecute = $@"echo helloworld", + }), + Publisher = "Microsoft.Azure.Extensions", + ExtensionType = "CustomScript", + TypeHandlerVersion = "2.1", + } + } + }; + + ArmOperation originalLro = await collection.CreateOrUpdateAsync(WaitUntil.Started, vmssName, input); + var token = originalLro.GetRehydrationToken(); + var resourceRehydratedLro = await ArmOperation.RehydrateAsync(Client, token.Value); + await resourceRehydratedLro.WaitForCompletionAsync(); + Assert.True(resourceRehydratedLro.HasValue); + VirtualMachineScaleSetResource rehydratedResult = resourceRehydratedLro.Value; + await originalLro.UpdateStatusAsync(); + VirtualMachineScaleSetResource originalResult = originalLro.Value; + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.Sku), JsonSerializer.Serialize(rehydratedResult.Data.Sku)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.Plan), JsonSerializer.Serialize(rehydratedResult.Data.Plan)); + Assert.AreEqual(originalResult.Data.Identity, rehydratedResult.Data.Identity); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.Location), JsonSerializer.Serialize(rehydratedResult.Data.Location)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.UpgradePolicy), JsonSerializer.Serialize(rehydratedResult.Data.UpgradePolicy)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.AutomaticRepairsPolicy), JsonSerializer.Serialize(rehydratedResult.Data.AutomaticRepairsPolicy)); + Assert.AreEqual(originalResult.Data.ProvisioningState, rehydratedResult.Data.ProvisioningState); + Assert.AreEqual(originalResult.Data.Overprovision, rehydratedResult.Data.Overprovision); + Assert.AreEqual(originalResult.Data.DoNotRunExtensionsOnOverprovisionedVms, rehydratedResult.Data.DoNotRunExtensionsOnOverprovisionedVms); + Assert.AreEqual(originalResult.Data.UniqueId, rehydratedResult.Data.UniqueId); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.SinglePlacementGroup), JsonSerializer.Serialize(rehydratedResult.Data.SinglePlacementGroup)); + Assert.AreEqual(originalResult.Data.ZoneBalance, rehydratedResult.Data.ZoneBalance); + Assert.AreEqual(originalResult.Data.PlatformFaultDomainCount, rehydratedResult.Data.PlatformFaultDomainCount); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.ProximityPlacementGroup), JsonSerializer.Serialize(rehydratedResult.Data.ProximityPlacementGroup)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.HostGroup), JsonSerializer.Serialize(rehydratedResult.Data.HostGroup)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.AdditionalCapabilities), JsonSerializer.Serialize(rehydratedResult.Data.AdditionalCapabilities)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.ScaleInPolicy), JsonSerializer.Serialize(rehydratedResult.Data.ScaleInPolicy)); + Assert.AreEqual(originalResult.Data.OrchestrationMode, rehydratedResult.Data.OrchestrationMode); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.SpotRestorePolicy), JsonSerializer.Serialize(rehydratedResult.Data.SpotRestorePolicy)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.PriorityMixPolicy), JsonSerializer.Serialize(rehydratedResult.Data.PriorityMixPolicy)); + Assert.AreEqual(JsonSerializer.Serialize(originalResult.Data.TimeCreated), JsonSerializer.Serialize(rehydratedResult.Data.TimeCreated)); + Assert.AreEqual(originalResult.Data.IsMaximumCapacityConstrained, rehydratedResult.Data.IsMaximumCapacityConstrained); + + var originalResponse = originalLro.GetRawResponse(); + var rehydratedResponse = resourceRehydratedLro.GetRawResponse(); + Assert.AreEqual(originalResponse.Status, rehydratedResponse.Status); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LroRehydrationTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LroRehydrationTests.cs index 1d0518e00f121..6594be52da887 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LroRehydrationTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/LroRehydrationTests.cs @@ -37,7 +37,7 @@ public async Task FakeLroTest() var rgOp = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Started, rgName, orgData); var rgOpRehydrationToken = rgOp.GetRehydrationToken(); Assert.NotNull(rgOpRehydrationToken); - var rehydratedOrgOperation = ArmOperation.Rehydrate(Client, (RehydrationToken)rgOpRehydrationToken!); + var rehydratedOrgOperation = ArmOperation.Rehydrate(Client, rgOpRehydrationToken!.Value); var rehydratedOrgResponse = rehydratedOrgOperation.GetRawResponse(); var response = rgOp.GetRawResponse(); Assert.AreEqual((int)HttpStatusCode.Created, response.Status); @@ -52,7 +52,7 @@ public async Task FakeLroTest() var deleteResponse = deleteOp.GetRawResponse(); var deleteOpRehydrationToken = deleteOp.GetRehydrationToken(); Assert.NotNull(deleteOpRehydrationToken); - var rehydratedDeleteOperation = ArmOperation.Rehydrate(Client, (RehydrationToken)deleteOpRehydrationToken!); + var rehydratedDeleteOperation = ArmOperation.Rehydrate(Client, deleteOpRehydrationToken!.Value); var rehydatedDeleteResponse = rehydratedDeleteOperation.GetRawResponse(); Assert.AreEqual((int)HttpStatusCode.NoContent, rehydatedDeleteResponse.Status); Assert.AreEqual(HttpStatusCode.NoContent.ToString(), rehydatedDeleteResponse.ReasonPhrase); @@ -90,7 +90,7 @@ public async Task CreateDeleteResourceGroup() var originalOperation = await Client.GetResourceGroupResource(ResourceGroupResource.CreateResourceIdentifier(subscription.Id.SubscriptionId, rgName)).ExportTemplateAsync(WaitUntil.Started, parameters); var originalOperationToken = originalOperation.GetRehydrationToken(); Assert.NotNull(originalOperationToken); - var rehydratedOperation = await ArmOperation.RehydrateAsync(Client, (RehydrationToken)originalOperationToken!); + var rehydratedOperation = await ArmOperation.RehydrateAsync(Client, originalOperationToken!.Value); await rehydratedOperation.WaitForCompletionResponseAsync(); Assert.AreEqual(rehydratedOperation.HasValue, true); var rehydratedResult = rehydratedOperation.Value; @@ -109,12 +109,12 @@ public async Task CreateDeleteResourceGroup() var originalDeleteOperation = await rg.DeleteAsync(WaitUntil.Started); var originalDeleteOperationToken = originalDeleteOperation.GetRehydrationToken(); Assert.NotNull(originalDeleteOperationToken); - var rehydratedDeleteOperation = await ArmOperation.RehydrateAsync(Client, (RehydrationToken)originalDeleteOperationToken!); + var rehydratedDeleteOperation = await ArmOperation.RehydrateAsync(Client, originalDeleteOperationToken!.Value); await rehydratedDeleteOperation.WaitForCompletionResponseAsync(); Assert.AreEqual(rehydratedDeleteOperation.HasCompleted, true); var token = rehydratedDeleteOperation.GetRehydrationToken(); Assert.NotNull(token); - var deleteFinalRehydratedLro = ArmOperation.Rehydrate(Client, (RehydrationToken)token!); + var deleteFinalRehydratedLro = ArmOperation.Rehydrate(Client, token!.Value); var ex = Assert.ThrowsAsync(async () => await rg.GetAsync()); Assert.AreEqual(404, ex?.Status); Assert.AreEqual(200, deleteFinalRehydratedLro.GetRawResponse().Status);