Skip to content

Update Batch preview module to support data plane API version 2019-08-01.10.0 and mgmt API version 2019-08-01 #10001

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

Merged
merged 7 commits into from
Sep 20, 2019
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
4 changes: 2 additions & 2 deletions src/Batch/Batch.Test/Batch.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Batch" Version="10.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="7.0.0" />
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="9.0.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
public class GetBatchNodeAgentSkusCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
public class GetBatchSupportedImagesCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
{
private GetBatchAccountNodeAgentSkuCommand cmdlet;
private GetBatchAccountSupportedImagesCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

public GetBatchNodeAgentSkusCommandTests(Xunit.Abstractions.ITestOutputHelper output)
public GetBatchSupportedImagesCommandTests(Xunit.Abstractions.ITestOutputHelper output)
{
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagement.Common.Models.XunitTracingInterceptor(output));
batchClientMock = new Mock<BatchClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new GetBatchAccountNodeAgentSkuCommand()
cmdlet = new GetBatchAccountSupportedImagesCommand()
{
CommandRuntime = commandRuntimeMock.Object,
BatchClient = batchClientMock.Object,
Expand All @@ -48,45 +48,45 @@ public GetBatchNodeAgentSkusCommandTests(Xunit.Abstractions.ITestOutputHelper ou

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchNodeAgentSkusParametersTest()
public void ListBatchSupportedImagesParametersTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

string[] idsOfNodeAgentSkus = new[] { "batch.node.centos 7", "batch.node.debian 8", "batch.node.opensuse 13.2" };

// Don't go to the service on an Get NodeAgentSkus call
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> response =
BatchTestHelpers.CreateNodeAgentSkuResponse(idsOfNodeAgentSkus);
AzureOperationResponse<IPage<ProxyModels.ImageInformation>, ProxyModels.AccountListSupportedImagesHeaders> response =
BatchTestHelpers.CreateSupportedImagesResponse(idsOfNodeAgentSkus);

RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
ProxyModels.AccountListNodeAgentSkusOptions,
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>>(responseToUse: response);
ProxyModels.AccountListSupportedImagesOptions,
AzureOperationResponse<IPage<ProxyModels.ImageInformation>, ProxyModels.AccountListSupportedImagesHeaders>>(responseToUse: response);

cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Setup the cmdlet to write pipeline output to a list that can be examined later
List<PSNodeAgentSku> pipeline = new List<PSNodeAgentSku>();
var pipeline = new List<PSImageInformation>();
commandRuntimeMock.Setup(r =>
r.WriteObject(It.IsAny<PSNodeAgentSku>()))
.Callback<object>(p => pipeline.Add((PSNodeAgentSku)p));
r.WriteObject(It.IsAny<PSImageInformation>()))
.Callback<object>(p => pipeline.Add((PSImageInformation)p));

// Verify no exceptions when required parameter is set
cmdlet.ExecuteCmdlet();

Assert.Equal(3, pipeline.Count);
int nodeAgentCount = 0;
foreach (PSNodeAgentSku p in pipeline)
foreach (PSImageInformation imageInfo in pipeline)
{
Assert.Contains(p.Id, idsOfNodeAgentSkus);
Assert.Contains(imageInfo.NodeAgentSkuId, idsOfNodeAgentSkus);
nodeAgentCount++;
}
Assert.Equal(idsOfNodeAgentSkus.Length, nodeAgentCount);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchNodeAgentSkusWithFilterTest()
public void ListBatchSupportedImagesWithFilterTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
Expand All @@ -95,11 +95,14 @@ public void ListBatchNodeAgentSkusWithFilterTest()
string requestFilter = null;

// Don't go to the service on an Get NodeAgentSkus call
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> getResponse = BatchTestHelpers.CreateGenericAzureOperationListResponse<ProxyModels.NodeAgentSku, ProxyModels.AccountListNodeAgentSkusHeaders>();
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.AccountListNodeAgentSkusOptions, AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>>(responseToUse: getResponse);
var getResponse = BatchTestHelpers.CreateGenericAzureOperationListResponse<ProxyModels.ImageInformation, ProxyModels.AccountListSupportedImagesHeaders>();
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
ProxyModels.AccountListSupportedImagesOptions,
AzureOperationResponse<IPage<ProxyModels.ImageInformation>,
ProxyModels.AccountListSupportedImagesHeaders>>(responseToUse: getResponse);
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
ProxyModels.AccountListNodeAgentSkusOptions listNodeAgentSkusOptions = (ProxyModels.AccountListNodeAgentSkusOptions)request.Options;
var listNodeAgentSkusOptions = (ProxyModels.AccountListSupportedImagesOptions)request.Options;
requestFilter = listNodeAgentSkusOptions.Filter;

return Task.FromResult(response);
Expand Down
26 changes: 18 additions & 8 deletions src/Batch/Batch.Test/BatchTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ public static class BatchTestHelpers
/// <summary>
/// Builds an AccountResource object using the specified parameters
/// </summary>
public static BatchAccount CreateAccountResource(string accountName, string resourceGroupName, string location = "location",
Hashtable tags = null, string storageId = null)
public static BatchAccount CreateAccountResource(
string accountName,
string resourceGroupName,
string location = "location",
Hashtable tags = null,
string storageId = null,
bool dedicatedCoreQuotaPerVMFamilyEnforced = false,
IList<VirtualMachineFamilyCoreQuota> machineFamilyQuotas = null)
{
string tenantUrlEnding = "batch-test.windows-int.net";
string endpoint = string.Format("{0}.{1}", accountName, tenantUrlEnding);
Expand All @@ -58,6 +64,8 @@ public static BatchAccount CreateAccountResource(string accountName, string reso

string id = string.Format("id/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Batch/batchAccounts/abc", subscription, resourceGroup);

machineFamilyQuotas = machineFamilyQuotas ?? new List<VirtualMachineFamilyCoreQuota> { new VirtualMachineFamilyCoreQuota("foo", 55 ) };

BatchAccount resource = new BatchAccount(
dedicatedCoreQuota: DefaultQuotaCount,
lowPriorityCoreQuota: DefaultQuotaCount,
Expand All @@ -69,7 +77,9 @@ public static BatchAccount CreateAccountResource(string accountName, string reso
location: location,
provisioningState: ProvisioningState.Succeeded,
autoStorage: new AutoStorageProperties() { StorageAccountId = storageId },
tags: tags == null ? null : TagsConversionHelper.CreateTagDictionary(tags, true));
tags: tags == null ? null : TagsConversionHelper.CreateTagDictionary(tags, true),
dedicatedCoreQuotaPerVMFamilyEnforced: dedicatedCoreQuotaPerVMFamilyEnforced,
dedicatedCoreQuotaPerVMFamily: machineFamilyQuotas);

return resource;
}
Expand Down Expand Up @@ -796,15 +806,15 @@ public static AzureOperationResponse<
/// <summary>
/// Builds a NodeAgentSKUResponse object
/// </summary>
public static AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> CreateNodeAgentSkuResponse(IEnumerable<string> skuIds)
public static AzureOperationResponse<IPage<ProxyModels.ImageInformation>, ProxyModels.AccountListSupportedImagesHeaders> CreateSupportedImagesResponse(IEnumerable<string> skuIds)
{
IEnumerable<ProxyModels.NodeAgentSku> nodeAgents =
skuIds.Select(id => new ProxyModels.NodeAgentSku() { Id = id });
IEnumerable<ProxyModels.ImageInformation> imageInfo =
skuIds.Select(id => new ProxyModels.ImageInformation() { NodeAgentSKUId = id });

var response = new AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>()
var response = new AzureOperationResponse<IPage<ProxyModels.ImageInformation>, ProxyModels.AccountListSupportedImagesHeaders>()
{
Response = new HttpResponseMessage(HttpStatusCode.OK),
Body = new MockPagedEnumerable<ProxyModels.NodeAgentSku>(nodeAgents)
Body = new MockPagedEnumerable<ProxyModels.ImageInformation>(imageInfo)
};

return response;
Expand Down
5 changes: 5 additions & 0 deletions src/Batch/Batch.Test/Pools/NewBatchPoolCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void NewBatchPoolParametersGetPassedToRequestTest()
cmdlet.TaskSchedulingPolicy = new PSTaskSchedulingPolicy(Azure.Batch.Common.ComputeNodeFillType.Spread);
cmdlet.VirtualMachineConfiguration = new PSVirtualMachineConfiguration(new PSImageReference("offer", "publisher", "sku"), "node agent");
cmdlet.VirtualMachineSize = "small";
cmdlet.MountConfiguration = new[] { new PSMountConfiguration(new PSAzureBlobFileSystemConfiguration("foo", "bar", "baz", AzureStorageAuthenticationKey.FromAccountKey("abc"))) };

PoolAddParameter requestParameters = null;

Expand Down Expand Up @@ -142,6 +143,10 @@ public void NewBatchPoolParametersGetPassedToRequestTest()
Assert.Equal(cmdlet.VirtualMachineConfiguration.ImageReference.Offer, requestParameters.VirtualMachineConfiguration.ImageReference.Offer);
Assert.Equal(cmdlet.VirtualMachineConfiguration.ImageReference.Sku, requestParameters.VirtualMachineConfiguration.ImageReference.Sku);
Assert.Equal(cmdlet.VirtualMachineSize, requestParameters.VmSize);
Assert.Equal(cmdlet.MountConfiguration[0].AzureBlobFileSystemConfiguration.AccountName, requestParameters.MountConfiguration[0].AzureBlobFileSystemConfiguration.AccountName);
Assert.Equal(cmdlet.MountConfiguration[0].AzureBlobFileSystemConfiguration.AccountKey, requestParameters.MountConfiguration[0].AzureBlobFileSystemConfiguration.AccountKey);
Assert.Equal(cmdlet.MountConfiguration[0].AzureBlobFileSystemConfiguration.ContainerName, requestParameters.MountConfiguration[0].AzureBlobFileSystemConfiguration.ContainerName);
Assert.Equal(cmdlet.MountConfiguration[0].AzureBlobFileSystemConfiguration.RelativeMountPath, requestParameters.MountConfiguration[0].AzureBlobFileSystemConfiguration.RelativeMountPath);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/Batch/Batch.Test/ScenarioTests/BatchAccountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void TestBatchAccountEndToEnd()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestListNodeAgentSkus()
public void TestGetBatchSupportedImages()
{
BatchController.NewInstance.RunPsTest(_logger, "Test-GetBatchNodeAgentSkus");
BatchController.NewInstance.RunPsTest(_logger, "Test-GetBatchSupportedImage");
}
}
}
14 changes: 7 additions & 7 deletions src/Batch/Batch.Test/ScenarioTests/BatchAccountTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ function Test-BatchAccountEndToEnd

<#
.SYNOPSIS
Tests getting a list of Batch node agent skus
Tests getting a list of Batch supported images
#>
function Test-GetBatchNodeAgentSkus
function Test-GetBatchSupportedImage
{
$context = New-Object Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ScenarioTestContext

# Get the node agent skus
$nodeAgentSkus = Get-AzBatchNodeAgentSku -BatchContext $context
$supportedImages = Get-AzBatchSupportedImage -BatchContext $context

foreach($nodeAgentSku in $nodeAgentSkus)
foreach($supportedImage in $supportedImages)
{
Assert-True { $nodeAgentSku.Id.StartsWith("batch.node") }
Assert-True { $nodeAgentSku.OSType -in "linux","windows" }
Assert-AreNotEqual $null $nodeAgentSku.VerifiedImageReferences
Assert-True { $supportedImage.NodeAgentSkuId.StartsWith("batch.node") }
Assert-True { $supportedImage.OSType -in "linux","windows" }
Assert-AreNotEqual $null $supportedImage.VerificationType
}
}
2 changes: 1 addition & 1 deletion src/Batch/Batch.Test/ScenarioTests/CertificateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void TestCancelCertificateDelete()
() =>
{
context = new ScenarioTestContext();
thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName);
thumbprint = ScenarioTestHelpers.AddTestCertificate(controller, context, BatchTestHelpers.TestCertificateFileName).ToLowerInvariant();
CertificateReference certRef = new CertificateReference();
certRef.StoreLocation = CertStoreLocation.CurrentUser;
certRef.StoreName = "My";
Expand Down
2 changes: 1 addition & 1 deletion src/Batch/Batch.Test/ScenarioTests/CertificateTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ function Test-TestCancelCertificateDelete
$filter = "state eq 'active'"
$cert = Get-AzBatchCertificate -Filter $filter -BatchContext $context

Assert-AreEqual $thumbprint $cert.Thumbprint
Assert-AreEqual $thumbprint $cert.Thumbprint.ToLowerInvariant()
}
Loading