Skip to content

Commit 22fc904

Browse files
[Az.Batch] Adds Get-AzBatchSupportedVirtualMachineSku, Get-AzBatchTaskSlotCount, and Get-AzBatchComputeNodeExtension commands (#16459)
* [Batch] Updated BatchModelGenerator tool for SDK v15.1.0 and added reflection - Improved README and switched to markdown - Updated project to .NET 5 - Ignore GeneratedFiles directory both at compile time and in git - Added support for System.Object type (for upcoming VM extension settings) - Added mappings for new models Added reflection to BatchModelGenerator Fixed mapping * [Batch] Updated to latest SDK versions Generated models Update batch version Generated against 15.3 Compile resource files Simplified test * Add parameter IdentityId for User Assigned Identities. * Added GetSupportedVirtualMachineSku command Added alias parameter * Added GetBatchTaskSlotCount command. Fix GetTaskCLotCounts Aliased MaxTasksPerComputeNode Added deprecation notice * Fix tests Fixed flaky test TaskCount test updates * Get and List ComputeNodeExtensions Fix type Command execution implementation Added unit tests Added tests Fixed tests * Change log, command mappings, and help files Command mappings Changelog and help files Updated changelog Help files Updated help Updated help Fixed help Updated property name * Scenario Test Recordings * Cleanup Cleanup * CI Error Fixes Added default parameter set Added PSPoolSpecificiation alias property for MaxTasksPerComputeNode * PR Feedback PR Feedback * Moved previously generated file out of generated folder * Cleanup and add ability to wrap Microsoft.Azure.Batch.Common enums. * Regenerated models * Cleanup and add ability to wrap Microsoft.Azure.Batch.Common enums. Fixed nullable reference types Fixed types * Regenerated models Generated models Generated models * Fixed enum types Co-authored-by: David Watrous <[email protected]>
1 parent 37d3848 commit 22fc904

File tree

209 files changed

+16846
-19283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+16846
-19283
lines changed

src/Accounts/Accounts/AzureRmAlias/Mappings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
"Test-AzBatchAutoScale": "Test-AzureBatchAutoScale",
357357
"Get-AzBatchLocationQuotas": "Get-AzureRmBatchLocationQuotas",
358358
"Get-AzBatchSubtask": "Get-AzureBatchSubtask",
359+
"Get-AzBatchSupportedVirtualMachineSku": "Get-AzureBatchSupportedVirtualMachineSku",
359360
"Get-AzBatchTask": "Get-AzureBatchTask",
360361
"New-AzBatchTask": "New-AzureBatchTask",
361362
"Remove-AzBatchTask": "Remove-AzureBatchTask",
@@ -365,6 +366,7 @@
365366
"Set-AzBatchTask": "Set-AzureBatchTask",
366367
"Stop-AzBatchTask": "Stop-AzureBatchTask",
367368
"Get-AzBatchComputeNode": "Get-AzureBatchComputeNode",
369+
"Get-AzBatchComputeNodeExtension": "Get-AzureBatchComputeNodeExtension",
368370
"Get-AzBatchJobSchedule": "Get-AzureBatchJobSchedule",
369371
"New-AzBatchJobSchedule": "New-AzureBatchJobSchedule",
370372
"Remove-AzBatchJobSchedule": "Remove-AzureBatchJobSchedule",

src/Batch/Batch.Test/Batch.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.Azure.Batch" Version="13.0.0" />
17-
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="11.0.0" />
16+
<PackageReference Include="Microsoft.Azure.Batch" Version="15.3.0" />
17+
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="14.0.0" />
1818
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
1919
<PackageReference Include="Microsoft.Azure.Management.Network" Version="21.0.0" />
2020
</ItemGroup>

src/Batch/Batch.Test/BatchAccounts/GetBatchAccountCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void GetBatchAccount_IdentityTest()
9292
{
9393
string accountName = "account01";
9494
string resourceGroup = "resourceGroup";
95-
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, identity: new BatchAccountIdentity(ResourceIdentityType.None, string.Empty, string.Empty));
95+
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, identity: new BatchAccountIdentity(ResourceIdentityType.None, string.Empty, string.Empty, null as IDictionary<string, UserAssignedIdentities>));
9696
BatchAccountContext expected = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);
9797
batchClientMock.Setup(b => b.GetAccount(resourceGroup, accountName)).Returns(expected);
9898

src/Batch/Batch.Test/BatchTestHelpers.cs

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static BatchAccount CreateAccountResource(
8181
tags: tags == null ? null : TagsConversionHelper.CreateTagDictionary(tags, true),
8282
dedicatedCoreQuotaPerVMFamilyEnforced: dedicatedCoreQuotaPerVMFamilyEnforced,
8383
dedicatedCoreQuotaPerVMFamily: machineFamilyQuotas,
84-
identity: identity ?? new BatchAccountIdentity(ResourceIdentityType.None));
84+
identity: identity);
8585

8686
return resource;
8787
}
@@ -376,18 +376,23 @@ public static RequestInterceptor ExamineRequestInterceptor<T>(Action<T> assertAc
376376
}
377377

378378
/// <summary>
379-
/// Builds a CloudPoolGetResponse object
379+
/// Builds a CloudPoolGetResponse object using a pool ID
380380
/// </summary>
381381
public static AzureOperationResponse<ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> CreateCloudPoolGetResponse(string poolId)
382382
{
383-
var response = new AzureOperationResponse<ProxyModels.CloudPool, ProxyModels.PoolGetHeaders>();
384-
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
385-
386383
ProxyModels.CloudPool pool = new ProxyModels.CloudPool();
387384
pool.Id = poolId;
385+
return CreateCloudPoolGetResponse(pool);
386+
}
388387

388+
/// <summary>
389+
/// Builds a CloudPoolGetResponse object using a pool model
390+
/// </summary>
391+
public static AzureOperationResponse<ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> CreateCloudPoolGetResponse(ProxyModels.CloudPool pool)
392+
{
393+
var response = new AzureOperationResponse<ProxyModels.CloudPool, ProxyModels.PoolGetHeaders>();
394+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
389395
response.Body = pool;
390-
391396
return response;
392397
}
393398

@@ -552,6 +557,50 @@ public static RequestInterceptor ExamineRequestInterceptor<T>(Action<T> assertAc
552557
return response;
553558
}
554559

560+
/// <summary>
561+
/// Builds a ComputeNodeExtensionGetResponse object
562+
/// </summary>
563+
public static AzureOperationResponse<ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> CreateComputeNodeExtensionGetResponse(Azure.Batch.VMExtension extension)
564+
{
565+
var response = new AzureOperationResponse<ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders>();
566+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
567+
568+
ProxyModels.NodeVMExtension proxyExtension = CreateProxyExtension(extension);
569+
response.Body = proxyExtension;
570+
571+
return response;
572+
}
573+
574+
/// <summary>
575+
/// Builds a ComputeNodeExtensionListResponse object
576+
/// </summary>
577+
public static AzureOperationResponse<IPage<ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders> CreateComputeNodeExtensionListResponse(IEnumerable<Azure.Batch.VMExtension> extensions)
578+
{
579+
var response = new AzureOperationResponse<IPage<ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders>();
580+
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
581+
582+
List<ProxyModels.NodeVMExtension> proxyExtensions = new List<ProxyModels.NodeVMExtension>();
583+
584+
foreach (Azure.Batch.VMExtension extension in extensions)
585+
{
586+
ProxyModels.NodeVMExtension proxyExtension = CreateProxyExtension(extension);
587+
proxyExtensions.Add(proxyExtension);
588+
}
589+
590+
response.Body = new MockPagedEnumerable<ProxyModels.NodeVMExtension>(proxyExtensions);
591+
592+
return response;
593+
}
594+
595+
private static ProxyModels.NodeVMExtension CreateProxyExtension(Azure.Batch.VMExtension extension)
596+
{
597+
ProxyModels.NodeVMExtension proxyExtension = new ProxyModels.NodeVMExtension();
598+
proxyExtension.InstanceView = new ProxyModels.VMExtensionInstanceView();
599+
proxyExtension.VmExtension = new ProxyModels.VMExtension(extension.Name, extension.Publisher, extension.Type);
600+
proxyExtension.ProvisioningState = ProvisioningState.Succeeded.ToString();
601+
return proxyExtension;
602+
}
603+
555604
/// <summary>
556605
/// Builds a CloudJobScheduleGetResponse object
557606
/// </summary>
@@ -707,20 +756,33 @@ public static AzureOperationResponse<
707756
/// <summary>
708757
/// Builds a TaskCountsGetResponse object
709758
/// </summary>
710-
public static AzureOperationResponse<ProxyModels.TaskCounts, ProxyModels.JobGetTaskCountsHeaders> CreateTaskCountsGetResponse(
711-
int active, int running, int succeeded, int failed)
759+
public static AzureOperationResponse<ProxyModels.TaskCountsResult, ProxyModels.JobGetTaskCountsHeaders> CreateTaskCountsGetResponse(
760+
int requiredTaskSlots, int activeTasks, int runningTasks, int succeededTasks, int failedTasks)
712761
{
713-
var response = new AzureOperationResponse<ProxyModels.TaskCounts, ProxyModels.JobGetTaskCountsHeaders>();
762+
var response = new AzureOperationResponse<ProxyModels.TaskCountsResult, ProxyModels.JobGetTaskCountsHeaders>();
714763
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
715764

765+
var completedTasks = succeededTasks + failedTasks;
766+
716767
ProxyModels.TaskCounts taskCounts = new ProxyModels.TaskCounts();
717-
taskCounts.Active = active;
718-
taskCounts.Running = running;
719-
taskCounts.Succeeded = succeeded;
720-
taskCounts.Failed = failed;
721-
taskCounts.Completed = succeeded + failed;
768+
taskCounts.Active = activeTasks;
769+
taskCounts.Running = runningTasks;
770+
taskCounts.Succeeded = succeededTasks;
771+
taskCounts.Failed = failedTasks;
772+
taskCounts.Completed = completedTasks;
773+
774+
ProxyModels.TaskSlotCounts slotCount = new ProxyModels.TaskSlotCounts();
775+
slotCount.Active = requiredTaskSlots * activeTasks;
776+
slotCount.Running = requiredTaskSlots * runningTasks;
777+
slotCount.Succeeded = requiredTaskSlots * succeededTasks;
778+
slotCount.Failed = requiredTaskSlots * failedTasks;
779+
slotCount.Completed = requiredTaskSlots * completedTasks;
780+
781+
ProxyModels.TaskCountsResult result = new ProxyModels.TaskCountsResult();
782+
result.TaskCounts = taskCounts;
783+
result.TaskSlotCounts = slotCount;
722784

723-
response.Body = taskCounts;
785+
response.Body = result;
724786

725787
return response;
726788
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Batch;
16+
using Microsoft.Azure.Batch.Protocol;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using Microsoft.Rest.Azure;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Diagnostics;
24+
using System.Linq;
25+
using System.Management.Automation;
26+
using System.Threading.Tasks;
27+
using Xunit;
28+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
29+
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;
30+
31+
namespace Microsoft.Azure.Commands.Batch.Test.ComputeNodeExtensions
32+
{
33+
public class GetBatchComputeNodeExtensionCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
34+
{
35+
private GetBatchComputeNodeExtensionCommand cmdlet;
36+
private Mock<BatchClient> batchClientMock;
37+
private Mock<ICommandRuntime> commandRuntimeMock;
38+
39+
public GetBatchComputeNodeExtensionCommandTests(Xunit.Abstractions.ITestOutputHelper output)
40+
{
41+
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagement.Common.Models.XunitTracingInterceptor(output));
42+
batchClientMock = new Mock<BatchClient>();
43+
commandRuntimeMock = new Mock<ICommandRuntime>();
44+
cmdlet = new GetBatchComputeNodeExtensionCommand()
45+
{
46+
CommandRuntime = commandRuntimeMock.Object,
47+
BatchClient = batchClientMock.Object,
48+
};
49+
}
50+
51+
[Fact]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void GetBatchComputeNodeExtensionTest()
54+
{
55+
string extensionName = "testExtension";
56+
string publisher = "testPublisher";
57+
string type = "testType";
58+
59+
// Setup cmdlet to get a compute node by id
60+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
61+
cmdlet.BatchContext = context;
62+
cmdlet.PoolId = "testPool";
63+
cmdlet.ComputeNodeId = "testComputeNode";
64+
cmdlet.Name = extensionName;
65+
66+
VMExtension extension = new VMExtension(extensionName, publisher, type);
67+
68+
// Build an extension instead of querying the service on a Get ComputeNodeExtension call
69+
AzureOperationResponse<ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension);
70+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
71+
ProxyModels.ComputeNodeExtensionGetOptions,
72+
AzureOperationResponse<ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders>>(response);
73+
74+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
75+
76+
// Setup the cmdlet to write pipeline output to a list that can be examined later
77+
List<PSNodeVMExtension> pipeline = new List<PSNodeVMExtension>();
78+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSNodeVMExtension>())).Callback<object>(c => pipeline.Add((PSNodeVMExtension)c));
79+
80+
cmdlet.ExecuteCmdlet();
81+
82+
// Verify that the cmdlet wrote the compute node returned from the OM to the pipeline
83+
Assert.Single(pipeline);
84+
85+
PSVMExtension pipelineExtension = pipeline[0].VmExtension;
86+
Assert.NotNull(pipelineExtension);
87+
Assert.Equal("testExtension", pipelineExtension.Name);
88+
Assert.Equal("testPublisher", pipelineExtension.Publisher);
89+
Assert.Equal("testType", pipelineExtension.Type);
90+
}
91+
92+
[Fact]
93+
[Trait(Category.AcceptanceType, Category.CheckIn)]
94+
public void GetBatchComputeNodeExtensionODataTest()
95+
{
96+
string extensionName = "testExtension";
97+
string publisher = "testPublisher";
98+
string type = "testType";
99+
100+
// Setup cmdlet to get a compute node by id
101+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
102+
cmdlet.BatchContext = context;
103+
cmdlet.PoolId = "testPool";
104+
cmdlet.ComputeNodeId = "testComputeNode";
105+
cmdlet.Name = extensionName;
106+
cmdlet.Select = "ExtensionName,Publisher";
107+
108+
VMExtension extension = new VMExtension(extensionName, publisher, type);
109+
110+
// Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
111+
AzureOperationResponse<ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> getResponse = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension);
112+
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
113+
ProxyModels.ComputeNodeExtensionGetOptions,
114+
AzureOperationResponse<ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders>>(getResponse);
115+
116+
string requestSelect = null;
117+
118+
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
119+
{
120+
ProxyModels.ComputeNodeExtensionGetOptions options = (ProxyModels.ComputeNodeExtensionGetOptions)request.Options;
121+
requestSelect = options.Select;
122+
123+
return Task.FromResult(response);
124+
});
125+
126+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };
127+
128+
cmdlet.ExecuteCmdlet();
129+
130+
Assert.Equal(cmdlet.Select, requestSelect);
131+
}
132+
133+
[Fact]
134+
[Trait(Category.AcceptanceType, Category.CheckIn)]
135+
public void ListBatchComputeNodeExtensionsTest()
136+
{
137+
// Setup cmdlet to get a compute node by id
138+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
139+
cmdlet.BatchContext = context;
140+
cmdlet.PoolId = "testPool";
141+
cmdlet.ComputeNodeId = "testComputeNode";
142+
143+
int count = 5;
144+
145+
// Build an extension instead of querying the service on a Get ComputeNodeExtension call
146+
AzureOperationResponse<IPage<ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionListResponse(CreateTestExtensions(count));
147+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
148+
ProxyModels.ComputeNodeExtensionListOptions,
149+
AzureOperationResponse<IPage<ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders>>(response);
150+
151+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
152+
153+
// Setup the cmdlet to write pipeline output to a list that can be examined later
154+
List<PSNodeVMExtension> pipeline = new List<PSNodeVMExtension>();
155+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSNodeVMExtension>())).Callback<object>(c => pipeline.Add((PSNodeVMExtension)c));
156+
157+
cmdlet.ExecuteCmdlet();
158+
159+
// Verify that the cmdlet wrote the compute node returned from the OM to the pipeline
160+
Assert.Equal(count, pipeline.Count);
161+
for (int i = 1; i <= count; i++)
162+
{
163+
PSVMExtension extension = pipeline[i-1].VmExtension;
164+
Assert.Equal($"testExtension{i}", extension.Name);
165+
Assert.Equal($"testPublisher{i}", extension.Publisher);
166+
Assert.Equal($"testType{i}", extension.Type);
167+
}
168+
}
169+
170+
private IEnumerable<VMExtension> CreateTestExtensions(int count)
171+
{
172+
for (int i = 1; i <= count; i++)
173+
{
174+
yield return new VMExtension($"testExtension{i}", $"testPublisher{i}", $"testType{i}");
175+
}
176+
}
177+
178+
[Fact]
179+
[Trait(Category.AcceptanceType, Category.CheckIn)]
180+
public void ListBatchComputeNodeExtensionsWithMaxCountTest()
181+
{
182+
int maxCount = 3;
183+
184+
// Setup cmdlet to get a compute node by id
185+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
186+
cmdlet.BatchContext = context;
187+
cmdlet.PoolId = "testPool";
188+
cmdlet.ComputeNodeId = "testComputeNode";
189+
cmdlet.MaxCount = maxCount;
190+
191+
int count = 5;
192+
193+
// Build an extension instead of querying the service on a Get ComputeNodeExtension call
194+
AzureOperationResponse<IPage<ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionListResponse(CreateTestExtensions(count));
195+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
196+
ProxyModels.ComputeNodeExtensionListOptions,
197+
AzureOperationResponse<IPage<ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders>>(response);
198+
199+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
200+
201+
// Setup the cmdlet to write pipeline output to a list that can be examined later
202+
List<PSNodeVMExtension> pipeline = new List<PSNodeVMExtension>();
203+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSNodeVMExtension>())).Callback<object>(c => pipeline.Add((PSNodeVMExtension)c));
204+
205+
cmdlet.ExecuteCmdlet();
206+
207+
// Verify that the cmdlet wrote the compute node returned from the OM to the pipeline
208+
Assert.Equal(maxCount, pipeline.Count);
209+
for (int i = 1; i <= maxCount; i++)
210+
{
211+
PSVMExtension extension = pipeline[i - 1].VmExtension;
212+
Assert.Equal($"testExtension{i}", extension.Name);
213+
Assert.Equal($"testPublisher{i}", extension.Publisher);
214+
Assert.Equal($"testType{i}", extension.Type);
215+
}
216+
}
217+
}
218+
}

0 commit comments

Comments
 (0)