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
3 changes: 2 additions & 1 deletion src/SDKs/Compute/Compute.Tests/Compute.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="4.2.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="10.0.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
<PackageReference Include="WindowsAzure.Storage" Version="8.7.0"/>
<ProjectReference Include="..\Management.Compute\Microsoft.Azure.Management.Compute.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public void TestContainerServiceUpdateOperations()
ValidateContainerService(inputContainerService, containerService);

var listResult = m_CrpClient.ContainerServices.ListByResourceGroup(rgName);
#if NET46
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we do not support .NET 46, this piece of code will never be executed.
Any reason for adding .NET 46 moniker?

Assert.True(listResult.Any(a => a.Name == containerService.Name));
#else
Assert.Contains(listResult, a => a.Name == containerService.Name);
#endif
m_CrpClient.ContainerServices.Delete(rgName, containerService.Name);
var listResultAfterDeletion = m_CrpClient.ContainerServices.ListByResourceGroup(rgName);
Assert.True(!listResultAfterDeletion.Any());
Expand Down
4 changes: 2 additions & 2 deletions src/SDKs/Compute/Compute.Tests/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static List<VirtualMachineSize> GetExpectedVirtualMachineSize(bool hasAZ
{
expectedVMSizePropertiesList.Add(new VirtualMachineSize()
{
Name = "Standard_M64s",
Name = VirtualMachineSizeTypes.StandardM64s,
MemoryInMB = 1024000,
NumberOfCores = 64,
OsDiskSizeInMB = 1047552,
Expand All @@ -80,7 +80,7 @@ private static List<VirtualMachineSize> GetExpectedVirtualMachineSize(bool hasAZ
});
expectedVMSizePropertiesList.Add(new VirtualMachineSize()
{
Name = "Standard_M64-16ms",
Name = VirtualMachineSizeTypes.StandardM6416ms,
MemoryInMB = 1792000,
NumberOfCores = 64,
OsDiskSizeInMB = 1047552,
Expand Down
4 changes: 4 additions & 0 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/HelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public class HelpersTests
public void TestUtilityFunctions()
{
Assert.Equal("Compute.Tests.HelpersTests", this.GetType().FullName);
#if NET46
Assert.Equal("TestUtilityFunctions", TestUtilities.GetCurrentMethodName(1));
#else
Assert.Equal("TestUtilityFunctions", TestUtilities.GetCurrentMethodName());
#endif
}
}
}
114 changes: 114 additions & 0 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/LogAnalyticsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Storage.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Linq;
using Xunit;

namespace Compute.Tests
{
public class LogAnalyticsTests : VMTestBase
{
[Fact]
public void TestExportingThrottlingLogs()
{
using (MockContext context = MockContext.Start(this.GetType().FullName))
{
EnsureClientsInitialized(context);

string rg1Name = ComputeManagementTestUtilities.GenerateName(TestPrefix);

string storageAccountName = ComputeManagementTestUtilities.GenerateName(TestPrefix);

try
{
string sasUri = GetBlobContainerSasUri(rg1Name, storageAccountName);

RequestRateByIntervalInput requestRateByIntervalInput = new RequestRateByIntervalInput()
{
BlobContainerSasUri = sasUri,
FromTime = DateTime.UtcNow.AddDays(-10),
ToTime = DateTime.UtcNow.AddDays(-8),
IntervalLength = IntervalInMins.FiveMins,
};

LogAnalyticsOperationResult result = m_CrpClient.LogAnalytics.ExportRequestRateByInterval(requestRateByIntervalInput, "westcentralus");

Assert.Equal("Succeeded", result.Status);
#if NET46
Assert.True(result.Properties.Output.EndsWith(".csv"));
#else
Assert.EndsWith(".csv", result.Properties.Output);
#endif

ThrottledRequestsInput throttledRequestsInput = new ThrottledRequestsInput()
{
BlobContainerSasUri = sasUri,
FromTime = DateTime.UtcNow.AddDays(-10),
ToTime = DateTime.UtcNow.AddDays(-8),
GroupByOperationName = true,
};

result = m_CrpClient.LogAnalytics.ExportThrottledRequests(throttledRequestsInput, "westcentralus");

Assert.Equal("Succeeded", result.Status);
#if NET46
Assert.True(result.Properties.Output.EndsWith(".csv"));
#else
Assert.EndsWith(".csv", result.Properties.Output);
#endif
}
finally
{
m_ResourcesClient.ResourceGroups.Delete(rg1Name);
}
}
}

private string GetBlobContainerSasUri(string rg1Name, string storageAccountName)
{
string sasUri = "foobar";

if (HttpMockServer.Mode == HttpRecorderMode.Record)
{
StorageAccount storageAccountOutput = CreateStorageAccount(rg1Name, storageAccountName);
var accountKeyResult = m_SrpClient.StorageAccounts.ListKeysWithHttpMessagesAsync(rg1Name, storageAccountName).Result;
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials(storageAccountName, accountKeyResult.Body.Key1), useHttps: true);

var blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("sascontainer");
#if NET46
container.CreateIfNotExists();
#else
container.CreateIfNotExistsAsync();
#endif
sasUri = GetContainerSasUri(container);
}

return sasUri;
}

private string GetContainerSasUri(CloudBlobContainer container)
{
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5);
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24);
sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write;

//Generate the shared access signature on the blob, setting the constraints directly on the signature.
string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);

//Return the URI string for the container, including the SAS token.
return container.Uri + sasContainerToken;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,19 @@ private void ValidateWinRMCustomDataAndUnattendContent(string winRMCertificateUr
Assert.Null(listeners[0].CertificateUrl);

Assert.True(listeners[1].Protocol == ProtocolTypes.Https);
#if NET46
Assert.True(listeners[1].CertificateUrl.Equals(winRMCertificateUrl, StringComparison.OrdinalIgnoreCase));
#else
Assert.Equal(listeners[1].CertificateUrl, winRMCertificateUrl, ignoreCase: true);
#endif
}
else if (listeners[0].Protocol == ProtocolTypes.Https)
{
#if NET46
Assert.True(listeners[0].CertificateUrl.Equals(winRMCertificateUrl, StringComparison.OrdinalIgnoreCase));
#else
Assert.Equal(listeners[0].CertificateUrl, winRMCertificateUrl, ignoreCase: true);
#endif

Assert.True(listeners[1].Protocol == ProtocolTypes.Http);
Assert.Null(listeners[1].CertificateUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void TestVMScenarioOperations_ManagedDisks()
try
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2");
TestVMScenarioOperationsInternal("TestVMScenarioOperations_ManagedDisks", vmSize: "Standard_M64s", hasManagedDisks: true,
TestVMScenarioOperationsInternal("TestVMScenarioOperations_ManagedDisks", vmSize: VirtualMachineSizeTypes.StandardM64s, hasManagedDisks: true,
storageAccountType: StorageAccountTypes.PremiumLRS, writeAcceleratorEnabled: true);
}
finally
Expand Down
8 changes: 8 additions & 0 deletions src/SDKs/Compute/Compute.Tests/ScenarioTests/VMTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,11 @@ protected void ValidateVMInstanceView(VirtualMachine vmIn, VirtualMachineInstanc
private void ValidateVMInstanceView(VirtualMachineInstanceView vmInstanceView, bool hasManagedDisks = false, string osDiskName = null,
string expectedComputerName = null, string expectedOSName = null, string expectedOSVersion = null)
{
#if NET46
Assert.True(vmInstanceView.Statuses.Any(s => !string.IsNullOrEmpty(s.Code)));
#else
Assert.Contains(vmInstanceView.Statuses, s => !string.IsNullOrEmpty(s.Code));
#endif

if (!hasManagedDisks)
{
Expand All @@ -993,7 +997,11 @@ private void ValidateVMInstanceView(VirtualMachineInstanceView vmInstanceView, b

if (osDiskName != null)
{
#if NET46
Assert.True(vmInstanceView.Disks.Any(x => x.Name == osDiskName));
#else
Assert.Contains(vmInstanceView.Disks, x => x.Name == osDiskName);
#endif
}

DiskInstanceView diskInstanceView = vmInstanceView.Disks.First();
Expand Down
Loading