Skip to content

Commit

Permalink
Force Detach test (#18553)
Browse files Browse the repository at this point in the history
* 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 <vrachapu@microsoft.com>

* 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 <pavanrachapudy@gmail.com>
Co-authored-by: Pavan Rachapudy <vrachapu@microsoft.com>
Co-authored-by: Adam Sandor <adsandor@microsoft.com>

* 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 <thchan@microsoft.com>
Co-authored-by: pavanrachapudy <pavanrachapudy@gmail.com>
Co-authored-by: Pavan Rachapudy <vrachapu@microsoft.com>
  • Loading branch information
4 people authored Mar 4, 2021
1 parent 73b66d6 commit e1b1017
Show file tree
Hide file tree
Showing 3 changed files with 4,876 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ public static void ValidateVirtualMachineSizeListResponse(IEnumerable<VirtualMac
Assert.NotNull(vmSizeProperties);
CompareVMSizes(expectedVMSizeProperties, vmSizeProperties);
}

/// <summary>
/// Marks a data disk to be detached.
/// </summary>
public static void MarkDataDiskToBeDetached(DataDisk disk, string detachOption = null)
{
Assert.NotNull(disk);
disk.ToBeDetached = true;
if (!string.IsNullOrEmpty(detachOption))
{
disk.DetachOption = detachOption;
}
}

private static List<VirtualMachineSize> GetExpectedVirtualMachineSize(bool hasAZ, bool? writeAcceleratorEnabled = null, bool hasDiffDisks = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Storage.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Compute.Tests
Expand Down Expand Up @@ -130,6 +132,76 @@ public void TestVMDataDiskScenario()
}
}
}

[Fact]
[Trait("Name", "TestVMDataDiskScenario_ManagedDisk_ForceDetach")]
public void TestVMDataDiskScenario_ManagedDisk_ForceDetach()
{
using (MockContext context = MockContext.Start(this.GetType()))
{
string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap");
EnsureClientsInitialized(context);

ImageReference imageReference = GetPlatformVMImage(useWindowsImage: true);
string resourceGroupName = TestUtilities.GenerateName(TestPrefix);
string storageAccountForDisksName = TestUtilities.GenerateName(TestPrefix);
string availabilitySetName = TestUtilities.GenerateName(TestPrefix);

try
{
StorageAccount storageAccountForDisks = CreateStorageAccount(resourceGroupName, storageAccountForDisksName);

Action<VirtualMachine> addManagedDataDiskToVM = vm =>
{
vm.HardwareProfile.VmSize = VirtualMachineSizeTypes.StandardA4;
vm.StorageProfile.DataDisks = new List<DataDisk>();
var diskName = "dataDisk" + TestUtilities.GenerateGuid();
var dd = new DataDisk
{
Caching = CachingTypes.None,
DiskSizeGB = 10,
CreateOption = DiskCreateOptionTypes.Empty,
Lun = 0,
Name = diskName,
ManagedDisk = new ManagedDiskParameters()
{
StorageAccountType = StorageAccountType.StandardLRS
}
};
vm.StorageProfile.DataDisks.Add(dd);
var testStatus = new InstanceViewStatus
{
Code = "test",
Message = "test"
};
var testStatusList = new List<InstanceViewStatus> { testStatus };
};

VirtualMachine inputVM;
CreateVM(resourceGroupName, availabilitySetName, storageAccountForDisks, imageReference, out inputVM, addManagedDataDiskToVM, hasManagedDisks: true);

VirtualMachine getVMWithInstanceViewResponse = m_CrpClient.VirtualMachines.Get(resourceGroupName, inputVM.Name, InstanceViewTypes.InstanceView);
ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse, hasManagedDisks: true);

DataDisk diskToBeForceDetached = getVMWithInstanceViewResponse.StorageProfile.DataDisks.FirstOrDefault(disk => disk.Lun == 0);
Assert.NotNull(diskToBeForceDetached);

Helpers.MarkDataDiskToBeDetached(diskToBeForceDetached, "ForceDetach");

var forceDetachVMResponse = m_CrpClient.VirtualMachines.CreateOrUpdate(resourceGroupName, getVMWithInstanceViewResponse.Name, getVMWithInstanceViewResponse);
Assert.Equal(0, forceDetachVMResponse.StorageProfile.DataDisks.Count);
}
finally
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
m_ResourcesClient.ResourceGroups.Delete(resourceGroupName);
}
}
}
}
}

Loading

0 comments on commit e1b1017

Please sign in to comment.