Skip to content

Added iaas cmdlets for Azure Batch module #2144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8f8d22b
Added Iaas api calls: remote login settings and list node agent skus
brnleehng Apr 1, 2016
820d5a9
Merge branch 'feature/swagger-iaas-2' into feature/swagger-iaas-cmdlets
brnleehng Apr 6, 2016
c3b666d
Removed shared account
brnleehng Apr 6, 2016
876c10f
Minor: Not using maxCount directly
brnleehng Apr 6, 2016
76bd733
Added list node agent/get remote login settings recordings
brnleehng Apr 6, 2016
09f58ab
Added skip for node agent sku test with filter
brnleehng Apr 8, 2016
c0c1185
Merge branch 'feature/swagger-iaas-2' into feature/swagger-iaas-cmdlets
brnleehng Apr 8, 2016
07e8455
Added help doc for remote login settings and node agent sku cmdlets
brnleehng Apr 8, 2016
1982e44
Moved get batch node agent sku comdlets to pool operations. Edited he…
brnleehng Apr 11, 2016
0aae20e
Edited scenario test for get remote login settings cmdlet and list no…
brnleehng Apr 12, 2016
8f06fa4
Added compute node login settings recordings tests
brnleehng Apr 12, 2016
8bb676f
Merge branch 'dev' into feature/swagger-iaas-cmdlets
brnleehng Apr 14, 2016
6dc3931
Updated to 4.0.1, changed skus to SKUs
brnleehng Apr 14, 2016
d25faa6
Modified response interceptor in TResponse param
brnleehng Apr 19, 2016
c2392bd
Fixed filterClause parameter naming
brnleehng Apr 25, 2016
63541b8
Merge branch 'dev' into feature/swagger-iaas-cmdlets
brnleehng Apr 25, 2016
d235cd6
Merge branch 'dev' into feature/swagger-iaas-cmdlets
brnleehng Apr 27, 2016
56f3edb
Added updated recordings for new iaas cmdlets
brnleehng Apr 27, 2016
ba5a664
Added copy to output always for recording tests
brnleehng Apr 27, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Rest.Azure;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Batch.Models;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;

namespace Microsoft.Azure.Commands.Batch.Test.Accounts
{
public class GetBatchNodeAgentSkusCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
{
private GetBatchAccountNodeAgentSkuCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

public GetBatchNodeAgentSkusCommandTests()
{
batchClientMock = new Mock<BatchClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new GetBatchAccountNodeAgentSkuCommand()
{
CommandRuntime = commandRuntimeMock.Object,
BatchClient = batchClientMock.Object,
};
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchNodeAgentSkusParametersTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

string[] idsOfNodeAgentSkus = new[] { "batch.node.centos 7", "batch.node.debian 8", "batch.node.opensuse 13.2" };

// Don't go to the service on an Get NodeAgentSkus call
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> response =
BatchTestHelpers.CreateNodeAgentSkuResponse(idsOfNodeAgentSkus);

RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
ProxyModels.AccountListNodeAgentSkusOptions,
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>>(responseToUse: response);

cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Setup the cmdlet to write pipeline output to a list that can be examined later
List<PSNodeAgentSku> pipeline = new List<PSNodeAgentSku>();
commandRuntimeMock.Setup(r =>
r.WriteObject(It.IsAny<PSNodeAgentSku>()))
.Callback<object>(p => pipeline.Add((PSNodeAgentSku)p));

// Verify no exceptions when required parameter is set
cmdlet.ExecuteCmdlet();

Assert.Equal(3, pipeline.Count);
int nodeAgentCount = 0;
foreach (PSNodeAgentSku p in pipeline)
{
Assert.True(idsOfNodeAgentSkus.Contains(p.Id));
nodeAgentCount++;
}
Assert.Equal(idsOfNodeAgentSkus.Length, nodeAgentCount);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchNodeAgentSkusWithFilterTest()
{
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;
cmdlet.Filter = "osType eq 'linux'";

string requestFilter = null;

// Don't go to the service on an Get NodeAgentSkus call
AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> getResponse = BatchTestHelpers.CreateGenericAzureOperationListResponse<ProxyModels.NodeAgentSku, ProxyModels.AccountListNodeAgentSkusHeaders>();
RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ProxyModels.AccountListNodeAgentSkusOptions, AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>>(responseToUse: getResponse);
ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
{
ProxyModels.AccountListNodeAgentSkusOptions listNodeAgentSkusOptions = (ProxyModels.AccountListNodeAgentSkusOptions) request.Options;
requestFilter = listNodeAgentSkusOptions.Filter;

return Task.FromResult(response);
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { requestInterceptor, responseInterceptor };

// Verify no exceptions when required parameter is set
cmdlet.ExecuteCmdlet();

Assert.Equal(cmdlet.Filter, requestFilter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
Expand Down Expand Up @@ -157,7 +158,7 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
public static RequestInterceptor CreateFakeServiceResponseInterceptor<TBody, TOptions, TResponse>(TResponse responseToUse = default(TResponse),
Action<BatchRequest<TBody, TOptions, TResponse>> requestAction = null)
where TOptions : ProxyModels.IOptions, new()
where TResponse : IAzureOperationResponse, new()
where TResponse : class, IAzureOperationResponse, new()
{
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
{
Expand All @@ -170,15 +171,12 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex

request.ServiceRequestFunc = (cancellationToken) =>
{
if (responseToUse == null)
TResponse response = responseToUse ?? new TResponse()
{
responseToUse = new TResponse()
{
Response = new HttpResponseMessage()
};
}
Response = new HttpResponseMessage()
};

Task<TResponse> task = Task.FromResult(responseToUse);
Task<TResponse> task = Task.FromResult(response);
return task;
};
});
Expand All @@ -192,7 +190,7 @@ public static void AssertBatchAccountContextsAreEqual(BatchAccountContext contex
/// <typeparam name="THeader">The type of header for the response</typeparam>
/// <returns></returns>
public static AzureOperationResponse<TBody, THeader> CreateGenericAzureOperationResponse<TBody, THeader>()
where TBody : class, new ()
where TBody : class, new ()
where THeader : class, new ()
{
var response = new AzureOperationResponse<TBody, THeader>()
Expand Down Expand Up @@ -221,7 +219,7 @@ public static AzureOperationResponse<IPage<TBody>, THeader> CreateGenericAzureOp
};

return response;
}
}

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

response.Body = cert;

return response;
}

Expand All @@ -330,7 +328,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
{
var response = new AzureOperationResponse<IPage<ProxyModels.Certificate>, ProxyModels.CertificateListHeaders>();
response.Response = new HttpResponseMessage(HttpStatusCode.OK);

List<ProxyModels.Certificate> certs = new List<ProxyModels.Certificate>();

foreach (string t in certThumbprints)
Expand Down Expand Up @@ -383,6 +381,23 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
return response;
}

/// <summary>
/// Builds a GetRemoteLoginSettingsResponse object
/// </summary>
public static AzureOperationResponse<ProxyModels.ComputeNodeGetRemoteLoginSettingsResult, ProxyModels.ComputeNodeGetRemoteLoginSettingsHeaders> CreateRemoteLoginSettingsGetResponse(string ipAddress)
{
var settings = new ProxyModels.ComputeNodeGetRemoteLoginSettingsResult();
settings.RemoteLoginIPAddress = ipAddress;

var response = new AzureOperationResponse<ProxyModels.ComputeNodeGetRemoteLoginSettingsResult, ProxyModels.ComputeNodeGetRemoteLoginSettingsHeaders>()
{
Response = new HttpResponseMessage(HttpStatusCode.OK),
Body = settings
};

return response;
}

/// <summary>
/// Builds a ComputeNodeGetResponse object
/// </summary>
Expand Down Expand Up @@ -492,7 +507,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
job.Id = id;
jobs.Add(job);
}

response.Body = new MockPagedEnumerable<ProxyModels.CloudJob>(jobs);

return response;
Expand All @@ -519,7 +534,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
/// </summary>
public static AzureOperationResponse<IPage<ProxyModels.CloudTask>, ProxyModels.TaskListHeaders> CreateCloudTaskListResponse(IEnumerable<string> taskIds)
{
var response = new AzureOperationResponse<IPage<ProxyModels.CloudTask>, ProxyModels.TaskListHeaders>();
var response = new AzureOperationResponse<IPage<ProxyModels.CloudTask>, ProxyModels.TaskListHeaders>();
response.Response = new HttpResponseMessage(HttpStatusCode.OK);

List<ProxyModels.CloudTask> tasks = new List<ProxyModels.CloudTask>();
Expand Down Expand Up @@ -563,6 +578,23 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
return response;
}

/// <summary>
/// Builds a NodeAgentSKUResponse object
/// </summary>
public static AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders> CreateNodeAgentSkuResponse(IEnumerable<string> skuIds)
{
IEnumerable<ProxyModels.NodeAgentSku> nodeAgents =
skuIds.Select(id => new ProxyModels.NodeAgentSku() { Id = id });

var response = new AzureOperationResponse<IPage<ProxyModels.NodeAgentSku>, ProxyModels.AccountListNodeAgentSkusHeaders>()
{
Response = new HttpResponseMessage(HttpStatusCode.OK),
Body = new MockPagedEnumerable<ProxyModels.NodeAgentSku>(nodeAgents)
};

return response;
}

/// <summary>
/// Builds a NodeFileGetPropertiesResponse object
/// </summary>
Expand Down Expand Up @@ -638,7 +670,7 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
response.Response = new HttpResponseMessage(HttpStatusCode.OK);

List<ProxyModels.NodeFile> files = new List<ProxyModels.NodeFile>();

foreach (string name in fileNames)
{
ProxyModels.NodeFile file = new ProxyModels.NodeFile();
Expand Down Expand Up @@ -689,7 +721,7 @@ public static CloudJobSchedule CreateFakeBoundJobSchedule(BatchAccountContext co
request.ServiceRequestFunc = (cancellationToken) =>
{
var response = new AzureOperationResponse<ProxyModels.CloudJobSchedule, ProxyModels.JobScheduleGetHeaders>();

response.Body = new ProxyModels.CloudJobSchedule(id: jobScheduleId, schedule: new ProxyModels.Schedule(), jobSpecification: new ProxyModels.JobSpecification());

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

/// <summary>
/// Uses Reflection to set a property value on an object.
/// Uses Reflection to set a property value on an object.
/// </summary>
internal static void SetField(object obj, string fieldName, object fieldValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<Reference Include="Hyak.Common">
<HintPath>..\..\..\packages\Hyak.Common.1.0.3\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Batch, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Azure.Batch.4.0.0\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
<Reference Include="Microsoft.Azure.Batch, Version=4.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Azure.Batch.4.0.1\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Common">
Expand Down Expand Up @@ -181,6 +181,7 @@
<ItemGroup>
<Compile Include="Accounts\GetBatchAccountCommandTests.cs" />
<Compile Include="Accounts\GetBatchAccountKeysCommandTests.cs" />
<Compile Include="Accounts\GetBatchNodeAgentSkusCommandTests.cs" />
<Compile Include="Accounts\NewBatchAccountCommandTests.cs" />
<Compile Include="Accounts\RegenBatchAccountKeyCommandTests.cs" />
<Compile Include="Accounts\RemoveBatchAccountCommandTests.cs" />
Expand All @@ -192,6 +193,7 @@
<Compile Include="Certificates\StopBatchCertificateDeletionCommandTests.cs" />
<Compile Include="ComputeNodes\DisableBatchComputeNodeSchedulingCommandTests.cs" />
<Compile Include="ComputeNodes\EnableBatchComputeNodeSchedulingCommandTests.cs" />
<Compile Include="ComputeNodes\GetBatchComputeNodeLoginSettingsCommandTests.cs" />
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommandTests.cs" />
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommandTests.cs" />
Expand Down Expand Up @@ -361,6 +363,12 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetComputeNodeById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetComputeNodeRemoteLoginSettingsById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetComputeNodeRemoteLoginSettingsPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestListAllComputeNodes.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -586,6 +594,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestListAllPools.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests\TestListNodeAgentSkus.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.PoolTests\TestListPoolsByFilter.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Loading