Skip to content

Commit e1b1017

Browse files
Sandidogrizzlytheodorepavanrachapudy90Pavan Rachapudy
authored
Force Detach test (#18553)
* Delete test json files (#18003) * Delete TestVMExtensionOperations.json * Delete TestVMScaleSetExtensions.json * Resolve conflicts for -updated merge (#18015) * Update SdkInfo_ComputeManagementClient.cs * Update VirtualMachineRunCommandsOperations.cs * Update VirtualMachineScaleSetVMRunCommandsOperations.cs * Create TestVMExtensionOperations.json * Delete TestVMExtensionOperations.json * Create TestVMExtensionOperations.json * Create TestVMScaleSetExtensions.json * Compute 2020 12 updated (#17975) * adding 2020-12-01 compute generated files * update default sku * update tests * test updates * records * tests fixes * all the recorded tests * more update * more update * more update * last test fixes * Updated TestVMIdentitySystemAssignedUserAssigned SDK Test to create User Assigned Identity using SDK (#17861) * Updated TestVMIdentitySystemAssignedUserAssigned SDK Test to create User Assigned MI using MSI SDK * Resolved Merge Conflicts and updated the test Co-authored-by: Pavan Rachapudy <[email protected]> * Delete AppGW tests (#17977) * Delete VMScaleSetAppGwWithAS.json * Delete VMScaleSetAppGwWithAS_A1V2.json * Delete VMScaleSetAppGwWithAS_SPG_False.json * Delete VMScaleSetAppGwWithAS_Spot.json * Delete VMScaleSetAppGWTests.cs * Delete deprecated ContainerService tests (#17976) * Delete ContainerServiceOperationalTests.cs * Delete ContainerServiceTestsBase.cs * Delete ContainerServiceUpdateTests.cs * Delete TestDCOSOperations.json * Delete TestSwarmOperations.json * Delete TestContainerServiceUpdateOperations.json * test * remove test text Co-authored-by: pavanrachapudy <[email protected]> Co-authored-by: Pavan Rachapudy <[email protected]> Co-authored-by: Adam Sandor <[email protected]> * new recording files * 2020-12 release features generated, tests pass * Update DiskRPTestsBase.cs (#18355) * Remove CloudService tests (#18423) * Delete CloudServiceExtensionTests.cs * Delete CloudServiceOperationTests.cs * Delete CloudServiceRoleInstanceTests.cs * Delete CloudServiceScenarioTests.cs * Delete CloudServiceTestsBase.cs * Delete CloudServiceUpdateTests.cs * Delete MultiRole_CreateUpdateGetAndDeleteWithExtension_WorkerAndWebRole.json * Delete MultiRole_CreateUpdateGetAndDeleteWithExtension_WorkerAndWebRole_MultiRoleExtension.json * Delete Test_Create_PowerOff_Start_CloudServiceOperation.json * Delete Test_ListCloudServicesOperation.json * Delete Test_CloudServiceRoleInstanceOperations.json * Delete TestCloudServiceScenarioOperations.json * Delete TestCloudServiceScenarioOperations_DeleteCloudService.json * Delete TestCloudServiceScenarioOperations_ExtensionProfile.json * Delete TestCloudServiceScenarioOperations_InstanceView.json * Delete TestCloudServiceOperations_ScaleIn_ScaleOut.json * Delete TestCloudServiceUpdateOperations.json * Update AzSdk.RP.props * Update AzSdk.RP.props remove containerService * Delete ServiceConfigurationHelpers.cs * regenerate on released 2020-12-01 swagger * re-recorded test jsons * test fixes * Update Helpers.cs * Update VMDataDiskTests.cs * Create TestVMDataDiskScenario_ManagedDisk_ForceDetach.json * Update OrchestrationMode.cs Co-authored-by: Theodore Chang <[email protected]> Co-authored-by: pavanrachapudy <[email protected]> Co-authored-by: Pavan Rachapudy <[email protected]>
1 parent 73b66d6 commit e1b1017

File tree

3 files changed

+4876
-0
lines changed

3 files changed

+4876
-0
lines changed

sdk/compute/Microsoft.Azure.Management.Compute/tests/Helpers/Helpers.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ public static void ValidateVirtualMachineSizeListResponse(IEnumerable<VirtualMac
9696
Assert.NotNull(vmSizeProperties);
9797
CompareVMSizes(expectedVMSizeProperties, vmSizeProperties);
9898
}
99+
100+
/// <summary>
101+
/// Marks a data disk to be detached.
102+
/// </summary>
103+
public static void MarkDataDiskToBeDetached(DataDisk disk, string detachOption = null)
104+
{
105+
Assert.NotNull(disk);
106+
disk.ToBeDetached = true;
107+
if (!string.IsNullOrEmpty(detachOption))
108+
{
109+
disk.DetachOption = detachOption;
110+
}
111+
}
99112

100113
private static List<VirtualMachineSize> GetExpectedVirtualMachineSize(bool hasAZ, bool? writeAcceleratorEnabled = null, bool hasDiffDisks = false)
101114
{

sdk/compute/Microsoft.Azure.Management.Compute/tests/ScenarioTests/VMDataDiskTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
using Microsoft.Azure.Management.Compute;
55
using Microsoft.Azure.Management.Compute.Models;
66
using Microsoft.Azure.Management.ResourceManager;
7+
using Microsoft.Azure.Management.Storage.Models;
78
using Microsoft.Azure.Test.HttpRecorder;
89
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
910
using System;
1011
using System.Collections.Generic;
12+
using System.Linq;
1113
using Xunit;
1214

1315
namespace Compute.Tests
@@ -130,6 +132,76 @@ public void TestVMDataDiskScenario()
130132
}
131133
}
132134
}
135+
136+
[Fact]
137+
[Trait("Name", "TestVMDataDiskScenario_ManagedDisk_ForceDetach")]
138+
public void TestVMDataDiskScenario_ManagedDisk_ForceDetach()
139+
{
140+
using (MockContext context = MockContext.Start(this.GetType()))
141+
{
142+
string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
143+
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap");
144+
EnsureClientsInitialized(context);
145+
146+
ImageReference imageReference = GetPlatformVMImage(useWindowsImage: true);
147+
string resourceGroupName = TestUtilities.GenerateName(TestPrefix);
148+
string storageAccountForDisksName = TestUtilities.GenerateName(TestPrefix);
149+
string availabilitySetName = TestUtilities.GenerateName(TestPrefix);
150+
151+
try
152+
{
153+
StorageAccount storageAccountForDisks = CreateStorageAccount(resourceGroupName, storageAccountForDisksName);
154+
155+
Action<VirtualMachine> addManagedDataDiskToVM = vm =>
156+
{
157+
vm.HardwareProfile.VmSize = VirtualMachineSizeTypes.StandardA4;
158+
vm.StorageProfile.DataDisks = new List<DataDisk>();
159+
160+
var diskName = "dataDisk" + TestUtilities.GenerateGuid();
161+
var dd = new DataDisk
162+
{
163+
Caching = CachingTypes.None,
164+
DiskSizeGB = 10,
165+
CreateOption = DiskCreateOptionTypes.Empty,
166+
Lun = 0,
167+
Name = diskName,
168+
ManagedDisk = new ManagedDiskParameters()
169+
{
170+
StorageAccountType = StorageAccountType.StandardLRS
171+
}
172+
};
173+
vm.StorageProfile.DataDisks.Add(dd);
174+
175+
var testStatus = new InstanceViewStatus
176+
{
177+
Code = "test",
178+
Message = "test"
179+
};
180+
181+
var testStatusList = new List<InstanceViewStatus> { testStatus };
182+
};
183+
184+
VirtualMachine inputVM;
185+
CreateVM(resourceGroupName, availabilitySetName, storageAccountForDisks, imageReference, out inputVM, addManagedDataDiskToVM, hasManagedDisks: true);
186+
187+
VirtualMachine getVMWithInstanceViewResponse = m_CrpClient.VirtualMachines.Get(resourceGroupName, inputVM.Name, InstanceViewTypes.InstanceView);
188+
ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse, hasManagedDisks: true);
189+
190+
DataDisk diskToBeForceDetached = getVMWithInstanceViewResponse.StorageProfile.DataDisks.FirstOrDefault(disk => disk.Lun == 0);
191+
Assert.NotNull(diskToBeForceDetached);
192+
193+
Helpers.MarkDataDiskToBeDetached(diskToBeForceDetached, "ForceDetach");
194+
195+
var forceDetachVMResponse = m_CrpClient.VirtualMachines.CreateOrUpdate(resourceGroupName, getVMWithInstanceViewResponse.Name, getVMWithInstanceViewResponse);
196+
Assert.Equal(0, forceDetachVMResponse.StorageProfile.DataDisks.Count);
197+
}
198+
finally
199+
{
200+
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
201+
m_ResourcesClient.ResourceGroups.Delete(resourceGroupName);
202+
}
203+
}
204+
}
133205
}
134206
}
135207

0 commit comments

Comments
 (0)