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

Add SDK changes for VMHealth field for VMs #13445

Merged
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 eng/mgmt/mgmtmetadata/compute_resource-manager.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ AutoRest installed successfully.
Commencing code generation
Generating CSharp code
Executing AutoRest command
cmd.exe /c autorest.cmd https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager/readme.md --csharp --version=v2 --reflect-api-versions --csharp-sdks-folder=D:\Azure-sdk\compute-2020-06\sdk
2020-07-01 17:17:32 UTC
cmd.exe /c autorest.cmd https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager/readme.md --csharp --version=v2 --reflect-api-versions --csharp-sdks-folder=E:\workdir\github\azure-sdk-for-net\sdk
2020-07-14 19:06:24 UTC
Azure-rest-api-specs repository information
GitHub fork: Azure
Branch: master
Commit: ab6b4d787190ceb777412ebf79bd57a8dccbec2c
Commit: 00ac1cbffba123ba5e30cb324935100495d0700d
AutoRest information
Requested version: v2
Bootstrapper version: autorest@2.0.4413

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
Provides developers with libraries for the updated compute platform under Azure Resource manager to deploy virtual machine, virtual machine extensions and availability set management capabilities. Launch, restart, scale, capture and manage VMs, VM Extensions and more. Note: This client library is for Virtual Machines under Azure Resource Manager.
Development of this library has shifted focus to the Azure Unified SDK. The future development will be focused on "Azure.ResourceManager.Compute" (https://www.nuget.org/packages/Azure.ResourceManager.Compute/). Please see the package changelog for more information.
</Description>
<Version>38.0.0.0</Version>
<Version>38.1.0.0</Version>
<AssemblyName>Microsoft.Azure.Management.Compute</AssemblyName>
<PackageTags>management;virtual machine;compute;</PackageTags>
<PackageReleaseNotes>
<![CDATA[
This is a public release of the Azure Compute SDK. Included with this release are VM model change to add a property related to in-guest VM patching, adding Disallowed property to VirtualMachineImage, adding SecurityProfile for supporting the Host Encryption in VM/VMSS, adding RetrieveBootDiagnosticsData API for VM and VMSS, adding AccessPatches API, adding ExtensionsTimeBudget property to VM and VMSS, updating dedicated host group automatic placement, and adding EncryptionType to DiskEncryptionSetUpdateProperties.
This is a public release of the Azure Compute SDK. Included with this release is the vmHealth property added to the VMInstanceView API.
]]>
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
[assembly: AssemblyTitle("Microsoft Azure Compute Management Library")]
[assembly: AssemblyDescription("Provides management functionality for Microsoft Azure Compute Resources.")]

[assembly: AssemblyVersion("38.0.0.0")]
[assembly: AssemblyFileVersion("38.0.0.0")]
[assembly: AssemblyVersion("38.1.0.0")]
[assembly: AssemblyFileVersion("38.1.0.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Microsoft Azure .NET SDK")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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 System.Reflection;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Compute.Tests
{
public class VMHealthExtensionTests : VMTestBase
{
VirtualMachineExtension GetHealthVMExtension()
{
var vmExtension = new VirtualMachineExtension
{
Location = ComputeManagementTestUtilities.DefaultLocation,
Tags = new Dictionary<string, string>() { { "extensionTag1", "1" }, { "extensionTag2", "2" } },
Publisher = "Microsoft.ManagedServices",
VirtualMachineExtensionType = "ApplicationHealthWindows",
TypeHandlerVersion = "1.0",
AutoUpgradeMinorVersion = true,
ForceUpdateTag = "RerunExtension",
Settings = new JRaw("{ \"port\": 3389, \"protocol\": \"tcp\" }"),
ProtectedSettings = "{}"
};
typeof(Resource).GetRuntimeProperty("Name").SetValue(vmExtension, "vmext01");
typeof(Resource).GetRuntimeProperty("Type").SetValue(vmExtension, "Microsoft.Compute/virtualMachines/extensions");

return vmExtension;
}

[Fact]
public void TestVMHealthExtensionOperations()
{
using (MockContext context = MockContext.Start(this.GetType()))
{
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");
VirtualMachine inputVM;
try
{
// Create VM with storage account
var storageAccountOutput = CreateStorageAccount(rgName, storageAccountName);
var vm = CreateVM(rgName, asName, storageAccountOutput, imageRef, out inputVM);

// Add an extension to the VM
var vmExtension = GetHealthVMExtension();
var response = m_CrpClient.VirtualMachineExtensions.CreateOrUpdate(rgName, vm.Name, vmExtension.Name, vmExtension);
ValidateVMExtension(vmExtension, response);

// Perform a Get operation on the extension
var getVMExtResponse = m_CrpClient.VirtualMachineExtensions.Get(rgName, vm.Name, vmExtension.Name);
ValidateVMExtension(vmExtension, getVMExtResponse);

// Validate Get InstanceView for the extension
var getVMExtInstanceViewResponse = m_CrpClient.VirtualMachineExtensions.Get(rgName, vm.Name, vmExtension.Name, "instanceView");
ValidateVMExtensionInstanceView(getVMExtInstanceViewResponse.InstanceView);

var getVMInstanceViewResponse = m_CrpClient.VirtualMachines.Get(rgName, vm.Name, InstanceViewTypes.InstanceView);
ValidateVMHealthStatusInstanceView(getVMInstanceViewResponse.InstanceView.VmHealth);

// Validate the extension delete API
m_CrpClient.VirtualMachineExtensions.Delete(rgName, vm.Name, vmExtension.Name);
}
finally
{
m_ResourcesClient.ResourceGroups.Delete(rgName);
}
}
}

private void ValidateVMExtension(VirtualMachineExtension vmExtExpected, VirtualMachineExtension vmExtReturned)
{
Assert.NotNull(vmExtReturned);
Assert.True(!string.IsNullOrEmpty(vmExtReturned.ProvisioningState));

Assert.True(vmExtExpected.Publisher == vmExtReturned.Publisher);
Assert.True(vmExtExpected.VirtualMachineExtensionType == vmExtReturned.VirtualMachineExtensionType);
Assert.True(vmExtExpected.AutoUpgradeMinorVersion == vmExtReturned.AutoUpgradeMinorVersion);
Assert.True(vmExtExpected.TypeHandlerVersion == vmExtReturned.TypeHandlerVersion);
}

private void ValidateVMExtensionInstanceView(VirtualMachineExtensionInstanceView vmExtInstanceView)
{
Assert.NotNull(vmExtInstanceView);
ValidateInstanceViewStatus(vmExtInstanceView.Statuses[0]);
}

private void ValidateVMHealthStatusInstanceView(VirtualMachineHealthStatus vmHealthStatus)
{
Assert.NotNull(vmHealthStatus);
ValidateInstanceViewStatus(vmHealthStatus.Status);
}

private void ValidateInstanceViewStatus(InstanceViewStatus instanceViewStatus)
{
Assert.NotNull(instanceViewStatus.DisplayStatus);
Assert.NotNull(instanceViewStatus.Code);
Assert.NotNull(instanceViewStatus.Level);
}
}
}
Loading