Skip to content

Commit bd82130

Browse files
committed
Merge pull request #778 from jasper-schneider/computeNodeOps
New Batch cmdlets for working with compute nodes
2 parents 523b0cf + d3bfd2b commit bd82130

28 files changed

+6262
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@
166166
<Compile Include="Accounts\RemoveBatchAccountCommandTests.cs" />
167167
<Compile Include="Accounts\SetBatchAccountCommandTests.cs" />
168168
<Compile Include="BatchTestHelpers.cs" />
169+
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
170+
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommandTests.cs" />
169171
<Compile Include="Files\GetBatchRemoteDesktopProtocolFileCommandTests.cs" />
170172
<Compile Include="Files\GetBatchNodeFileCommandTests.cs" />
171173
<Compile Include="Files\GetBatchNodeFileContentCommandTests.cs" />
@@ -178,6 +180,7 @@
178180
<Compile Include="Pools\GetBatchPoolCommandTests.cs" />
179181
<Compile Include="Pools\NewBatchPoolCommandTests.cs" />
180182
<Compile Include="Pools\RemoveBatchPoolCommandTests.cs" />
183+
<Compile Include="Pools\SetBatchPoolOSVersionCommandTests.cs" />
181184
<Compile Include="Pools\StartBatchPoolResizeCommandTests.cs" />
182185
<Compile Include="Pools\StopBatchPoolResizeCommandTests.cs" />
183186
<Compile Include="Pools\TestBatchAutoScaleCommandTests.cs" />
@@ -270,6 +273,18 @@
270273
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestListComputeNodesWithMaxCount.json">
271274
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
272275
</None>
276+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRebootComputeNodeById.json">
277+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
278+
</None>
279+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestRebootComputeNodePipeline.json">
280+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
281+
</None>
282+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestReimageComputeNodeById.json">
283+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
284+
</None>
285+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestReimageComputeNodePipeline.json">
286+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
287+
</None>
273288
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeUserTests\TestCreateComputeNodeUser.json">
274289
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
275290
</None>
@@ -378,6 +393,12 @@
378393
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.JobTests\TestNewJob.json">
379394
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
380395
</None>
396+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestChangeOSVersionById.json">
397+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
398+
</None>
399+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestChangeOSVersionPipeline.json">
400+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
401+
</None>
381402
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestDeletePool.json">
382403
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
383404
</None>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.Common;
18+
using Microsoft.Azure.Batch.Protocol;
19+
using Microsoft.Azure.Batch.Protocol.Models;
20+
using Microsoft.Azure.Commands.Batch.Models;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Moq;
23+
using System.Collections.Generic;
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+
30+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
31+
{
32+
public class ResetBatchComputeNodeCommandTests
33+
{
34+
private ResetBatchComputeNodeCommand cmdlet;
35+
private Mock<BatchClient> batchClientMock;
36+
private Mock<ICommandRuntime> commandRuntimeMock;
37+
38+
public ResetBatchComputeNodeCommandTests()
39+
{
40+
batchClientMock = new Mock<BatchClient>();
41+
commandRuntimeMock = new Mock<ICommandRuntime>();
42+
cmdlet = new ResetBatchComputeNodeCommand()
43+
{
44+
CommandRuntime = commandRuntimeMock.Object,
45+
BatchClient = batchClientMock.Object,
46+
};
47+
}
48+
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void ResetBatchComputeNodeParametersTest()
52+
{
53+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
54+
cmdlet.BatchContext = context;
55+
cmdlet.Id = null;
56+
57+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
58+
59+
cmdlet.PoolId = "testPool";
60+
61+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
62+
63+
cmdlet.Id = "computeNode1";
64+
65+
// Don't go to the service on a Reimage ComputeNode call
66+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
67+
{
68+
BatchRequest<ComputeNodeReimageParameters, ComputeNodeReimageResponse> request =
69+
(BatchRequest<ComputeNodeReimageParameters, ComputeNodeReimageResponse>)baseRequest;
70+
71+
request.ServiceRequestFunc = (cancellationToken) =>
72+
{
73+
ComputeNodeReimageResponse response = new ComputeNodeReimageResponse();
74+
Task<ComputeNodeReimageResponse> task = Task.FromResult(response);
75+
return task;
76+
};
77+
});
78+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
79+
80+
// Verify no exceptions when required parameter is set
81+
cmdlet.ExecuteCmdlet();
82+
}
83+
84+
[Fact]
85+
[Trait(Category.AcceptanceType, Category.CheckIn)]
86+
public void ResetComputeNodeRequestTest()
87+
{
88+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
89+
cmdlet.BatchContext = context;
90+
91+
cmdlet.PoolId = "testPool";
92+
cmdlet.Id = "computeNode1";
93+
cmdlet.ReimageOption = ComputeNodeReimageOption.Terminate;
94+
95+
ComputeNodeReimageOption? requestReimageOption = null;
96+
97+
// Don't go to the service on a Reimage ComputeNode call
98+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
99+
{
100+
BatchRequest<ComputeNodeReimageParameters, ComputeNodeReimageResponse> request =
101+
(BatchRequest<ComputeNodeReimageParameters, ComputeNodeReimageResponse>)baseRequest;
102+
103+
request.ServiceRequestFunc = (cancellationToken) =>
104+
{
105+
requestReimageOption = request.TypedParameters.ComputeNodeReimageOption;
106+
107+
ComputeNodeReimageResponse response = new ComputeNodeReimageResponse();
108+
Task<ComputeNodeReimageResponse> task = Task.FromResult(response);
109+
return task;
110+
};
111+
});
112+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
113+
114+
cmdlet.ExecuteCmdlet();
115+
116+
// Verify that the reimage option was properly set on the outgoing request
117+
Assert.Equal(cmdlet.ReimageOption, requestReimageOption);
118+
}
119+
}
120+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.Common;
18+
using Microsoft.Azure.Batch.Protocol;
19+
using Microsoft.Azure.Batch.Protocol.Models;
20+
using Microsoft.Azure.Commands.Batch.Models;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Moq;
23+
using System.Collections.Generic;
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+
30+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
31+
{
32+
public class RestartBatchComputeNodeCommandTests
33+
{
34+
private RestartBatchComputeNodeCommand cmdlet;
35+
private Mock<BatchClient> batchClientMock;
36+
private Mock<ICommandRuntime> commandRuntimeMock;
37+
38+
public RestartBatchComputeNodeCommandTests()
39+
{
40+
batchClientMock = new Mock<BatchClient>();
41+
commandRuntimeMock = new Mock<ICommandRuntime>();
42+
cmdlet = new RestartBatchComputeNodeCommand()
43+
{
44+
CommandRuntime = commandRuntimeMock.Object,
45+
BatchClient = batchClientMock.Object,
46+
};
47+
}
48+
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void RestartBatchComputeNodeParametersTest()
52+
{
53+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
54+
cmdlet.BatchContext = context;
55+
cmdlet.Id = null;
56+
57+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
58+
59+
cmdlet.PoolId = "testPool";
60+
61+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
62+
63+
cmdlet.Id = "computeNode1";
64+
65+
// Don't go to the service on a Reboot ComputeNode call
66+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
67+
{
68+
BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse> request =
69+
(BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse>)baseRequest;
70+
71+
request.ServiceRequestFunc = (cancellationToken) =>
72+
{
73+
ComputeNodeRebootResponse response = new ComputeNodeRebootResponse();
74+
Task<ComputeNodeRebootResponse> task = Task.FromResult(response);
75+
return task;
76+
};
77+
});
78+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
79+
80+
// Verify no exceptions when required parameter is set
81+
cmdlet.ExecuteCmdlet();
82+
}
83+
84+
[Fact]
85+
[Trait(Category.AcceptanceType, Category.CheckIn)]
86+
public void RestartComputeNodeRequestTest()
87+
{
88+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
89+
cmdlet.BatchContext = context;
90+
91+
cmdlet.PoolId = "testPool";
92+
cmdlet.Id = "computeNode1";
93+
cmdlet.RebootOption = ComputeNodeRebootOption.Terminate;
94+
95+
ComputeNodeRebootOption? requestRebootOption = null;
96+
97+
// Don't go to the service on a Reboot ComputeNode call
98+
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
99+
{
100+
BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse> request =
101+
(BatchRequest<ComputeNodeRebootParameters, ComputeNodeRebootResponse>)baseRequest;
102+
103+
request.ServiceRequestFunc = (cancellationToken) =>
104+
{
105+
requestRebootOption = request.TypedParameters.ComputeNodeRebootOption;
106+
107+
ComputeNodeRebootResponse response = new ComputeNodeRebootResponse();
108+
Task<ComputeNodeRebootResponse> task = Task.FromResult(response);
109+
return task;
110+
};
111+
});
112+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
113+
114+
cmdlet.ExecuteCmdlet();
115+
116+
// Verify that the reboot option was properly set on the outgoing request
117+
Assert.Equal(cmdlet.RebootOption, requestRebootOption);
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)