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 missing tests for vmss redeploy and perform maintenance. #4135

Merged
merged 1 commit into from
Mar 15, 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

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.

Large diffs are not rendered by default.

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

using System.Collections.Generic;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.Storage.Models;
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using Xunit;

namespace Compute.Tests
Expand Down Expand Up @@ -106,7 +108,98 @@ private void TestVMScaleSetOperationsInternal(MockContext context, bool hasManag

Assert.True(passed);
}


[Fact]
public void TestVMScaleSetOperations_Redeploy()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var originalLocation = ComputeManagementTestUtilities.DefaultLocation;
ComputeManagementTestUtilities.DefaultLocation = "EastUS2";

EnsureClientsInitialized(context);

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

bool passed = false;

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

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

m_CrpClient.VirtualMachineScaleSets.Redeploy(rgName, vmScaleSet.Name);

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.DeleteIfExists(rgName);
ComputeManagementTestUtilities.DefaultLocation = originalLocation;
}

Assert.True(passed);
}
}

[Fact]
public void TestVMScaleSetOperations_PerformMaintenance()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var originalLocation = ComputeManagementTestUtilities.DefaultLocation;
ComputeManagementTestUtilities.DefaultLocation = "EastUS2";

EnsureClientsInitialized(context);

ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);
string rgName = TestUtilities.GenerateName(TestPrefix) + 1;
string vmssName = TestUtilities.GenerateName("vmss");
string storageAccountName = TestUtilities.GenerateName(TestPrefix);
VirtualMachineScaleSet inputVMScaleSet;
VirtualMachineScaleSet vmScaleSet = null;

bool passed = false;

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

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

m_CrpClient.VirtualMachineScaleSets.PerformMaintenance(rgName, vmScaleSet.Name);

passed = true;
}
catch (CloudException cex)
{
passed = true;
string expectedMessage =
$"Operation 'performMaintenance' is not allowed on VM '{vmScaleSet.Name}_0' " +
"since the Subscription of this VM is not eligible.";
Assert.Equal(expectedMessage, cex.Message);
}
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.DeleteIfExists(rgName);
ComputeManagementTestUtilities.DefaultLocation = originalLocation;
}

Assert.True(passed);
}
}

/// <summary>
/// Covers following Operations:
/// Create RG
Expand Down Expand Up @@ -177,5 +270,103 @@ public void TestVMScaleSetBatchOperations()
Assert.True(passed);
}
}

[Fact]
public void TestVMScaleSetBatchOperations_Redeploy()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var originalLocation = ComputeManagementTestUtilities.DefaultLocation;
ComputeManagementTestUtilities.DefaultLocation = "EastUS2";

EnsureClientsInitialized(context);

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

bool passed = false;
try
{
StorageAccount storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking(rgName, vmssName,
storageAccountOutput, imageRef, out inputVMScaleSet, createWithManagedDisks: true,
vmScaleSetCustomizer: virtualMachineScaleSet => virtualMachineScaleSet.UpgradePolicy =
new UpgradePolicy {Mode = UpgradeMode.Manual});

List<string> virtualMachineScaleSetInstanceIDs = new List<string> {"0", "1"};

m_CrpClient.VirtualMachineScaleSets.Redeploy(rgName, vmScaleSet.Name, virtualMachineScaleSetInstanceIDs);

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.DeleteIfExists(rgName);
ComputeManagementTestUtilities.DefaultLocation = originalLocation;
}

Assert.True(passed);
}
}

[Fact]
public void TestVMScaleSetBatchOperations_PerformMaintenance()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var originalLocation = ComputeManagementTestUtilities.DefaultLocation;
ComputeManagementTestUtilities.DefaultLocation = "EastUS2";

EnsureClientsInitialized(context);

ImageReference imageRef = GetPlatformVMImage(useWindowsImage: true);
string rgName = TestUtilities.GenerateName(TestPrefix) + 1;
string vmssName = TestUtilities.GenerateName("vmss");
string storageAccountName = TestUtilities.GenerateName(TestPrefix);
VirtualMachineScaleSet inputVMScaleSet;
VirtualMachineScaleSet vmScaleSet = null;

bool passed = false;
try
{
StorageAccount storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);

vmScaleSet = CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageRef,
out inputVMScaleSet, createWithManagedDisks: true,
vmScaleSetCustomizer: virtualMachineScaleSet => virtualMachineScaleSet.UpgradePolicy =
new UpgradePolicy {Mode = UpgradeMode.Manual});

List<string> virtualMachineScaleSetInstanceIDs = new List<string> { "0", "1" };

m_CrpClient.VirtualMachineScaleSets.PerformMaintenance(rgName, vmScaleSet.Name,
virtualMachineScaleSetInstanceIDs);

passed = true;
}
catch (CloudException cex)
{
passed = true;
string expectedMessage =
$"Operation 'performMaintenance' is not allowed on VM '{vmScaleSet.Name}_0' " +
"since the Subscription of this VM is not eligible.";
Assert.Equal(expectedMessage, cex.Message);
}
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.DeleteIfExists(rgName);
ComputeManagementTestUtilities.DefaultLocation = originalLocation;
}

Assert.True(passed);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Storage;
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Compute.Tests
Expand Down Expand Up @@ -196,6 +195,96 @@ public void TestVMScaleSetVMOperations_Put()
}
}

/// <summary>
/// Covers following operations:
/// Create RG
/// Create VM Scale Set
/// Redeploy one instance of VM Scale Set
/// Delete RG
/// </summary>
[Fact]
public void TestVMScaleSetVMOperations_Redeploy()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var originalLocation = ComputeManagementTestUtilities.DefaultLocation;
ComputeManagementTestUtilities.DefaultLocation = "EastUS2";

InitializeCommon(context);
instanceId = "0";
bool passed = false;

try
{
var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);
VirtualMachineScaleSet vmScaleSet = CreateVMScaleSet_NoAsyncTracking(rgName, vmssName,
storageAccountOutput, imageRef, out inputVMScaleSet, createWithManagedDisks: true);
m_CrpClient.VirtualMachineScaleSetVMs.Redeploy(rgName, vmScaleSet.Name, instanceId);

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.DeleteIfExists(rgName);
ComputeManagementTestUtilities.DefaultLocation = originalLocation;
}

Assert.True(passed);
}
}

/// <summary>
/// Covers following operations:
/// Create RG
/// Create VM Scale Set
/// Perform maintenance on one instance of VM Scale Set
/// Delete RG
/// </summary>
[Fact]
public void TestVMScaleSetVMOperations_PerformMaintenance()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var originalLocation = ComputeManagementTestUtilities.DefaultLocation;
ComputeManagementTestUtilities.DefaultLocation = "EastUS2";

InitializeCommon(context);
instanceId = "0";
VirtualMachineScaleSet vmScaleSet = null;

bool passed = false;

try
{
var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);
vmScaleSet = CreateVMScaleSet_NoAsyncTracking(rgName, vmssName, storageAccountOutput, imageRef,
out inputVMScaleSet, createWithManagedDisks: true);
m_CrpClient.VirtualMachineScaleSetVMs.PerformMaintenance(rgName, vmScaleSet.Name, instanceId);

passed = true;
}
catch (CloudException cex)
{
passed = true;
string expectedMessage =
$"Operation 'performMaintenance' is not allowed on VM '{vmScaleSet.Name}_0' " +
"since the Subscription of this VM is not eligible.";
Assert.Equal(expectedMessage, cex.Message);
}
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.DeleteIfExists(rgName);
ComputeManagementTestUtilities.DefaultLocation = originalLocation;
}

Assert.True(passed);
}
}

private Disk CreateDataDisk(string diskName)
{
var disk = new Disk
Expand Down