Skip to content

Commit 2dca584

Browse files
committed
Merge pull request #292 from Azure/dev
.
2 parents fb72755 + aecf42f commit 2dca584

File tree

213 files changed

+29595
-19023
lines changed

Some content is hidden

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

213 files changed

+29595
-19023
lines changed

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchTestHelpers.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,28 @@ public static ProxyModels.CloudTaskListResponse CreateCloudTaskListResponse(IEnu
401401
return response;
402402
}
403403

404+
/// <summary>
405+
/// Builds a CloudTaskListSubtasksResponse object
406+
/// </summary>
407+
public static ProxyModels.CloudTaskListSubtasksResponse CreateCloudTaskListSubtasksResponse(IEnumerable<int> subtaskIds)
408+
{
409+
ProxyModels.CloudTaskListSubtasksResponse response = new ProxyModels.CloudTaskListSubtasksResponse();
410+
response.StatusCode = HttpStatusCode.OK;
411+
412+
List<ProxyModels.SubtaskInformation> subtasks = new List<ProxyModels.SubtaskInformation>();
413+
414+
foreach (int id in subtaskIds)
415+
{
416+
ProxyModels.SubtaskInformation subtask = new ProxyModels.SubtaskInformation();
417+
subtask.Id = id;
418+
subtasks.Add(subtask);
419+
}
420+
421+
response.SubtasksInformation = subtasks;
422+
423+
return response;
424+
}
425+
404426
/// <summary>
405427
/// Builds a NodeFileGetPropertiesResponse object
406428
/// </summary>

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
<Reference Include="Hyak.Common">
4444
<HintPath>..\..\..\packages\Hyak.Common.1.0.2\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
4545
</Reference>
46-
<Reference Include="Microsoft.Azure.Batch, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47-
<SpecificVersion>False</SpecificVersion>
48-
<HintPath>..\..\..\packages\Azure.Batch.2.0.2\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
46+
<Reference Include="Microsoft.Azure.Batch, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<HintPath>..\..\..\packages\Azure.Batch.3.0.0\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
48+
<Private>True</Private>
4949
</Reference>
5050
<Reference Include="Microsoft.Azure.Common">
5151
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
@@ -180,6 +180,8 @@
180180
<Compile Include="Certificates\NewBatchCertificateCommandTests.cs" />
181181
<Compile Include="Certificates\RemoveBatchCertificateCommandTests.cs" />
182182
<Compile Include="Certificates\StopBatchCertificateDeletionCommandTests.cs" />
183+
<Compile Include="ComputeNodes\DisableBatchComputeNodeSchedulingCommandTests.cs" />
184+
<Compile Include="ComputeNodes\EnableBatchComputeNodeSchedulingCommandTests.cs" />
183185
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommandTests.cs" />
184186
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
185187
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommandTests.cs" />
@@ -225,6 +227,7 @@
225227
<Compile Include="ScenarioTests\ComputeNodeTests.cs" />
226228
<Compile Include="ScenarioTests\JobScheduleTests.cs" />
227229
<Compile Include="Subscriptions\GetBatchSubscriptionQuotasCommandTests.cs" />
230+
<Compile Include="Tasks\GetBatchSubtaskCommandTests.cs" />
228231
<Compile Include="Tasks\GetBatchTaskCommandTests.cs" />
229232
<Compile Include="Tasks\NewBatchTaskCommandTests.cs" />
230233
<Compile Include="Tasks\RemoveBatchTaskCommandTests.cs" />
@@ -335,6 +338,12 @@
335338
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestListCertificatesWithMaxCount.json">
336339
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
337340
</None>
341+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestDisableAndEnableComputeNodeSchedulingById.json">
342+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
343+
</None>
344+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestDisableAndEnableComputeNodeSchedulingPipeline.json">
345+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
346+
</None>
338347
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetAndListComputeNodesWithSelect.json">
339348
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
340349
</None>
@@ -608,9 +617,15 @@
608617
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestGetTaskById.json">
609618
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
610619
</None>
620+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListAllSubtasks.json">
621+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
622+
</None>
611623
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListAllTasks.json">
612624
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
613625
</None>
626+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListSubtasksWithMaxCount.json">
627+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
628+
</None>
614629
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListTaskPipeline.json">
615630
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
616631
</None>
@@ -650,6 +665,9 @@
650665
</ItemGroup>
651666
<ItemGroup>
652667
<Content Include="about.txt" />
668+
<Content Include="Resources\MSMpiSetup.exe">
669+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
670+
</Content>
653671
</ItemGroup>
654672
<ItemGroup />
655673
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 System;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Batch.Protocol;
18+
using Microsoft.Azure.Batch.Protocol.Models;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System.Collections.Generic;
22+
using System.Management.Automation;
23+
using Xunit;
24+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
25+
using Microsoft.Azure.Batch.Common;
26+
27+
namespace Microsoft.Azure.Commands.Batch.Test.ComputeNodes
28+
{
29+
public class DisableBatchComputeNodeSchedulingCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
30+
{
31+
private DisableBatchComputeNodeSchedulingCommand cmdlet;
32+
private Mock<BatchClient> batchClientMock;
33+
private Mock<ICommandRuntime> commandRuntimeMock;
34+
35+
public DisableBatchComputeNodeSchedulingCommandTests()
36+
{
37+
batchClientMock = new Mock<BatchClient>();
38+
commandRuntimeMock = new Mock<ICommandRuntime>();
39+
cmdlet = new DisableBatchComputeNodeSchedulingCommand()
40+
{
41+
CommandRuntime = commandRuntimeMock.Object,
42+
BatchClient = batchClientMock.Object,
43+
};
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
public void DisableComputeNodeSchedulingParametersTest()
49+
{
50+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
51+
cmdlet.BatchContext = context;
52+
cmdlet.PoolId = null;
53+
cmdlet.Id = null;
54+
55+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
56+
57+
cmdlet.PoolId = "testPool";
58+
cmdlet.Id = "computeNode01";
59+
60+
// Don't go to the service on an Disable Compute Node Scheduling call
61+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeDisableSchedulingParameters, ComputeNodeDisableSchedulingResponse>();
62+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
63+
64+
// Verify no exceptions when required parameter is set
65+
cmdlet.ExecuteCmdlet();
66+
}
67+
68+
[Fact]
69+
[Trait(Category.AcceptanceType, Category.CheckIn)]
70+
public void DisableComputeNodeSchedulingRequestTest()
71+
{
72+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
73+
cmdlet.BatchContext = context;
74+
75+
DisableComputeNodeSchedulingOption? disableOption = DisableComputeNodeSchedulingOption.TaskCompletion;
76+
DisableComputeNodeSchedulingOption? requestDisableOption = null;
77+
78+
cmdlet.PoolId = "testPool";
79+
cmdlet.Id = "computeNode1";
80+
cmdlet.DisableSchedulingOption = disableOption;
81+
82+
// Don't go to the service on an Disable Compute Node Scheduling call
83+
Action<BatchRequest<ComputeNodeDisableSchedulingParameters, ComputeNodeDisableSchedulingResponse>> extractFormulaAction =
84+
(request) =>
85+
{
86+
requestDisableOption = request.TypedParameters.DisableComputeNodeSchedulingOption;
87+
};
88+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor(requestAction: extractFormulaAction);
89+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
90+
91+
cmdlet.ExecuteCmdlet();
92+
93+
// Verify that the parameters were properly set on the outgoing request
94+
Assert.Equal(disableOption, requestDisableOption);
95+
}
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 System;
16+
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Batch.Protocol;
18+
using Microsoft.Azure.Batch.Protocol.Models;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System.Collections.Generic;
22+
using System.Management.Automation;
23+
using Xunit;
24+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
25+
26+
namespace Microsoft.Azure.Commands.Batch.Test.ComputeNodes
27+
{
28+
public class EnableBatchComputeNodeSchedulingCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
29+
{
30+
private EnableBatchComputeNodeSchedulingCommand cmdlet;
31+
private Mock<BatchClient> batchClientMock;
32+
private Mock<ICommandRuntime> commandRuntimeMock;
33+
34+
public EnableBatchComputeNodeSchedulingCommandTests()
35+
{
36+
batchClientMock = new Mock<BatchClient>();
37+
commandRuntimeMock = new Mock<ICommandRuntime>();
38+
cmdlet = new EnableBatchComputeNodeSchedulingCommand()
39+
{
40+
CommandRuntime = commandRuntimeMock.Object,
41+
BatchClient = batchClientMock.Object,
42+
};
43+
}
44+
45+
[Fact]
46+
[Trait(Category.AcceptanceType, Category.CheckIn)]
47+
public void EnableComputeNodeSchedulingParametersTest()
48+
{
49+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
50+
cmdlet.BatchContext = context;
51+
cmdlet.PoolId = null;
52+
cmdlet.Id = null;
53+
54+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
55+
56+
cmdlet.PoolId = "testPool";
57+
cmdlet.Id = "computeNode01";
58+
59+
// Don't go to the service on an Enable Compute Node Scheduling call
60+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeEnableSchedulingParameters, ComputeNodeEnableSchedulingResponse>();
61+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
62+
63+
// Verify no exceptions when required parameter is set
64+
cmdlet.ExecuteCmdlet();
65+
}
66+
}
67+
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/Pools/EnableBatchAutoScaleCommandTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public void EnableAutoScaleParametersTest()
5454

5555
cmdlet.Id = "testPool";
5656

57-
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
58-
59-
cmdlet.AutoScaleFormula = "formula";
60-
6157
// Don't go to the service on an Enable AutoScale call
6258
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudPoolEnableAutoScaleParameters, CloudPoolEnableAutoScaleResponse>();
6359
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
@@ -74,24 +70,29 @@ public void EnableAutoScaleRequestTest()
7470
cmdlet.BatchContext = context;
7571

7672
string formula = "$TargetDedicated=2";
73+
TimeSpan? interval = TimeSpan.FromMinutes(6);
7774
string requestFormula = null;
75+
TimeSpan? requestInterval = null;
7876

7977
cmdlet.Id = "testPool";
8078
cmdlet.AutoScaleFormula = formula;
79+
cmdlet.AutoScaleEvaluationInterval = interval;
8180

8281
// Don't go to the service on an Enable AutoScale call
8382
Action<BatchRequest<CloudPoolEnableAutoScaleParameters, CloudPoolEnableAutoScaleResponse>> extractFormulaAction =
8483
(request) =>
8584
{
8685
requestFormula = request.TypedParameters.AutoScaleFormula;
86+
requestInterval = request.TypedParameters.AutoScaleEvaluationInterval;
8787
};
8888
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor(requestAction: extractFormulaAction);
8989
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
9090

9191
cmdlet.ExecuteCmdlet();
9292

93-
// Verify that the autoscale formula was properly set on the outgoing request
93+
// Verify that the autoscale parameters were properly set on the outgoing request
9494
Assert.Equal(formula, requestFormula);
95+
Assert.Equal(interval, requestInterval);
9596
}
9697
}
9798
}
Binary file not shown.

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ public void TestReimageComputeNodePipeline()
193193
TestReimageComputeNode(true, TestUtilities.GetCurrentMethodName());
194194
}
195195

196+
[Fact]
197+
[Trait(Category.AcceptanceType, Category.CheckIn)]
198+
public void TestDisableAndEnableComputeNodeSchedulingById()
199+
{
200+
TestDisableAndEnableComputeNodeScheduling(false, TestUtilities.GetCurrentMethodName());
201+
}
202+
203+
[Fact]
204+
[Trait(Category.AcceptanceType, Category.CheckIn)]
205+
public void TestDisableAndEnableComputeNodeSchedulingPipeline()
206+
{
207+
TestDisableAndEnableComputeNodeScheduling(true, TestUtilities.GetCurrentMethodName());
208+
}
209+
196210
private void TestRemoveComputeNode(bool usePipeline, string testMethodName)
197211
{
198212
BatchController controller = BatchController.NewInstance;
@@ -253,5 +267,23 @@ private void TestReimageComputeNode(bool usePipeline, string testMethodName)
253267
TestUtilities.GetCallingClass(),
254268
testMethodName);
255269
}
270+
271+
private void TestDisableAndEnableComputeNodeScheduling(bool usePipeline, string testMethodName)
272+
{
273+
BatchController controller = BatchController.NewInstance;
274+
BatchAccountContext context = null;
275+
string computeNodeId = null;
276+
controller.RunPsTestWorkflow(
277+
() => { return new string[] { string.Format("Test-DisableAndEnableComputeNodeScheduling '{0}' '{1}' '{2}' '{3}'", ScenarioTestHelpers.MpiOnlineAccount, poolId, computeNodeId, usePipeline ? 1 : 0) }; },
278+
() =>
279+
{
280+
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, ScenarioTestHelpers.MpiOnlineAccount);
281+
computeNodeId = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId);
282+
ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId);
283+
},
284+
null,
285+
TestUtilities.GetCallingClass(),
286+
testMethodName);
287+
}
256288
}
257289
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,38 @@ function Test-ReimageComputeNode
267267
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -BatchContext $context
268268

269269
Assert-AreEqual 'Reimaging' $computeNode.State
270+
}
271+
272+
<#
273+
.SYNOPSIS
274+
Tests disabling and enabling compute node scheduling
275+
#>
276+
function Test-DisableAndEnableComputeNodeScheduling
277+
{
278+
param([string]$accountName, [string]$poolId, [string]$computeNodeId, [string]$usePipeline)
279+
280+
$context = Get-ScenarioTestContext $accountName
281+
282+
$disableOption = ([Microsoft.Azure.Batch.Common.DisableComputeNodeSchedulingOption]::Terminate)
283+
if ($usePipeline -eq '1')
284+
{
285+
Get-AzureBatchComputeNode $poolId $computeNodeId -BatchContext $context | Disable-AzureBatchComputeNodeScheduling -DisableSchedulingOption $disableOption -BatchContext $context
286+
}
287+
else
288+
{
289+
Disable-AzureBatchComputeNodeScheduling $poolId $computeNodeId -DisableSchedulingOption $disableOption -BatchContext $context
290+
}
291+
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -Select "id,schedulingState" -BatchContext $context
292+
Assert-AreEqual 'Disabled' $computeNode.SchedulingState
293+
294+
if ($usePipeline -eq '1')
295+
{
296+
Get-AzureBatchComputeNode $poolId $computeNodeId -BatchContext $context | Enable-AzureBatchComputeNodeScheduling -BatchContext $context
297+
}
298+
else
299+
{
300+
Enable-AzureBatchComputeNodeScheduling $poolId $computeNodeId -BatchContext $context
301+
}
302+
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -Select "id,schedulingState" -BatchContext $context
303+
Assert-AreEqual 'Enabled' $computeNode.SchedulingState
270304
}

0 commit comments

Comments
 (0)