From ac273f0a3186e759b4a0af86c0d7299e7786e826 Mon Sep 17 00:00:00 2001 From: "Erich(Renyong) Wang" Date: Wed, 17 Jun 2020 13:25:14 +0800 Subject: [PATCH] update test cases --- .../tests/ComputeClientBase.cs | 4 ++ .../Helpers/ComputeManagementTestUtilities.cs | 14 +----- .../ScenarioTests/AvailabilitySetTests.cs | 4 +- .../tests/ScenarioTests/GalleryTests.cs | 24 +++++----- .../tests/ScenarioTests/HelpersTests.cs | 44 ------------------- .../tests/ScenarioTests/VMTestBase.cs | 1 - .../VMScaleSetNetworkProfileTests.cs | 30 ++++--------- .../VMScaleSetOperationalTests.cs | 26 +++-------- .../VMScaleSetVMOperationalTests.cs | 40 +++++++---------- 9 files changed, 47 insertions(+), 140 deletions(-) delete mode 100644 sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/HelpersTests.cs diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs index 18211617fcf6..237e01528db2 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/ComputeClientBase.cs @@ -20,6 +20,10 @@ namespace Azure.ResourceManager [NonParallelizable] public abstract class ComputeClientBase : ManagementRecordedTestBase { + protected string LocationEastUs2 = "EastUS2"; + protected string LocationSouthAsia = "southeastasia"; + protected string LocationWestCentralUs = "westcentralus"; + public ResourceGroupsOperations ResourceGroupsOperations { get; set; } public ProvidersOperations ProvidersOperations { get; set; } public DeploymentsOperations DeploymentsOperations { get; set; } diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/Helpers/ComputeManagementTestUtilities.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/Helpers/ComputeManagementTestUtilities.cs index 79f6592262ef..57e2c346fb91 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/Helpers/ComputeManagementTestUtilities.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/Helpers/ComputeManagementTestUtilities.cs @@ -3,20 +3,8 @@ namespace Azure.ResourceManager.Compute.Tests { - public class ComputeManagementTestUtilities : ComputeClientBase + public class ComputeManagementTestUtilities { - public ComputeManagementTestUtilities(bool isAsync) - : base(isAsync) - { - } - public static string DefaultLocations = "southeastasia"; - - public string GenerateName(string prefix = null, - [System.Runtime.CompilerServices.CallerMemberName] - string methodName="GenerateName_failed") - { - return Recording.GetVariable(methodName, prefix); - } } } diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/AvailabilitySetTests.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/AvailabilitySetTests.cs index 06b2f95ac15e..02a9bfbaa119 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/AvailabilitySetTests.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/AvailabilitySetTests.cs @@ -59,9 +59,7 @@ public async Task CleanupResourceGroup() [Test] public async Task TestOperations() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "westcentralus"); - EnsureClientsInitialized(false); + EnsureClientsInitialized(LocationWestCentralUs); await Initialize(); // Attempt to Create Availability Set with out of bounds FD and UD values await VerifyInvalidFDUDValuesFail(); diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/GalleryTests.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/GalleryTests.cs index d3bd14fa8ed8..69a0b91359b1 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/GalleryTests.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/GalleryTests.cs @@ -21,8 +21,8 @@ public class GalleryTests : VMTestBase public GalleryTests(bool isAsync) : base(isAsync) { - computeManagementTestUtilities = new ComputeManagementTestUtilities(isAsync); } + [SetUp] public void ClearChallengeCacheforRecord() { @@ -48,7 +48,7 @@ public async Task CleanupResourceGroup() [Test] public async Task Gallery_CRUD_Tests() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(galleryHomeLocation); string rgName = Recording.GenerateAssetName(ResourceGroupPrefix); string rgName2 = rgName + "New"; @@ -75,7 +75,7 @@ public async Task Gallery_CRUD_Tests() string galleryName2 = galleryName + "New"; await ResourceGroupsOperations.CreateOrUpdateAsync(rgName2, new ResourceGroup(galleryHomeLocation)); Trace.TraceInformation("Created the resource group: " + rgName2); - computeManagementTestUtilities.WaitSeconds(10); + WaitSeconds(10); await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName2, galleryName2, galleryIn)); Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName2, rgName2)); List listGalleriesInRgResult = await (GalleriesOperations.ListByResourceGroupAsync(rgName)).ToEnumerableAsync(); @@ -97,7 +97,7 @@ public async Task Gallery_CRUD_Tests() [Test] public async Task GalleryImage_CRUD_Tests() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(galleryHomeLocation); string rgName = Recording.GenerateAssetName(ResourceGroupPrefix); await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(galleryHomeLocation)); @@ -142,9 +142,7 @@ public async Task GalleryImage_CRUD_Tests() [Test] public async Task GalleryImageVersion_CRUD_Tests() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", galleryHomeLocation); - EnsureClientsInitialized(false); + EnsureClientsInitialized(galleryHomeLocation); string rgName = Recording.GenerateAssetName(ResourceGroupPrefix); VirtualMachine vm = null; string imageName = Recording.GenerateAssetName("psTestSourceImage"); @@ -206,7 +204,7 @@ await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartCreateOrU Trace.TraceInformation(string.Format("Deleted the gallery image version: {0} in gallery image: {1}", galleryImageVersionName, galleryImageName)); - computeManagementTestUtilities.WaitMinutes(5); + this.WaitMinutes(5); await WaitForCompletionAsync(await ImagesOperations.StartDeleteAsync(rgName, imageName)); Trace.TraceInformation("Deleted the CRP image."); await WaitForCompletionAsync(await VirtualMachinesOperations.StartDeleteAsync(rgName, vm.Name)); @@ -222,8 +220,8 @@ await WaitForCompletionAsync(await GalleryImageVersionsOperations.StartCreateOrU [Test] public async Task GalleryApplication_CRUD_Tests() { - string location = ComputeManagementTestUtilities.DefaultLocations; - EnsureClientsInitialized(true); + string location = LocationSouthAsia; + EnsureClientsInitialized(location); string rgName = Recording.GenerateAssetName(ResourceGroupPrefix); await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(location)); @@ -264,10 +262,8 @@ public async Task GalleryApplication_CRUD_Tests() [Ignore("need to be skipped")] public async Task GalleryApplicationVersion_CRUD_Tests() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - string location = computeManagementTestUtilities.DefaultLocation; - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", location); - EnsureClientsInitialized(false); + string location = LocationSouthAsia; + EnsureClientsInitialized(LocationSouthAsia); string rgName = Recording.GenerateAssetName(ResourceGroupPrefix); string applicationName = Recording.GenerateAssetName("psTestSourceApplication"); string galleryName = Recording.GenerateAssetName(GalleryNamePrefix); diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/HelpersTests.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/HelpersTests.cs deleted file mode 100644 index 57d52a81d845..000000000000 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/HelpersTests.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Threading.Tasks; -using Azure.Core.TestFramework; -using NUnit.Framework; - -namespace Azure.ResourceManager.Compute.Tests -{ - [AsyncOnly] - public class HelpersTests :ComputeClientBase - { - public HelpersTests(bool isAsync) - : base(isAsync) - { - } - - [SetUp] - public void ClearChallengeCacheforRecord() - { - if (Mode == RecordedTestMode.Record || Mode == RecordedTestMode.Playback) - { - InitializeBase(); - } - } - - [TearDown] - public async Task CleanupResourceGroup() - { - await CleanupResourceGroupsAsync(); - } - - [Test] - public void TestUtilityFunctions() - { - Assert.AreEqual("Azure.ResourceManager.Compute.Tests.HelpersTests", this.GetType().FullName); -#if NET46 - Assert.Equal("TestUtilityFunctions", TestUtilities.GetCurrentMethodName(1)); -#else - //Assert.AreEqual("TestUtilityFunctions", TestUtilities.GetCurrentMethodName()); -#endif - } - } -} diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/VMTestBase.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/VMTestBase.cs index 6feaa8ececbc..b6abb8d01faa 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/VMTestBase.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/ScenarioTests/VMTestBase.cs @@ -26,7 +26,6 @@ public class VMTestBase : ComputeClientBase public VMTestBase(bool isAsync) : base(isAsync) { - computeManagementTestUtilities = new ComputeManagementTestUtilities(isAsync); } protected const string TestPrefix = "crptestar"; protected const string PLACEHOLDER = "[PLACEHOLDEr1]"; diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetNetworkProfileTests.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetNetworkProfileTests.cs index 1867f4ffbfa8..479707211614 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetNetworkProfileTests.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetNetworkProfileTests.cs @@ -24,7 +24,7 @@ public VMScaleSetNetworkProfileTests(bool isAsync) [Test] public async Task TestVMScaleSetWithApplciationGateway() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationSouthAsia); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); @@ -71,7 +71,7 @@ public async Task TestVMScaleSetWithApplciationGateway() [Test] public async Task TestVMScaleSetWithDnsSettings() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationSouthAsia); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); @@ -126,8 +126,6 @@ public async Task TestVMScaleSetWithDnsSettings() [Test] public async Task TestVMScaleSetWithPublicIP() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); @@ -140,8 +138,7 @@ public async Task TestVMScaleSetWithPublicIP() // This is because NRP is still deploying to other regions and is not available worldwide. // Before changing the default location, we have to save it to be reset it at the end of the test. // Since ComputeManagementTestUtilities.DefaultLocation is a static variable and can affect other tests if it is not reset. - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "westcentralus"); - EnsureClientsInitialized(false); + EnsureClientsInitialized(LocationWestCentralUs); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -182,8 +179,6 @@ public async Task TestVMScaleSetWithPublicIP() [Ignore("this case should be tested by compute team because of ex '[4:46 PM] Lipeng You (Wicresoft North America Ltd)'message': 'Subscription /subscriptions/c9cbd920-c00c-427c-852b-8aaf38badaeb/resourceGroups//providers/Microsoft.Network/subscriptions/ is not registered for feature Microsoft.Network/AllowBringYourOwnPublicIpAddress required to carry out the requested operation.'")] public async Task TestVMScaleSetWithPublicIPAndIPTags() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); @@ -195,8 +190,7 @@ public async Task TestVMScaleSetWithPublicIPAndIPTags() // This is because NRP is still deploying to other regions and is not available worldwide. // Before changing the default location, we have to save it to be reset it at the end of the test. // Since ComputeManagementTestUtilities.DefaultLocation is a static variable and can affect other tests if it is not reset. - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "westcentralus"); - EnsureClientsInitialized(false); + EnsureClientsInitialized(LocationWestCentralUs); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -249,12 +243,6 @@ public async Task TestVMScaleSetWithPublicIPAndIPTags() [Test] public async Task TestVMScaleSetWithPublicIPAndPublicIPPrefix() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - if (originalTestLocation == null) - { - originalTestLocation = String.Empty; - } - // Create resource group string rgName = Recording.GenerateAssetName(TestPrefix) + 1; var vmssName = Recording.GenerateAssetName("vmss"); @@ -263,7 +251,7 @@ public async Task TestVMScaleSetWithPublicIPAndPublicIPPrefix() VirtualMachineScaleSet inputVMScaleSet; bool passed = false; - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationWestCentralUs); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -307,7 +295,7 @@ public async Task TestVMScaleSetWithPublicIPAndPublicIPPrefix() [Test] public async Task TestVMScaleSetWithnNsg() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationSouthAsia); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); @@ -360,7 +348,7 @@ public async Task TestVMScaleSetWithnNsg() [Test] public async Task TestVMScaleSetWithnIpv6() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationSouthAsia); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); @@ -410,7 +398,7 @@ public async Task TestVMScaleSetWithnIpv6() [Test] public async Task TestVMSSWithMultiCA() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationWestCentralUs); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); @@ -461,7 +449,7 @@ public async Task TestVMSSWithMultiCA() [Test] public async Task TestVMSSAccelNtwkng() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationWestCentralUs); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetOperationalTests.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetOperationalTests.cs index 1f779763cad4..5a6fb7eae06d 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetOperationalTests.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetOperationalTests.cs @@ -57,7 +57,7 @@ public async Task TestVMScaleSetOperations_ManagedDisks() private async Task TestVMScaleSetOperationsInternal(bool hasManagedDisks = false) { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationEastUs2); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); @@ -97,16 +97,13 @@ private async Task TestVMScaleSetOperationsInternal(bool hasManagedDisks = false [Test] public async Task TestVMScaleSetOperations_Redeploy() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - string rgName = Recording.GenerateAssetName(TestPrefix) + 1; string vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "EastUS2"); - EnsureClientsInitialized(false); + EnsureClientsInitialized(LocationEastUs2); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -139,7 +136,7 @@ public async Task TestVMScaleSetOperations_PowerOffWithSkipShutdown() VirtualMachineScaleSet inputVMScaleSet; bool passed = false; - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationEastUs2); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -158,8 +155,6 @@ public async Task TestVMScaleSetOperations_PowerOffWithSkipShutdown() [Test] public async Task TestVMScaleSetOperations_PerformMaintenance() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - string rgName = Recording.GenerateAssetName(TestPrefix) + 1; string vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); @@ -170,8 +165,7 @@ public async Task TestVMScaleSetOperations_PerformMaintenance() try { - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "EastUS2"); - EnsureClientsInitialized(false); + EnsureClientsInitialized(LocationEastUs2); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -214,7 +208,7 @@ public async Task TestVMScaleSetOperations_PerformMaintenance() [Test] public async Task TestVMScaleSetBatchOperations() { - EnsureClientsInitialized(true); + EnsureClientsInitialized(LocationSouthAsia); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); @@ -262,16 +256,13 @@ public async Task TestVMScaleSetBatchOperations() [Test] public async Task TestVMScaleSetBatchOperations_Redeploy() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - string rgName = Recording.GenerateAssetName(TestPrefix) + 1; string vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); VirtualMachineScaleSet inputVMScaleSet; bool passed = false; - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "EastUS2"); - EnsureClientsInitialized(false); + EnsureClientsInitialized(LocationEastUs2); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -292,8 +283,6 @@ public async Task TestVMScaleSetBatchOperations_Redeploy() [Test] public async Task TestVMScaleSetBatchOperations_PerformMaintenance() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - string rgName = Recording.GenerateAssetName(TestPrefix) + 1; string vmssName = Recording.GenerateAssetName("vmss"); string storageAccountName = Recording.GenerateAssetName(TestPrefix); @@ -303,8 +292,7 @@ public async Task TestVMScaleSetBatchOperations_PerformMaintenance() bool passed = false; try { - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "EastUS2"); - EnsureClientsInitialized(false); + EnsureClientsInitialized(LocationEastUs2); ImageReference imageRef = await GetPlatformVMImage(useWindowsImage: true); StorageAccount storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); diff --git a/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetVMOperationalTests.cs b/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetVMOperationalTests.cs index a3371b084961..581d485ef9b7 100644 --- a/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetVMOperationalTests.cs +++ b/sdk/compute/Azure.ResourceManager.Compute/tests/VMScaleSetTests/VMScaleSetVMOperationalTests.cs @@ -22,10 +22,8 @@ public VMScaleSetVMOperationalTests(bool isAsync) private ImageReference imageRef; private VirtualMachineScaleSet inputVMScaleSet; - private async void InitializeCommon(bool useDefaultLocation) + private async void InitializeCommon() { - EnsureClientsInitialized(useDefaultLocation); - imageRef = await GetPlatformVMImage(useWindowsImage: true); rgName = Recording.GenerateAssetName(TestPrefix) + 1; vmssName = Recording.GenerateAssetName("vmss"); @@ -52,7 +50,8 @@ private async void InitializeCommon(bool useDefaultLocation) [Test] public async Task TestVMScaleSetVMOperations() { - await TestVMScaleSetVMOperationsInternal(true, false); + EnsureClientsInitialized(LocationSouthAsia); + await TestVMScaleSetVMOperationsInternal(false); } /// @@ -77,12 +76,13 @@ public async Task TestVMScaleSetVMOperations() [Test] public async Task TestVMScaleSetVMOperations_ManagedDisks() { - await TestVMScaleSetVMOperationsInternal(true, true); + EnsureClientsInitialized(LocationSouthAsia); + await TestVMScaleSetVMOperationsInternal(true); } - private async Task TestVMScaleSetVMOperationsInternal(bool useDefaultLocation, bool hasManagedDisks = false) + private async Task TestVMScaleSetVMOperationsInternal(bool hasManagedDisks = false) { - InitializeCommon(useDefaultLocation); + InitializeCommon(); instanceId = "0"; bool passed = false; @@ -150,7 +150,8 @@ private async Task TestVMScaleSetVMOperationsInternal(bool useDefaultLocation, b [Test] public async Task TestVMScaleSetVMOperations_RunCommand() { - InitializeCommon(false); + EnsureClientsInitialized(LocationSouthAsia); + InitializeCommon(); instanceId = "0"; bool passed = false; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -185,10 +186,9 @@ public async Task TestVMScaleSetVMOperations_RunCommand() [Ignore("this case need to be tested by compute team")] public async Task TestVMScaleSetVMOperations_Put() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); bool passed = false; - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "westus2"); - InitializeCommon(true); + EnsureClientsInitialized("westus2"); + InitializeCommon(); instanceId = "0"; var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); @@ -205,7 +205,6 @@ public async Task TestVMScaleSetVMOperations_Put() VirtualMachineScaleSetVM vmssVMReturned = (await WaitForCompletionAsync(await VirtualMachineScaleSetVMsOperations.StartUpdateAsync(rgName, vmScaleSet.Name, vmssVM.InstanceId, vmssVM))).Value; ValidateVMScaleSetVM(vmScaleSetVMModel, vmScaleSet.Sku.Name, vmssVMReturned, hasManagedDisks: true); passed = true; - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); Assert.True(passed); } @@ -219,13 +218,11 @@ public async Task TestVMScaleSetVMOperations_Put() [Test] public async Task TestVMScaleSetVMOperations_Redeploy() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - + EnsureClientsInitialized(LocationEastUs2); instanceId = "0"; bool passed = false; - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "EastUS2"); - InitializeCommon(true); + InitializeCommon(); var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, @@ -235,7 +232,6 @@ public async Task TestVMScaleSetVMOperations_Redeploy() await VirtualMachineScaleSetVMsOperations.StartRedeployAsync(rgName, vmScaleSet.Name, instanceId); passed = true; - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); Assert.True(passed); } @@ -249,8 +245,7 @@ public async Task TestVMScaleSetVMOperations_Redeploy() [Test] public async Task TestVMScaleSetVMOperations_PerformMaintenance() { - string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION"); - + EnsureClientsInitialized(LocationEastUs2); instanceId = "0"; VirtualMachineScaleSet vmScaleSet = null; @@ -258,8 +253,7 @@ public async Task TestVMScaleSetVMOperations_PerformMaintenance() try { - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "EastUS2"); - InitializeCommon(true); + InitializeCommon(); var storageAccountOutput = await CreateStorageAccount(rgName, storageAccountName); var getTwoVirtualMachineScaleSet = await CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageRef, @@ -278,10 +272,6 @@ public async Task TestVMScaleSetVMOperations_PerformMaintenance() "since the Subscription of this VM is not eligible."; Assert.IsTrue(cex.Message.Contains(expectedMessage)); } - finally - { - Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation); - } Assert.True(passed); }