Skip to content

Commit

Permalink
deep delete for disks (#19930)
Browse files Browse the repository at this point in the history
  • Loading branch information
srcharug authored Jun 1, 2021
1 parent 8763c5d commit c1639e4
Show file tree
Hide file tree
Showing 2 changed files with 2,875 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Xunit;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Compute;
using System;

namespace Compute.Tests
{
public class VMDeleteOptionTests : VMTestBase
{
[Fact]
[Trait("Name", "TestDeleteOptionForDisks")]
public void TestDeleteOptionForDisks()
{
string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
using (MockContext context = MockContext.Start(this.GetType()))
{
// Hard code the location to "eastus2euap".
// 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", "eastus2euap");
EnsureClientsInitialized(context);

ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);

// Create resource group
var rgName = ComputeManagementTestUtilities.GenerateName(TestPrefix);
string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix);
string asName = ComputeManagementTestUtilities.GenerateName("as");

try
{
// Create Storage Account, so that both the VMs can share it
var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

VirtualMachine inputVM;
CreateVM(rgName, asName, storageAccountOutput, imageRef, out inputVM, hasManagedDisks: true);

Assert.Equal(DiskDeleteOptionTypes.Detach, inputVM.StorageProfile.OsDisk.DeleteOption);

foreach (DataDisk disk in inputVM.StorageProfile.DataDisks)
{
Assert.Equal(DiskDeleteOptionTypes.Detach, disk.DeleteOption);
}

m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name);
}
finally
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
m_ResourcesClient.ResourceGroups.Delete(rgName);
}
}
}
}
}
Loading

0 comments on commit c1639e4

Please sign in to comment.