Skip to content

Commit bd92c41

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into release
2 parents 250e454 + 7edd186 commit bd92c41

File tree

64 files changed

+10619
-578
lines changed

Some content is hidden

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

64 files changed

+10619
-578
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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.Rest.Azure;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Moq;
20+
using System.Collections.Generic;
21+
using System.Linq;
22+
using System.Management.Automation;
23+
using System.Threading.Tasks;
24+
using Microsoft.Azure.Commands.Batch.Models;
25+
using Xunit;
26+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
27+
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;
28+
29+
namespace Microsoft.Azure.Commands.Batch.Test.Accounts
30+
{
31+
public class GetBatchNodeAgentSkusCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
32+
{
33+
private GetBatchAccountNodeAgentSkuCommand cmdlet;
34+
private Mock<BatchClient> batchClientMock;
35+
private Mock<ICommandRuntime> commandRuntimeMock;
36+
37+
public GetBatchNodeAgentSkusCommandTests()
38+
{
39+
batchClientMock = new Mock<BatchClient>();
40+
commandRuntimeMock = new Mock<ICommandRuntime>();
41+
cmdlet = new GetBatchAccountNodeAgentSkuCommand()
42+
{
43+
CommandRuntime = commandRuntimeMock.Object,
44+
BatchClient = batchClientMock.Object,
45+
};
46+
}
47+
48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void ListBatchNodeAgentSkusParametersTest()
51+
{
52+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
53+
cmdlet.BatchContext = context;
54+
55+
string[] idsOfNodeAgentSkus = new[] { "batch.node.centos 7", "batch.node.debian 8", "batch.node.opensuse 13.2" };
56+
57+
// Don't go to the service on an Get NodeAgentSkus call
58+
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> response =
59+
BatchTestHelpers.CreateNodeAgentSkuResponse(idsOfNodeAgentSkus);
60+
61+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
62+
ProxyModels.AccountListNodeAgentSkusOptions,
63+
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>>(responseToUse: response);
64+
65+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
66+
67+
// Setup the cmdlet to write pipeline output to a list that can be examined later
68+
List<PSNodeAgentSku> pipeline = new List<PSNodeAgentSku>();
69+
commandRuntimeMock.Setup(r =>
70+
r.WriteObject(It.IsAny<PSNodeAgentSku>()))
71+
.Callback<object>(p => pipeline.Add((PSNodeAgentSku)p));
72+
73+
// Verify no exceptions when required parameter is set
74+
cmdlet.ExecuteCmdlet();
75+
76+
Assert.Equal(3, pipeline.Count);
77+
int nodeAgentCount = 0;
78+
foreach (PSNodeAgentSku p in pipeline)
79+
{
80+
Assert.True(idsOfNodeAgentSkus.Contains(p.Id));
81+
nodeAgentCount++;
82+
}
83+
Assert.Equal(idsOfNodeAgentSkus.Length, nodeAgentCount);
84+
}
85+
86+
[Fact]
87+
[Trait(Category.AcceptanceType, Category.CheckIn)]
88+
public void ListBatchNodeAgentSkusWithFilterTest()
89+
{
90+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
91+
cmdlet.BatchContext = context;
92+
cmdlet.Filter = "osType eq 'linux'";
93+
94+
string requestFilter = null;
95+
96+
// Don't go to the service on an Get NodeAgentSkus call
97+
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> getResponse = BatchTestHelpers.CreateGenericAzureOperationListResponse<ProxyModels.NodeAgentSku, ProxyModels.AccountListNodeAgentSkusHeaders>();
98+
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.AccountListNodeAgentSkusOptions, AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>>(responseToUse: getResponse);
99+
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
100+
{
101+
ProxyModels.AccountListNodeAgentSkusOptions listNodeAgentSkusOptions = (ProxyModels.AccountListNodeAgentSkusOptions) request.Options;
102+
requestFilter = listNodeAgentSkusOptions.Filter;
103+
104+
return Task.FromResult(response);
105+
});
106+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };
107+
108+
// Verify no exceptions when required parameter is set
109+
cmdlet.ExecuteCmdlet();
110+
111+
Assert.Equal(cmdlet.Filter, requestFilter);
112+
}
113+
}
114+
}

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

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Collections;
2222
using System.Collections.Generic;
2323
using System.IO;
24+
using System.Linq;
2425
using System.Net;
2526
using System.Net.Http;
2627
using System.Reflection;
@@ -157,7 +158,7 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
157158
public static RequestInterceptor CreateFakeServiceResponseInterceptor<TBody, TOptions, TResponse>(TResponse responseToUse = default(TResponse),
158159
Action<BatchRequest<TBody, TOptions, TResponse>> requestAction = null)
159160
where TOptions : ProxyModels.IOptions, new()
160-
where TResponse : IAzureOperationResponse, new()
161+
where TResponse : class, IAzureOperationResponse, new()
161162
{
162163
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
163164
{
@@ -170,15 +171,12 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
170171

171172
request.ServiceRequestFunc = (cancellationToken) =>
172173
{
173-
if (responseToUse == null)
174+
TResponse response = responseToUse ?? new TResponse()
174175
{
175-
responseToUse = new TResponse()
176-
{
177-
Response = new HttpResponseMessage()
178-
};
179-
}
176+
Response = new HttpResponseMessage()
177+
};
180178

181-
Task<TResponse> task = Task.FromResult(responseToUse);
179+
Task<TResponse> task = Task.FromResult(response);
182180
return task;
183181
};
184182
});
@@ -192,7 +190,7 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
192190
/// <typeparam name="THeader">The type of header for the response</typeparam>
193191
/// <returns></returns>
194192
public static AzureOperationResponse<TBody, THeader> CreateGenericAzureOperationResponse<TBody, THeader>()
195-
where TBody : class, new ()
193+
where TBody : class, new ()
196194
where THeader : class, new ()
197195
{
198196
var response = new AzureOperationResponse<TBody, THeader>()
@@ -221,7 +219,7 @@ public static AzureOperationResponse<IPage<TBody>, THeader> CreateGenericAzureOp
221219
};
222220

223221
return response;
224-
}
222+
}
225223

226224
/// <summary>
227225
/// Creates a RequestInterceptor that does not contact the Batch Service on a Get NodeFile or a Get NodeFile Properties call.
@@ -319,7 +317,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
319317
cert.Thumbprint = thumbprint;
320318

321319
response.Body = cert;
322-
320+
323321
return response;
324322
}
325323

@@ -330,7 +328,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
330328
{
331329
var response = new AzureOperationResponse<IPage<ProxyModels.Certificate>, ProxyModels.CertificateListHeaders>();
332330
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
333-
331+
334332
List<ProxyModels.Certificate> certs = new List<ProxyModels.Certificate>();
335333

336334
foreach (string t in certThumbprints)
@@ -383,6 +381,23 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
383381
return response;
384382
}
385383

384+
/// <summary>
385+
/// Builds a GetRemoteLoginSettingsResponse object
386+
/// </summary>
387+
public static AzureOperationResponse<ProxyModels.ComputeNodeGetRemoteLoginSettingsResult, ProxyModels.ComputeNodeGetRemoteLoginSettingsHeaders> CreateRemoteLoginSettingsGetResponse(string ipAddress)
388+
{
389+
var settings = new ProxyModels.ComputeNodeGetRemoteLoginSettingsResult();
390+
settings.RemoteLoginIPAddress = ipAddress;
391+
392+
var response = new AzureOperationResponse<ProxyModels.ComputeNodeGetRemoteLoginSettingsResult, ProxyModels.ComputeNodeGetRemoteLoginSettingsHeaders>()
393+
{
394+
Response = new HttpResponseMessage(HttpStatusCode.OK),
395+
Body = settings
396+
};
397+
398+
return response;
399+
}
400+
386401
/// <summary>
387402
/// Builds a ComputeNodeGetResponse object
388403
/// </summary>
@@ -492,7 +507,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
492507
job.Id = id;
493508
jobs.Add(job);
494509
}
495-
510+
496511
response.Body = new MockPagedEnumerable<ProxyModels.CloudJob>(jobs);
497512

498513
return response;
@@ -519,7 +534,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
519534
/// </summary>
520535
public static AzureOperationResponse<IPage<ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> CreateCloudTaskListResponse(IEnumerable<string> taskIds)
521536
{
522-
var response = new AzureOperationResponse<IPage<ProxyModels.CloudTask>, ProxyModels.TaskListHeaders>();
537+
var response = new AzureOperationResponse<IPage<ProxyModels.CloudTask>, ProxyModels.TaskListHeaders>();
523538
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
524539

525540
List<ProxyModels.CloudTask> tasks = new List<ProxyModels.CloudTask>();
@@ -563,6 +578,23 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
563578
return response;
564579
}
565580

581+
/// <summary>
582+
/// Builds a NodeAgentSKUResponse object
583+
/// </summary>
584+
public static AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> CreateNodeAgentSkuResponse(IEnumerable<string> skuIds)
585+
{
586+
IEnumerable<ProxyModels.NodeAgentSku> nodeAgents =
587+
skuIds.Select(id => new ProxyModels.NodeAgentSku() { Id = id });
588+
589+
var response = new AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>()
590+
{
591+
Response = new HttpResponseMessage(HttpStatusCode.OK),
592+
Body = new MockPagedEnumerable<ProxyModels.NodeAgentSku>(nodeAgents)
593+
};
594+
595+
return response;
596+
}
597+
566598
/// <summary>
567599
/// Builds a NodeFileGetPropertiesResponse object
568600
/// </summary>
@@ -638,7 +670,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
638670
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
639671

640672
List<ProxyModels.NodeFile> files = new List<ProxyModels.NodeFile>();
641-
673+
642674
foreach (string name in fileNames)
643675
{
644676
ProxyModels.NodeFile file = new ProxyModels.NodeFile();
@@ -689,7 +721,7 @@ public static CloudJobSchedule CreateFakeBoundJobSchedule(BatchAccountContext co
689721
request.ServiceRequestFunc = (cancellationToken) =>
690722
{
691723
var response = new AzureOperationResponse<ProxyModels.CloudJobSchedule, ProxyModels.JobScheduleGetHeaders>();
692-
724+
693725
response.Body = new ProxyModels.CloudJobSchedule(id: jobScheduleId, schedule: new ProxyModels.Schedule(), jobSpecification: new ProxyModels.JobSpecification());
694726

695727
Task<AzureOperationResponse<ProxyModels.CloudJobSchedule, ProxyModels.JobScheduleGetHeaders>> task = Task.FromResult(response);
@@ -759,7 +791,7 @@ internal static void SetProperty(object obj, string propertyName, object propert
759791
}
760792

761793
/// <summary>
762-
/// Uses Reflection to set a property value on an object.
794+
/// Uses Reflection to set a property value on an object.
763795
/// </summary>
764796
internal static void SetField(object obj, string fieldName, object fieldValue)
765797
{

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
<Reference Include="Hyak.Common">
4545
<HintPath>..\..\..\packages\Hyak.Common.1.0.3\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
4646
</Reference>
47-
<Reference Include="Microsoft.Azure.Batch, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48-
<HintPath>..\..\..\packages\Azure.Batch.4.0.0\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
47+
<Reference Include="Microsoft.Azure.Batch, Version=4.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48+
<HintPath>..\..\..\packages\Azure.Batch.4.0.1\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
4949
<Private>True</Private>
5050
</Reference>
5151
<Reference Include="Microsoft.Azure.Common">
@@ -181,6 +181,7 @@
181181
<ItemGroup>
182182
<Compile Include="Accounts\GetBatchAccountCommandTests.cs" />
183183
<Compile Include="Accounts\GetBatchAccountKeysCommandTests.cs" />
184+
<Compile Include="Accounts\GetBatchNodeAgentSkusCommandTests.cs" />
184185
<Compile Include="Accounts\NewBatchAccountCommandTests.cs" />
185186
<Compile Include="Accounts\RegenBatchAccountKeyCommandTests.cs" />
186187
<Compile Include="Accounts\RemoveBatchAccountCommandTests.cs" />
@@ -192,6 +193,7 @@
192193
<Compile Include="Certificates\StopBatchCertificateDeletionCommandTests.cs" />
193194
<Compile Include="ComputeNodes\DisableBatchComputeNodeSchedulingCommandTests.cs" />
194195
<Compile Include="ComputeNodes\EnableBatchComputeNodeSchedulingCommandTests.cs" />
196+
<Compile Include="ComputeNodes\GetBatchComputeNodeLoginSettingsCommandTests.cs" />
195197
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommandTests.cs" />
196198
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
197199
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommandTests.cs" />
@@ -361,6 +363,12 @@
361363
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetComputeNodeById.json">
362364
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
363365
</None>
366+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetComputeNodeRemoteLoginSettingsById.json">
367+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
368+
</None>
369+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetComputeNodeRemoteLoginSettingsPipeline.json">
370+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
371+
</None>
364372
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestListAllComputeNodes.json">
365373
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
366374
</None>
@@ -586,6 +594,9 @@
586594
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestListAllPools.json">
587595
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
588596
</None>
597+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests\TestListNodeAgentSkus.json">
598+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
599+
</None>
589600
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestListPoolsByFilter.json">
590601
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
591602
</None>

0 commit comments

Comments
 (0)