Skip to content

Commit ff02500

Browse files
author
jasper-schneider
committed
Add support for multiple compute nodes
1 parent 2780755 commit ff02500

File tree

12 files changed

+2028
-54
lines changed

12 files changed

+2028
-54
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@
371371
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveComputeNodePipeline.json">
372372
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
373373
</None>
374+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRemoveMultipleComputeNodes.json">
375+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
376+
</None>
374377
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeUserTests\TestCreateComputeNodeUser.json">
375378
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
376379
</None>

src/ResourceManager/AzureBatch/Commands.Batch.Test/ComputeNodes/RemoveBatchComputeNodeCommandTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public void RemoveBatchComputeNodeParametersTest()
5454

5555
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
5656
cmdlet.BatchContext = context;
57-
cmdlet.Id = null;
57+
cmdlet.Ids = null;
5858

5959
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
6060

6161
cmdlet.PoolId = "testPool";
6262

6363
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
6464

65-
cmdlet.Id = "computeNode1";
65+
cmdlet.Ids = new string[] { "computeNode1" };
6666

6767
// Don't go to the service on a Remove ComputeNode call
6868
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeRemoveParameters, ComputeNodeRemoveResponse>();
@@ -84,12 +84,13 @@ public void RemoveComputeNodeRequestTest()
8484
cmdlet.BatchContext = context;
8585

8686
cmdlet.PoolId = "testPool";
87-
cmdlet.Id = "computeNode1";
87+
cmdlet.Ids = new string[] { "computeNode1", "computeNode2" };
8888
cmdlet.DeallocationOption = ComputeNodeDeallocationOption.Terminate;
8989
cmdlet.ResizeTimeout = TimeSpan.FromMinutes(8);
9090

9191
ComputeNodeDeallocationOption? requestDeallocationOption = null;
9292
TimeSpan? requestResizeTimeout = null;
93+
IList<string> requestComputeNodeIds = null;
9394

9495
// Don't go to the service on a Remove ComputeNode call
9596
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
@@ -102,6 +103,7 @@ public void RemoveComputeNodeRequestTest()
102103
// Grab the parameters from the outgoing request.
103104
requestDeallocationOption = request.TypedParameters.ComputeNodeDeallocationOption;
104105
requestResizeTimeout = request.TypedParameters.ResizeTimeout;
106+
requestComputeNodeIds = request.TypedParameters.ComputeNodeIds;
105107

106108
ComputeNodeRemoveResponse response = new ComputeNodeRemoveResponse();
107109
Task<ComputeNodeRemoveResponse> task = Task.FromResult(response);
@@ -115,6 +117,11 @@ public void RemoveComputeNodeRequestTest()
115117
// Verify that the parameters were properly set on the outgoing request
116118
Assert.Equal(cmdlet.DeallocationOption, requestDeallocationOption);
117119
Assert.Equal(cmdlet.ResizeTimeout, requestResizeTimeout);
120+
Assert.Equal(cmdlet.Ids.Length, requestComputeNodeIds.Count);
121+
foreach (string id in cmdlet.Ids)
122+
{
123+
Assert.True(requestComputeNodeIds.Contains(id));
124+
}
118125
}
119126
}
120127
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/ComputeNodeTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,34 @@ public void TestRemoveComputeNodePipeline()
137137
TestRemoveComputeNode(true, TestUtilities.GetCurrentMethodName());
138138
}
139139

140+
[Fact]
141+
[Trait(Category.AcceptanceType, Category.CheckIn)]
142+
public void TestRemoveMultipleComputeNodes()
143+
{
144+
BatchController controller = BatchController.NewInstance;
145+
BatchAccountContext context = null;
146+
string computeNodeId = null;
147+
string computeNodeId2 = null;
148+
int originalDedicated = 3;
149+
controller.RunPsTestWorkflow(
150+
() => { return new string[] { string.Format("Test-RemoveMultipleComputeNodes '{0}' '{1}' '{2}' '{3}'", accountName, poolId, computeNodeId, computeNodeId2) }; },
151+
() =>
152+
{
153+
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, accountName);
154+
originalDedicated = ScenarioTestHelpers.GetPoolCurrentDedicated(controller, context, poolId);
155+
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, poolId);
156+
ScenarioTestHelpers.ResizePool(controller, context, poolId, originalDedicated + 2);
157+
ScenarioTestHelpers.WaitForSteadyPoolAllocation(controller, context, poolId);
158+
computeNodeId = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId);
159+
ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId);
160+
computeNodeId2 = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId, 1);
161+
ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId2);
162+
},
163+
null,
164+
TestUtilities.GetCallingClass(),
165+
TestUtilities.GetCurrentMethodName());
166+
}
167+
140168
[Fact]
141169
[Trait(Category.AcceptanceType, Category.CheckIn)]
142170
public void TestRebootComputeNodeById()

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/ComputeNodeTests.ps1

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ function Test-RemoveComputeNode
172172
}
173173

174174
# State transition isn't immediate
175-
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -Select "id,state" -BatchContext $context
175+
$filter = "id eq '$computeNodeId'"
176+
$select = "id,state"
177+
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter $filter -Select $select -BatchContext $context
176178
$start = [DateTime]::Now
177179
$end = $start.AddSeconds(30)
178180
while ($computeNode.State -ne 'LeavingPool')
@@ -182,7 +184,36 @@ function Test-RemoveComputeNode
182184
throw [System.TimeoutException] "Timed out waiting for compute node to enter LeavingPool state"
183185
}
184186
Start-TestSleep 1000
185-
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -Select "id,state" -BatchContext $context
187+
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter $filter -Select $select -BatchContext $context
188+
}
189+
}
190+
191+
<#
192+
.SYNOPSIS
193+
Tests removing multiple compute nodes from a pool
194+
#>
195+
function Test-RemoveMultipleComputeNodes
196+
{
197+
param([string]$accountName, [string]$poolId, [string]$computeNodeId, [string]$computeNodeId2)
198+
199+
$context = Get-ScenarioTestContext $accountName
200+
201+
Remove-AzureBatchComputeNode $poolId @($computeNodeId, $computeNodeId2) -Force -BatchContext $context
202+
203+
# State transition isn't immediate
204+
$filter = "(id eq '$computeNodeId') or (id eq '$computeNodeId2')"
205+
$select = "id,state"
206+
$computeNodes = Get-AzureBatchComputeNode -PoolId $poolId -Filter $filter -Select $select -BatchContext $context
207+
$start = [DateTime]::Now
208+
$end = $start.AddSeconds(30)
209+
while ($computeNodes[0].State -ne 'LeavingPool' -and $computeNodes[1].State -ne 'LeavingPool')
210+
{
211+
if ([DateTime]::Now -gt $end)
212+
{
213+
throw [System.TimeoutException] "Timed out waiting for compute nodes to enter LeavingPool state"
214+
}
215+
Start-TestSleep 1000
216+
$computeNodes = Get-AzureBatchComputeNode -PoolId $poolId -Filter $filter -Select $select -BatchContext $context
186217
}
187218
}
188219

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/ScenarioTestHelpers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ public static void TerminateJob(BatchController controller, BatchAccountContext
476476
/// <summary>
477477
/// Gets the id of a compute node in the specified pool
478478
/// </summary>
479-
public static string GetComputeNodeId(BatchController controller, BatchAccountContext context, string poolId)
479+
public static string GetComputeNodeId(BatchController controller, BatchAccountContext context, string poolId, int index = 0)
480480
{
481481
BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);
482482

483483
ListComputeNodeOptions options = new ListComputeNodeOptions(context, poolId, null);
484-
485-
return client.ListComputeNodes(options).First().Id;
484+
List<PSComputeNode> computeNodes = client.ListComputeNodes(options).ToList();
485+
return computeNodes[index].Id;
486486
}
487487

488488
/// <summary>

0 commit comments

Comments
 (0)