Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compute] Add availability set list by subscription and standard ssd disk #4517

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/SDKs/Compute/Compute.Tests/DiskRPTests/DiskRPTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ protected Disk GenerateDefaultDisk(string diskCreateOption, string rgName, int?

switch (diskCreateOption)
{
case DiskCreateOption.Empty:
case "Empty":
disk = GenerateBaseDisk(diskCreateOption);
disk.DiskSizeGB = diskSizeGB;
disk.Zones = zones;
break;
case DiskCreateOption.Import:
case "Import":
disk = GenerateImportDisk(diskCreateOption, rgName);
disk.DiskSizeGB = diskSizeGB;
disk.Zones = zones;
Expand Down Expand Up @@ -402,7 +402,7 @@ private Disk GenerateBaseDisk(string diskCreateOption)
return disk;
}

protected Snapshot GenerateDefaultSnapshot(string sourceDiskId, string snapshotStorageAccountTypes = SnapshotStorageAccountTypes.StandardLRS)
protected Snapshot GenerateDefaultSnapshot(string sourceDiskId, string snapshotStorageAccountTypes = "Standard_LRS")
{
Snapshot snapshot = GenerateBaseSnapshot(sourceDiskId, snapshotStorageAccountTypes);
return snapshot;
Expand Down
135 changes: 106 additions & 29 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/AvailabilitySetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ public class AvailabilitySetTests : VMTestBase
ComputeManagementClient computeClient;
ResourceManagementClient resourcesClient;

ResourceGroup resourceGroup;
ResourceGroup resourceGroup1;
ResourceGroup resourceGroup2;

string subId;
string location;
const string testPrefix = TestPrefix;
string resourceGroupName;
string baseResourceGroupName;
string resourceGroup1Name;

// These values are configurable in the service, but normal default values are FD = 3 and UD = 5
// FD values can be 2 or 3
Expand Down Expand Up @@ -64,10 +65,13 @@ public void TestOperations()

// Updating an Availability Set should fail
//VerifyUpdateFails();

// Make sure availability sets across resource groups are listed successfully
VerifyListAvailabilitySetsInSubscription();
}
finally
{
resourcesClient.ResourceGroups.Delete(resourceGroupName);
resourcesClient.ResourceGroups.Delete(resourceGroup1Name);
}
}
}
Expand All @@ -81,14 +85,15 @@ private void Initialize(MockContext context)
subId = computeClient.SubscriptionId;
location = m_location;

resourceGroupName = ComputeManagementTestUtilities.GenerateName(testPrefix);
baseResourceGroupName = ComputeManagementTestUtilities.GenerateName(TestPrefix);
resourceGroup1Name = baseResourceGroupName + "_1";

resourceGroup = resourcesClient.ResourceGroups.CreateOrUpdate(
resourceGroupName,
resourceGroup1 = resourcesClient.ResourceGroups.CreateOrUpdate(
resourceGroup1Name,
new ResourceGroup
{
Location = location,
Tags = new Dictionary<string, string>() { { resourceGroupName, DateTime.UtcNow.ToString("u") } }
Tags = new Dictionary<string, string>() { { resourceGroup1Name, DateTime.UtcNow.ToString("u") } }
});
}

Expand All @@ -106,7 +111,7 @@ private void VerifyUpdateFails()
};

// Create and expect success.
var createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroupName, availabilitySetName, inputAvailabilitySet);
var createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroup1Name, availabilitySetName, inputAvailabilitySet);

try // Modify the FD and expect failure
{
Expand All @@ -122,7 +127,7 @@ private void VerifyUpdateFails()
};

createOrUpdateResponse = null;
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroupName, availabilitySetName, inputAvailabilitySet);
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroup1Name, availabilitySetName, inputAvailabilitySet);
}
catch (CloudException ex)
{
Expand All @@ -144,7 +149,7 @@ private void VerifyUpdateFails()
};

createOrUpdateResponse = null;
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroupName, availabilitySetName, inputAvailabilitySet);
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(resourceGroup1Name, availabilitySetName, inputAvailabilitySet);
}
catch (CloudException ex)
{
Expand All @@ -153,7 +158,7 @@ private void VerifyUpdateFails()
Assert.True(createOrUpdateResponse == null);

// Clean up
computeClient.AvailabilitySets.Delete(resourceGroupName, availabilitySetName);
computeClient.AvailabilitySets.Delete(resourceGroup1Name, availabilitySetName);
}

private void VerifyNonDefaultValuesSucceed()
Expand All @@ -180,12 +185,12 @@ private void VerifyNonDefaultValuesSucceed()
};

var createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroupName,
resourceGroup1Name,
inputAvailabilitySetName,
inputAvailabilitySet);

// This call will also delete the Availability Set
ValidateResults(createOrUpdateResponse, inputAvailabilitySet, inputAvailabilitySetName, nonDefaultFD, nonDefaultUD);
ValidateResults(createOrUpdateResponse, inputAvailabilitySet, resourceGroup1Name, inputAvailabilitySetName, nonDefaultFD, nonDefaultUD);
}

private void VerifyDefaultValuesSucceed()
Expand All @@ -202,13 +207,13 @@ private void VerifyDefaultValuesSucceed()
};

var createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroupName,
resourceGroup1Name,
inputAvailabilitySetName,
inputAvailabilitySet);

// List AvailabilitySets
string expectedAvailabilitySetId = Helpers.GetAvailabilitySetRef(subId, resourceGroupName, inputAvailabilitySetName);
var listResponse = computeClient.AvailabilitySets.List(resourceGroupName);
string expectedAvailabilitySetId = Helpers.GetAvailabilitySetRef(subId, resourceGroup1Name, inputAvailabilitySetName);
var listResponse = computeClient.AvailabilitySets.List(resourceGroup1Name);
ValidateAvailabilitySet(inputAvailabilitySet, listResponse.FirstOrDefault(x => x.Name == inputAvailabilitySetName),
inputAvailabilitySetName, expectedAvailabilitySetId, defaultFD, defaultUD);

Expand All @@ -219,12 +224,12 @@ private void VerifyDefaultValuesSucceed()

string updateKey = "UpdateTag";
updateParams.Tags.Add(updateKey, "updateValue");
createOrUpdateResponse = computeClient.AvailabilitySets.Update(resourceGroupName, inputAvailabilitySetName, updateParams);
createOrUpdateResponse = computeClient.AvailabilitySets.Update(resourceGroup1Name, inputAvailabilitySetName, updateParams);

Assert.True(createOrUpdateResponse.Tags.ContainsKey(updateKey));

// This call will also delete the Availability Set
ValidateResults(createOrUpdateResponse, inputAvailabilitySet, inputAvailabilitySetName, defaultFD, defaultUD);
ValidateResults(createOrUpdateResponse, inputAvailabilitySet, resourceGroup1Name, inputAvailabilitySetName, defaultFD, defaultUD);
}

private void VerifyInvalidFDUDValuesFail()
Expand All @@ -246,7 +251,7 @@ private void VerifyInvalidFDUDValuesFail()
try
{
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroupName,
resourceGroup1Name,
inputAvailabilitySetName,
inputAvailabilitySet);
}
Expand All @@ -260,7 +265,7 @@ private void VerifyInvalidFDUDValuesFail()
try
{
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroupName,
resourceGroup1Name,
inputAvailabilitySetName,
inputAvailabilitySet);
}
Expand All @@ -275,7 +280,7 @@ private void VerifyInvalidFDUDValuesFail()
try
{
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroupName,
resourceGroup1Name,
inputAvailabilitySetName,
inputAvailabilitySet);
}
Expand All @@ -290,7 +295,7 @@ private void VerifyInvalidFDUDValuesFail()
try
{
createOrUpdateResponse = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroupName,
resourceGroup1Name,
inputAvailabilitySetName,
inputAvailabilitySet);
}
Expand All @@ -302,15 +307,15 @@ private void VerifyInvalidFDUDValuesFail()
Assert.True(createOrUpdateResponse == null);
}

private void ValidateResults(AvailabilitySet createOrUpdateResponse, AvailabilitySet inputAvailabilitySet, string inputAvailabilitySetName, int expectedFD, int expectedUD)
private void ValidateResults(AvailabilitySet outputAvailabilitySet, AvailabilitySet inputAvailabilitySet, string resourceGroupName, string inputAvailabilitySetName, int expectedFD, int expectedUD)
{
string expectedAvailabilitySetId = Helpers.GetAvailabilitySetRef(subId, resourceGroupName, inputAvailabilitySetName);

Assert.True(createOrUpdateResponse.Name == inputAvailabilitySetName);
Assert.True(createOrUpdateResponse.Location.ToLower() == this.location.ToLower()
|| createOrUpdateResponse.Location.ToLower() == inputAvailabilitySet.Location.ToLower());
Assert.True(outputAvailabilitySet.Name == inputAvailabilitySetName);
Assert.True(outputAvailabilitySet.Location.ToLower() == this.location.ToLower()
|| outputAvailabilitySet.Location.ToLower() == inputAvailabilitySet.Location.ToLower());

ValidateAvailabilitySet(inputAvailabilitySet, createOrUpdateResponse, inputAvailabilitySetName, expectedAvailabilitySetId, expectedFD, expectedUD);
ValidateAvailabilitySet(inputAvailabilitySet, outputAvailabilitySet, inputAvailabilitySetName, expectedAvailabilitySetId, expectedFD, expectedUD);

// GET AvailabilitySet
var getResponse = computeClient.AvailabilitySets.Get(resourceGroupName, inputAvailabilitySetName);
Expand All @@ -324,7 +329,6 @@ private void ValidateResults(AvailabilitySet createOrUpdateResponse, Availabilit
computeClient.AvailabilitySets.Delete(resourceGroupName, inputAvailabilitySetName);
}


private void ValidateAvailabilitySet(AvailabilitySet inputAvailabilitySet, AvailabilitySet outputAvailabilitySet, string inputAvailabilitySetName, string expectedAvailabilitySetId, int expectedFD, int expectedUD)
{
Assert.True(inputAvailabilitySetName == outputAvailabilitySet.Name);
Expand All @@ -347,6 +351,79 @@ private void ValidateAvailabilitySet(AvailabilitySet inputAvailabilitySet, Avail
//Assert.NotNull(outputAvailabilitySet.Properties.Id);
//Assert.True(expectedAvailabilitySetIds.ToLowerInvariant() == outputAvailabilitySet.Properties.Id.ToLowerInvariant());
}

// Make sure availability sets across resource groups are listed successfully
private void VerifyListAvailabilitySetsInSubscription()
{
string resourceGroup2Name = baseResourceGroupName + "_2";
string baseInputAvailabilitySetName = ComputeManagementTestUtilities.GenerateName("asdefaultvalues");
string availabilitySet1Name = baseInputAvailabilitySetName + "_1";
string availabilitySet2Name = baseInputAvailabilitySetName + "_2";

try
{
AvailabilitySet inputAvailabilitySet1 = new AvailabilitySet
{
Location = location,
Tags = new Dictionary<string, string>()
{
{"RG1", "rg1"},
{"testTag", "1"},
},
};
AvailabilitySet outputAvailabilitySet1 = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroup1Name,
availabilitySet1Name,
inputAvailabilitySet1);

resourceGroup2 = resourcesClient.ResourceGroups.CreateOrUpdate(
resourceGroup2Name,
new ResourceGroup
{
Location = location,
Tags = new Dictionary<string, string>() { { resourceGroup2Name, DateTime.UtcNow.ToString("u") } }
});

AvailabilitySet inputAvailabilitySet2 = new AvailabilitySet
{
Location = location,
Tags = new Dictionary<string, string>()
{
{"RG2", "rg2"},
{"testTag", "2"},
},
};
AvailabilitySet outputAvailabilitySet2 = computeClient.AvailabilitySets.CreateOrUpdate(
resourceGroup2Name,
availabilitySet2Name,
inputAvailabilitySet2);

IPage<AvailabilitySet> response = computeClient.AvailabilitySets.ListBySubscription();
Assert.Null(response.NextPageLink);

int validationCount = 0;

foreach (AvailabilitySet availabilitySet in response)
{
if (availabilitySet.Name == availabilitySet1Name)
{
ValidateResults(outputAvailabilitySet1, inputAvailabilitySet1, resourceGroup1Name, availabilitySet1Name, defaultFD, defaultUD);
validationCount++;
}
else if (availabilitySet.Name == availabilitySet2Name)
{
ValidateResults(outputAvailabilitySet2, inputAvailabilitySet2, resourceGroup2Name, availabilitySet2Name, defaultFD, defaultUD);
validationCount++;
}
}

Assert.True(validationCount == 2);
}
finally
{
resourcesClient.ResourceGroups.Delete(resourceGroup2Name);
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void TestVMBootDiagnostics()

var getVMWithInstanceViewResponse = m_CrpClient.VirtualMachines.Get(rgName, inputVM.Name, InstanceViewTypes.InstanceView);
ValidateVMInstanceView(inputVM, getVMWithInstanceViewResponse);

m_CrpClient.VirtualMachines.Delete(rgName, inputVM.Name);
}
finally
Expand Down
25 changes: 22 additions & 3 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/VMScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,27 @@ public void TestVMScenarioOperations_ManagedDisks()
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
}
}


/// <summary>
/// TODO: StandardSSD is currently in preview and is available only in a few regions. Once it goes GA, it can be tested in
/// the default test location.
/// </summary>
[Fact]
[Trait("Name", "TestVMScenarioOperations_ManagedDisks_StandardSSD")]
public void TestVMScenarioOperations_ManagedDisks_StandardSSD()
{
string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
try
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "northeurope");
TestVMScenarioOperationsInternal("TestVMScenarioOperations_ManagedDisks_StandardSSD", hasManagedDisks: true,
storageAccountType: StorageAccountTypes.StandardSSDLRS);
}
finally
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
}
}

/// <summary>
Expand All @@ -87,8 +106,8 @@ public void TestVMScenarioOperations_ManagedDisks_PirImage_Zones()
}
}

private void TestVMScenarioOperationsInternal(string methodName, bool hasManagedDisks = false, IList<string> zones = null, string vmSize = VirtualMachineSizeTypes.StandardA0,
string storageAccountType = StorageAccountTypes.StandardLRS, bool? writeAcceleratorEnabled = null, bool callUpdateVM = false)
private void TestVMScenarioOperationsInternal(string methodName, bool hasManagedDisks = false, IList<string> zones = null, string vmSize = "Standard_A0",
string storageAccountType = "Standard_LRS", bool? writeAcceleratorEnabled = null, bool callUpdateVM = false)
{
using (MockContext context = MockContext.Start(this.GetType().FullName, methodName))
{
Expand Down
8 changes: 4 additions & 4 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/VMTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Compute.Tests
public class VMTestBase
{
protected const string TestPrefix = "crptestar";
protected const string PLACEHOLDER = "[PLACEHOLDER]";
protected const string PLACEHOLDER = "[PLACEHOLDEr1]";
protected const string ComputerName = "Test";

protected ResourceManagementClient m_ResourcesClient;
Expand Down Expand Up @@ -209,8 +209,8 @@ protected VirtualMachine CreateVM(
bool createWithPublicIpAddress = false,
bool waitForCompletion = true,
bool hasManagedDisks = false,
string vmSize = VirtualMachineSizeTypes.StandardA0,
string storageAccountType = StorageAccountTypes.StandardLRS,
string vmSize = "Standard_A0",
string storageAccountType = "Standard_LRS",
bool? writeAcceleratorEnabled = null,
IList<string> zones = null)
{
Expand Down Expand Up @@ -731,7 +731,7 @@ protected string CreateAvailabilitySet(string rgName, string asName, bool hasMan
}

protected VirtualMachine CreateDefaultVMInput(string rgName, string storageAccountName, ImageReference imageRef, string asetId, string nicId, bool hasManagedDisks = false,
string vmSize = VirtualMachineSizeTypes.StandardA0, string storageAccountType = StorageAccountTypes.StandardLRS, bool? writeAcceleratorEnabled = null)
string vmSize = "Standard_A0", string storageAccountType = "Standard_LRS", bool? writeAcceleratorEnabled = null)
{
// Generate Container name to hold disk VHds
string containerName = ComputeManagementTestUtilities.GenerateName(TestPrefix);
Expand Down
Loading