Skip to content

Update Batch cmdlets to use general availability API #663

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 5 commits into from
Jul 31, 2015
Merged
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
11 changes: 11 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2015.08.07 version 0.9.6
* Azure Batch cmdlets
* Cmdlets updated to use the general availability API. See http://blogs.technet.com/b/windowshpc/archive/2015/07/10/what-39-s-new-in-azure-batch-july-release-general-availability.aspx
* Breaking changes to cmdlets resulting from API update:
* Workitems have been removed.
* If you were adding all tasks to a single job, use the New-AzureBatchJob cmdlet to directly create your job.
* If you were managing workitems with a recurring schedule defined, use the AzureBatchJobSchedule cmdlets instead.
* If you were using the AzureBatchVM cmdlets, use the AzureBatchComputeNode cmdlets instead.
* The AzureBatchTaskFile and AzureBatchVMFile cmdlets have been consolidated into the AzureBatchNodeFile cmdlets.
* The Name property on most entities has been replaced by an Id property.

2015.07.17 version 0.9.5
* Azure SQL cmdlets
* Allowing to use of Storage V2 accounts in Auditing policies
Expand Down
261 changes: 99 additions & 162 deletions src/ResourceManager/Batch/Commands.Batch.Test/BatchTestHelpers.cs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// ----------------------------------------------------------------------------------
//
// 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.Azure.Commands.Batch.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
using System.Management.Automation;
using System.Threading.Tasks;
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.ComputeNodeUsers
{
public class NewBatchComputeNodeUserCommandTests
{
private NewBatchComputeNodeUserCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

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

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewBatchComputeNodeUserParametersTest()
{
// Setup cmdlet without the required parameters
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
cmdlet.BatchContext = context;

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

cmdlet.PoolId = "testPool";
cmdlet.ComputeNodeId = "computeNode1";

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

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

// Don't go to the service on an Add ComputeNodeUser call
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
{
BatchRequest<ComputeNodeAddUserParameters, ComputeNodeAddUserResponse> request =
(BatchRequest<ComputeNodeAddUserParameters, ComputeNodeAddUserResponse>)baseRequest;

request.ServiceRequestFunc = (cancellationToken) =>
{
ComputeNodeAddUserResponse response = new ComputeNodeAddUserResponse();
Task<ComputeNodeAddUserResponse> task = Task.FromResult(response);
return task;
};
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

// Verify no exceptions when required parameters are set
cmdlet.ExecuteCmdlet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using System;
using Microsoft.Azure.Batch;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Azure.Batch.Protocol.Entities;
using Microsoft.Azure.Batch.Protocol.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Moq;
using System.Collections.Generic;
Expand All @@ -24,19 +24,19 @@
using Xunit;
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;

namespace Microsoft.Azure.Commands.Batch.Test.Users
namespace Microsoft.Azure.Commands.Batch.Test.ComputeNodeUsers
{
public class RemoveBatchVMUserCommandTests
public class RemoveBatchComputeNodeUserCommandTests
{
private RemoveBatchVMUserCommand cmdlet;
private RemoveBatchComputeNodeUserCommand cmdlet;
private Mock<BatchClient> batchClientMock;
private Mock<ICommandRuntime> commandRuntimeMock;

public RemoveBatchVMUserCommandTests()
public RemoveBatchComputeNodeUserCommandTests()
{
batchClientMock = new Mock<BatchClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new RemoveBatchVMUserCommand()
cmdlet = new RemoveBatchComputeNodeUserCommand()
{
CommandRuntime = commandRuntimeMock.Object,
BatchClient = batchClientMock.Object,
Expand All @@ -45,7 +45,7 @@ public RemoveBatchVMUserCommandTests()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RemoveBatchUserParametersTest()
public void RemoveBatchComputeNodeUserParametersTest()
{
// Setup cmdlet without the required parameters
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
Expand All @@ -57,20 +57,22 @@ public void RemoveBatchUserParametersTest()

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

cmdlet.PoolName = "testPool";
cmdlet.VMName = "vm1";
cmdlet.PoolId = "testPool";
cmdlet.ComputeNodeId = "computeNode1";
cmdlet.Name = "testUser";

// Don't go to the service on a DeleteTVMUser call
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
{
if (request is DeleteTVMUserRequest)
BatchRequest<ComputeNodeDeleteUserParameters, ComputeNodeDeleteUserResponse> request =
(BatchRequest<ComputeNodeDeleteUserParameters, ComputeNodeDeleteUserResponse>)baseRequest;

request.ServiceRequestFunc = (cancellationToken) =>
{
DeleteTVMUserResponse response = new DeleteTVMUserResponse();
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
ComputeNodeDeleteUserResponse response = new ComputeNodeDeleteUserResponse();
Task<ComputeNodeDeleteUserResponse> task = Task.FromResult(response);
return task;
}
return null;
};
});
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };

Expand Down
Loading