Skip to content
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Compute.Tests
{
using System.Collections.Generic;
using System.Linq;

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

using Xunit;

public class VMScaleSetPriorityTests : VMScaleSetTestsBase
{
/// <summary>
/// Covers following Operations:
/// Create RG
/// Create Storage Account
/// Create Network Resources
/// Get VMScaleSet Model View
/// Get VMScaleSet Instance View
/// List VMScaleSets in a RG
/// List Available Skus
/// Delete VMScaleSet
/// Delete RG
/// </summary>
[Fact]
[Trait("Name", "TestVMScaleSetScenarioOperations_Accept_Regular")]
public void TestVMScaleSetPriorityOperations_Accept_Regular()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
TestVMScaleSetPriorityOperationsInternal(context, "Regular");
}
}

/// <summary>
/// Covers following Operations:
/// Create RG
/// Create Storage Account
/// Create Network Resources
/// Get VMScaleSet Model View
/// Get VMScaleSet Instance View
/// List VMScaleSets in a RG
/// List Available Skus
/// Delete VMScaleSet
/// Delete RG
/// </summary>
[Fact]
[Trait("Name", "TestVMScaleSetScenarioOperations_Accept_Low")]
public void TestVMScaleSetPriorityOperations_Accept_Low()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
TestVMScaleSetPriorityOperationsInternal(context, "Low");
}
}

private void TestVMScaleSetPriorityOperationsInternal(
MockContext context,
string priority,
bool hasManagedDisks = false,
IList<string> zones = null
)
{
EnsureClientsInitialized(context);
this.m_location = "westcentralus";

ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);

// Create resource group
var rgName = TestUtilities.GenerateName(TestPrefix);
var vmssName = TestUtilities.GenerateName("vmss");
string storageAccountName = TestUtilities.GenerateName(TestPrefix);
VirtualMachineScaleSet inputVMScaleSet;

try
{
var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

m_CrpClient.VirtualMachineScaleSets.Delete(rgName, "VMScaleSetDoesNotExist");

var getResponse = CreateVMScaleSet_NoAsyncTracking(
rgName,
vmssName,
storageAccountOutput,
imageRef,
out inputVMScaleSet,
null,
(vmScaleSet) =>
{
vmScaleSet.Overprovision = true;
vmScaleSet.VirtualMachineProfile.Priority = priority;
vmScaleSet.Sku.Name = "Standard_A1";
vmScaleSet.Sku.Tier = "Standard";
vmScaleSet.Sku.Capacity = 2;
},
createWithManagedDisks: hasManagedDisks,
zones: zones);

ValidateVMScaleSet(inputVMScaleSet, getResponse, hasManagedDisks);

var getInstanceViewResponse = m_CrpClient.VirtualMachineScaleSets.GetInstanceView(rgName, vmssName);
Assert.NotNull(getInstanceViewResponse);
ValidateVMScaleSetInstanceView(inputVMScaleSet, getInstanceViewResponse);

var listResponse = m_CrpClient.VirtualMachineScaleSets.List(rgName);
ValidateVMScaleSet(
inputVMScaleSet,
listResponse.FirstOrDefault(x => x.Name == vmssName),
hasManagedDisks);

var listSkusResponse = m_CrpClient.VirtualMachineScaleSets.ListSkus(rgName, vmssName);
Assert.NotNull(listSkusResponse);
Assert.False(listSkusResponse.Count() == 0);
Assert.Same(inputVMScaleSet.VirtualMachineProfile.Priority, priority);

m_CrpClient.VirtualMachineScaleSets.Delete(rgName, vmssName);
}
finally
{
//Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
//of the test to cover deletion. CSM does persistent retrying over all RG resources.
m_ResourcesClient.ResourceGroups.Delete(rgName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Storage;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Compute.Tests
{
public class VMScaleSetVMOperationalTests : VMScaleSetVMTestsBase
public class VMScaleSetVMOperationalTests : VMScaleSetVMTestsBase
{
private string rgName, vmssName, storageAccountName, instanceId;
private ImageReference imageRef;
private VirtualMachineScaleSet inputVMScaleSet;

private void InitializeCommon(MockContext context)
{
EnsureClientsInitialized(context);

imageRef = GetPlatformVMImage(useWindowsImage: true);
rgName = TestUtilities.GenerateName(TestPrefix) + 1;
vmssName = TestUtilities.GenerateName("vmss");
storageAccountName = TestUtilities.GenerateName(TestPrefix);
}

/// <summary>
/// Covers following Operations:
/// Create RG
Expand Down Expand Up @@ -70,16 +85,8 @@ public void TestVMScaleSetVMOperations_ManagedDisks()

private void TestVMScaleSetVMOperationsInternal(MockContext context, bool hasManagedDisks = false)
{
EnsureClientsInitialized(context);

ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);

// Create resource group
string rgName = TestUtilities.GenerateName(TestPrefix) + 1;
string vmssName = TestUtilities.GenerateName("vmss");
string storageAccountName = TestUtilities.GenerateName(TestPrefix);
const string instanceId = "0";
VirtualMachineScaleSet inputVMScaleSet;
InitializeCommon(context);
instanceId = "0";

bool passed = false;
try
Expand Down Expand Up @@ -136,5 +143,117 @@ private void TestVMScaleSetVMOperationsInternal(MockContext context, bool hasMan

Assert.True(passed);
}

/// <summary>
/// Covers following Operations for a VMSS VM with managed disks:
/// Create RG
/// Create Storage Account
/// Create Network Resources
/// Create VMScaleSet
/// Get VMScaleSetVM Model View
/// Create DataDisk
/// Update VirtualMachineScaleVM to Attach Disk
/// Delete RG
/// </summary>
[Fact]
public void TestVMScaleSetVMOperations_Put()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
InitializeCommon(context);
bool passed = false;
instanceId = "0";

m_location = "southcentralus"; // Right now some regions are in hotfix that do not have this API

try
{
var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking(
rgName, vmssName, storageAccountOutput, imageRef, out inputVMScaleSet, createWithManagedDisks: true);

VirtualMachineScaleSetVM vmssVM = m_CrpClient.VirtualMachineScaleSetVMs.Get(rgName, vmScaleSet.Name, instanceId);

VirtualMachineScaleSetVM vmScaleSetVMModel = GenerateVMScaleSetVMModel(vmScaleSet, instanceId, hasManagedDisks: true);
ValidateVMScaleSetVM(vmScaleSetVMModel, vmScaleSet.Sku.Name, vmssVM, hasManagedDisks: true);

AttachDataDiskToVMScaleSetVM(vmssVM, vmScaleSetVMModel, 2);

VirtualMachineScaleSetVM vmssVMReturned = m_CrpClient.VirtualMachineScaleSetVMs.Update(rgName, vmScaleSet.Name, vmssVM.InstanceId, vmssVM);
ValidateVMScaleSetVM(vmScaleSetVMModel, vmScaleSet.Sku.Name, vmssVMReturned, hasManagedDisks: true);

passed = true;
}
finally
{
// Cleanup the created resources. But don't wait since it takes too long, and it's not the purpose
// of the test to cover deletion. CSM does persistent retrying over all RG resources.
m_ResourcesClient.ResourceGroups.Delete(rgName);
}

Assert.True(passed);
}
}

private Disk CreateDataDisk(string diskName)
{
var disk = new Disk
{
Location = m_location,
DiskSizeGB = 10,
};
disk.Sku = new DiskSku()
{
Name = StorageAccountTypes.StandardLRS
};
disk.CreationData = new CreationData()
{
CreateOption = DiskCreateOption.Empty
};

return m_CrpClient.Disks.CreateOrUpdate(rgName, diskName, disk);
}

private DataDisk CreateModelDataDisk(Disk disk)
{
var modelDisk = new DataDisk
{
DiskSizeGB = disk.DiskSizeGB,
CreateOption = DiskCreateOptionTypes.Attach
};

return modelDisk;
}

private void AttachDataDiskToVMScaleSetVM(VirtualMachineScaleSetVM vmssVM, VirtualMachineScaleSetVM vmModel, int lun)
{
if(vmssVM.StorageProfile.DataDisks == null)
vmssVM.StorageProfile.DataDisks = new List<DataDisk>();

if (vmModel.StorageProfile.DataDisks == null)
vmModel.StorageProfile.DataDisks = new List<DataDisk>();

var diskName = TestPrefix + "dataDisk" + lun;

var disk = CreateDataDisk(diskName);

var dd = new DataDisk
{
CreateOption = DiskCreateOptionTypes.Attach,
Lun = lun,
Name = diskName,
ManagedDisk = new ManagedDiskParameters()
{
Id = disk.Id,
StorageAccountType = disk.Sku.Name
}
};

vmssVM.StorageProfile.DataDisks.Add(dd);

// Add the data disk to the model for validation later
vmModel.StorageProfile.DataDisks.Add(CreateModelDataDisk(disk));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@ public partial interface IVirtualMachineScaleSetVMsOperations
/// </exception>
Task<AzureOperationResponse<OperationStatusResponse>> DeallocateWithHttpMessagesAsync(string resourceGroupName, string vmScaleSetName, string instanceId, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Updates a virtual machine of a VM scale set.
/// </summary>
/// <param name='resourceGroupName'>
/// The name of the resource group.
/// </param>
/// <param name='vmScaleSetName'>
/// The name of the VM scale set where the extension should be create
/// or updated.
/// </param>
/// <param name='instanceId'>
/// The instance ID of the virtual machine.
/// </param>
/// <param name='parameters'>
/// Parameters supplied to the Update Virtual Machine Scale Sets VM
/// operation.
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <exception cref="Microsoft.Rest.Azure.CloudException">
/// Thrown when the operation returned an invalid status code
/// </exception>
/// <exception cref="Microsoft.Rest.SerializationException">
/// Thrown when unable to deserialize the response
/// </exception>
/// <exception cref="Microsoft.Rest.ValidationException">
/// Thrown when a required parameter is null
/// </exception>
Task<AzureOperationResponse<VirtualMachineScaleSetVM>> UpdateWithHttpMessagesAsync(string resourceGroupName, string vmScaleSetName, string instanceId, VirtualMachineScaleSetVM parameters, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes a virtual machine from a VM scale set.
/// </summary>
/// <param name='resourceGroupName'>
Expand Down Expand Up @@ -407,6 +440,39 @@ public partial interface IVirtualMachineScaleSetVMsOperations
/// </exception>
Task<AzureOperationResponse<OperationStatusResponse>> BeginDeallocateWithHttpMessagesAsync(string resourceGroupName, string vmScaleSetName, string instanceId, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Updates a virtual machine of a VM scale set.
/// </summary>
/// <param name='resourceGroupName'>
/// The name of the resource group.
/// </param>
/// <param name='vmScaleSetName'>
/// The name of the VM scale set where the extension should be create
/// or updated.
/// </param>
/// <param name='instanceId'>
/// The instance ID of the virtual machine.
/// </param>
/// <param name='parameters'>
/// Parameters supplied to the Update Virtual Machine Scale Sets VM
/// operation.
/// </param>
/// <param name='customHeaders'>
/// The headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <exception cref="Microsoft.Rest.Azure.CloudException">
/// Thrown when the operation returned an invalid status code
/// </exception>
/// <exception cref="Microsoft.Rest.SerializationException">
/// Thrown when unable to deserialize the response
/// </exception>
/// <exception cref="Microsoft.Rest.ValidationException">
/// Thrown when a required parameter is null
/// </exception>
Task<AzureOperationResponse<VirtualMachineScaleSetVM>> BeginUpdateWithHttpMessagesAsync(string resourceGroupName, string vmScaleSetName, string instanceId, VirtualMachineScaleSetVM parameters, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Deletes a virtual machine from a VM scale set.
/// </summary>
/// <param name='resourceGroupName'>
Expand Down
Loading