Skip to content

Dev #293

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 16 commits into from
Jan 4, 2016
Merged

Dev #293

Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -401,6 +401,28 @@ public static ProxyModels.CloudTaskListResponse CreateCloudTaskListResponse(IEnu
return response;
}

/// <summary>
/// Builds a CloudTaskListSubtasksResponse object
/// </summary>
public static ProxyModels.CloudTaskListSubtasksResponse CreateCloudTaskListSubtasksResponse(IEnumerable<int> subtaskIds)
{
ProxyModels.CloudTaskListSubtasksResponse response = new ProxyModels.CloudTaskListSubtasksResponse();
response.StatusCode = HttpStatusCode.OK;

List<ProxyModels.SubtaskInformation> subtasks = new List<ProxyModels.SubtaskInformation>();

foreach (int id in subtaskIds)
{
ProxyModels.SubtaskInformation subtask = new ProxyModels.SubtaskInformation();
subtask.Id = id;
subtasks.Add(subtask);
}

response.SubtasksInformation = subtasks;

return response;
}

/// <summary>
/// Builds a NodeFileGetPropertiesResponse object
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<Reference Include="Hyak.Common">
<HintPath>..\..\..\packages\Hyak.Common.1.0.2\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Batch, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Azure.Batch.2.0.2\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
<Reference Include="Microsoft.Azure.Batch, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Azure.Batch.3.0.0\lib\net45\Microsoft.Azure.Batch.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Common">
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
Expand Down Expand Up @@ -180,6 +180,8 @@
<Compile Include="Certificates\NewBatchCertificateCommandTests.cs" />
<Compile Include="Certificates\RemoveBatchCertificateCommandTests.cs" />
<Compile Include="Certificates\StopBatchCertificateDeletionCommandTests.cs" />
<Compile Include="ComputeNodes\DisableBatchComputeNodeSchedulingCommandTests.cs" />
<Compile Include="ComputeNodes\EnableBatchComputeNodeSchedulingCommandTests.cs" />
<Compile Include="ComputeNodes\RemoveBatchComputeNodeCommandTests.cs" />
<Compile Include="ComputeNodes\ResetBatchComputeNodeCommandTests.cs" />
<Compile Include="ComputeNodes\RestartBatchComputeNodeCommandTests.cs" />
Expand Down Expand Up @@ -225,6 +227,7 @@
<Compile Include="ScenarioTests\ComputeNodeTests.cs" />
<Compile Include="ScenarioTests\JobScheduleTests.cs" />
<Compile Include="Subscriptions\GetBatchSubscriptionQuotasCommandTests.cs" />
<Compile Include="Tasks\GetBatchSubtaskCommandTests.cs" />
<Compile Include="Tasks\GetBatchTaskCommandTests.cs" />
<Compile Include="Tasks\NewBatchTaskCommandTests.cs" />
<Compile Include="Tasks\RemoveBatchTaskCommandTests.cs" />
Expand Down Expand Up @@ -335,6 +338,12 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.CertificateTests\TestListCertificatesWithMaxCount.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestDisableAndEnableComputeNodeSchedulingById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestDisableAndEnableComputeNodeSchedulingPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ComputeNodeTests\TestGetAndListComputeNodesWithSelect.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -608,9 +617,15 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestGetTaskById.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListAllSubtasks.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListAllTasks.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListSubtasksWithMaxCount.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListTaskPipeline.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -650,6 +665,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="about.txt" />
<Content Include="Resources\MSMpiSetup.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// ----------------------------------------------------------------------------------
//
// 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 System;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Batch.Protocol.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
using Microsoft.Azure.Batch.Common;

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

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

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

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

cmdlet.PoolId = "testPool";
cmdlet.Id = "computeNode01";

// Don't go to the service on an Disable Compute Node Scheduling call
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeDisableSchedulingParameters, ComputeNodeDisableSchedulingResponse>();
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

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

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

DisableComputeNodeSchedulingOption? disableOption = DisableComputeNodeSchedulingOption.TaskCompletion;
DisableComputeNodeSchedulingOption? requestDisableOption = null;

cmdlet.PoolId = "testPool";
cmdlet.Id = "computeNode1";
cmdlet.DisableSchedulingOption = disableOption;

// Don't go to the service on an Disable Compute Node Scheduling call
Action<BatchRequest<ComputeNodeDisableSchedulingParameters, ComputeNodeDisableSchedulingResponse>> extractFormulaAction =
(request) =>
{
requestDisableOption = request.TypedParameters.DisableComputeNodeSchedulingOption;
};
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor(requestAction: extractFormulaAction);
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

cmdlet.ExecuteCmdlet();

// Verify that the parameters were properly set on the outgoing request
Assert.Equal(disableOption, requestDisableOption);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ----------------------------------------------------------------------------------
//
// 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 System;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Batch.Protocol.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Management.Automation;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

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

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

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

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

cmdlet.PoolId = "testPool";
cmdlet.Id = "computeNode01";

// Don't go to the service on an Enable Compute Node Scheduling call
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<ComputeNodeEnableSchedulingParameters, ComputeNodeEnableSchedulingResponse>();
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Verify no exceptions when required parameter is set
cmdlet.ExecuteCmdlet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public void EnableAutoScaleParametersTest()

cmdlet.Id = "testPool";

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

cmdlet.AutoScaleFormula = "formula";

// Don't go to the service on an Enable AutoScale call
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<CloudPoolEnableAutoScaleParameters, CloudPoolEnableAutoScaleResponse>();
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
Expand All @@ -74,24 +70,29 @@ public void EnableAutoScaleRequestTest()
cmdlet.BatchContext = context;

string formula = "$TargetDedicated=2";
TimeSpan? interval = TimeSpan.FromMinutes(6);
string requestFormula = null;
TimeSpan? requestInterval = null;

cmdlet.Id = "testPool";
cmdlet.AutoScaleFormula = formula;
cmdlet.AutoScaleEvaluationInterval = interval;

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

cmdlet.ExecuteCmdlet();

// Verify that the autoscale formula was properly set on the outgoing request
// Verify that the autoscale parameters were properly set on the outgoing request
Assert.Equal(formula, requestFormula);
Assert.Equal(interval, requestInterval);
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ public void TestReimageComputeNodePipeline()
TestReimageComputeNode(true, TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDisableAndEnableComputeNodeSchedulingById()
{
TestDisableAndEnableComputeNodeScheduling(false, TestUtilities.GetCurrentMethodName());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestDisableAndEnableComputeNodeSchedulingPipeline()
{
TestDisableAndEnableComputeNodeScheduling(true, TestUtilities.GetCurrentMethodName());
}

private void TestRemoveComputeNode(bool usePipeline, string testMethodName)
{
BatchController controller = BatchController.NewInstance;
Expand Down Expand Up @@ -253,5 +267,23 @@ private void TestReimageComputeNode(bool usePipeline, string testMethodName)
TestUtilities.GetCallingClass(),
testMethodName);
}

private void TestDisableAndEnableComputeNodeScheduling(bool usePipeline, string testMethodName)
{
BatchController controller = BatchController.NewInstance;
BatchAccountContext context = null;
string computeNodeId = null;
controller.RunPsTestWorkflow(
() => { return new string[] { string.Format("Test-DisableAndEnableComputeNodeScheduling '{0}' '{1}' '{2}' '{3}'", ScenarioTestHelpers.MpiOnlineAccount, poolId, computeNodeId, usePipeline ? 1 : 0) }; },
() =>
{
context = ScenarioTestHelpers.GetBatchAccountContextWithKeys(controller, ScenarioTestHelpers.MpiOnlineAccount);
computeNodeId = ScenarioTestHelpers.GetComputeNodeId(controller, context, poolId);
ScenarioTestHelpers.WaitForIdleComputeNode(controller, context, poolId, computeNodeId);
},
null,
TestUtilities.GetCallingClass(),
testMethodName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,38 @@ function Test-ReimageComputeNode
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -BatchContext $context

Assert-AreEqual 'Reimaging' $computeNode.State
}

<#
.SYNOPSIS
Tests disabling and enabling compute node scheduling
#>
function Test-DisableAndEnableComputeNodeScheduling
{
param([string]$accountName, [string]$poolId, [string]$computeNodeId, [string]$usePipeline)

$context = Get-ScenarioTestContext $accountName

$disableOption = ([Microsoft.Azure.Batch.Common.DisableComputeNodeSchedulingOption]::Terminate)
if ($usePipeline -eq '1')
{
Get-AzureBatchComputeNode $poolId $computeNodeId -BatchContext $context | Disable-AzureBatchComputeNodeScheduling -DisableSchedulingOption $disableOption -BatchContext $context
}
else
{
Disable-AzureBatchComputeNodeScheduling $poolId $computeNodeId -DisableSchedulingOption $disableOption -BatchContext $context
}
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -Select "id,schedulingState" -BatchContext $context
Assert-AreEqual 'Disabled' $computeNode.SchedulingState

if ($usePipeline -eq '1')
{
Get-AzureBatchComputeNode $poolId $computeNodeId -BatchContext $context | Enable-AzureBatchComputeNodeScheduling -BatchContext $context
}
else
{
Enable-AzureBatchComputeNodeScheduling $poolId $computeNodeId -BatchContext $context
}
$computeNode = Get-AzureBatchComputeNode -PoolId $poolId -Filter "id eq '$computeNodeId'" -Select "id,schedulingState" -BatchContext $context
Assert-AreEqual 'Enabled' $computeNode.SchedulingState
}
Loading