Skip to content

Commit bbd4e65

Browse files
jasper-schneidermatthchr
authored andcommitted
Update Batch management plane with latest features
1 parent 25ac615 commit bbd4e65

File tree

107 files changed

+4415
-4954
lines changed

Some content is hidden

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

107 files changed

+4415
-4954
lines changed

src/ResourceManager/AzureBatch/ChangeLog.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Added new parameters to `New-AzureRmBatchAccount`.
22+
- `PoolAllocationMode`: The allocation mode to use for creating pools in the Batch account. To create a Batch account which allocates pool nodes in the user's subscription, set this to `UserSubscription`.
23+
- `KeyVaultId`: The resource ID of the Azure key vault associated with the Batch account.
24+
- `KeyVaultUrl`: The URL of the Azure key vault associated with the Batch account.
25+
* Updated parameters to `New-AzureBatchTask`.
26+
- Removed the `RunElevated` switch. The `UserIdentity` parameter has been added to replace `RunElevated`, and the equivalent behavior can be achieved by constructing a `PSUserIdentity` as shown below:
27+
- $autoUser = New-Object Microsoft.Azure.Commands.Batch.Models.PSAutoUserSpecification -ArgumentList @("Task", "Admin")
28+
- $userIdentity = New-Object Microsoft.Azure.Commands.Batch.Models.PSUserIdentity $autoUser
29+
- Added the `AuthenticationTokenSettings` parameter. This parameter allows you to request the Batch service provide an authentication token to the task when it runs, avoiding the need to pass Batch account keys to the task in order to issue requests to the Batch service.
30+
* Added the `UserAccounts` parameter to `New-AzureBatchPool`.
31+
- This parameter defines user accounts created on each node in the pool.
32+
* Renamed the `Name` parameter to `Path` on `Get-AzureBatchNodeFile`, `Get-AzureBatchNodeFileContent`, and `Remove-AzureBatchNodeFile`.
33+
- A `Name` alias was created for the `Path` parameter.
34+
* Changes to objects:
35+
- Removed the `RunElevated` property on `PSCloudTask`, `PSStartTask`, `PSJobManagerTask`, `PSJobPreparationTask`, and `PSJobReleaseTask`. The `UserIdentity` property has been added to replace `RunElevated`. Equivalent behavior to `RunElevated = $true` can be achieved by constructing a `PSUserIdentity` as shown below:
36+
- $autoUser = New-Object Microsoft.Azure.Commands.Batch.Models.PSAutoUserSpecification -ArgumentList @("Task", "Admin")
37+
- $userIdentity = New-Object Microsoft.Azure.Commands.Batch.Models.PSUserIdentity $autoUser
38+
- Added the `AuthenticationTokenSettings` property to `PSCloudTask` and `PSJobManagerTask`.
39+
- Added the `UserAccounts` property to `PSCloudPool` and `PSPoolSpecification`.
40+
- Renamed the `Name` property on `PSNodeFile` to `Path`.
41+
- Added the `DependencyAction` property to `PSExitOptions`.
42+
- Added the `OSDisk` property to `PSVirtualMachineConfiguration`. Note that in order to allow deploying nodes using custom VHDs, the Batch account being used must have been created with `PoolAllocationMode = UserSubscription`.
43+
* Added support for Azure Active Directory based authentication.
44+
- To use Azure Active Directory authentication, retrieve a `BatchAccountContext` object using the `Get-AzureRmBatchAccount` cmdlet, and supply this `BatchAccountContext` to the `-BatchContext` parameter of a Batch service cmdlet. Azure Active Directory authentication is mandatory for accounts with `PoolAllocationMode = UserSubscription`.
45+
- For existing accounts or for new accounts created with `PoolAllocationMode = BatchService`, you may continue to use shared key authentication by retrieving a `BatchAccountContext` object using the `Get-AzureRmBatchAccoutKeys` cmdlet.
2146

2247
## Version 3.4.1
2348
- Marked cmdlet parameters and type properties obsolete in

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchAccounts/NewBatchAccountCommandTests.cs

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Batch.Models;
1516
using Microsoft.Azure.Management.Batch.Models;
1617
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1718
using Moq;
@@ -46,18 +47,28 @@ public void NewBatchAccountTest()
4647
string accountName = "account01";
4748
string resourceGroup = "resourceGroup";
4849
string location = "location";
49-
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup);
50-
BatchAccountContext expected = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);
50+
AccountCreateParameters actualCreateParameters = null;
5151

52-
batchClientMock.Setup(b => b.CreateAccount(resourceGroup, accountName, location, null, null)).Returns(expected);
52+
// Setup the mock client to return a fake response and capture the account create parameters
53+
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, location);
54+
BatchAccountContext fakeResponse = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);
5355

56+
batchClientMock.Setup(b => b.CreateAccount(It.IsAny<AccountCreateParameters>()))
57+
.Returns(fakeResponse)
58+
.Callback((AccountCreateParameters p) => actualCreateParameters = p);
59+
60+
// Setup and run the cmdlet
5461
cmdlet.AccountName = accountName;
5562
cmdlet.ResourceGroupName = resourceGroup;
5663
cmdlet.Location = location;
57-
5864
cmdlet.ExecuteCmdlet();
5965

60-
commandRuntimeMock.Verify(r => r.WriteObject(expected), Times.Once());
66+
// Verify the fake response was written to the pipeline and that the captured account create
67+
// parameters matched expectations.
68+
commandRuntimeMock.Verify(r => r.WriteObject(fakeResponse), Times.Once());
69+
Assert.Equal(accountName, actualCreateParameters.BatchAccount);
70+
Assert.Equal(resourceGroup, actualCreateParameters.ResourceGroup);
71+
Assert.Equal(location, actualCreateParameters.Location);
6172
}
6273

6374
[Fact]
@@ -68,20 +79,70 @@ public void NewBatchWithAutoStorageAccountTest()
6879
string resourceGroup = "resourceGroup";
6980
string location = "location";
7081
string storageId = "storageId";
82+
AccountCreateParameters actualCreateParameters = null;
7183

72-
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup);
73-
BatchAccountContext expected = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);
84+
// Setup the mock client to return a fake response and capture the account create parameters
85+
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, location);
86+
BatchAccountContext fakeResponse = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);
7487

75-
batchClientMock.Setup(b => b.CreateAccount(resourceGroup, accountName, location, null, storageId)).Returns(expected);
88+
batchClientMock.Setup(b => b.CreateAccount(It.IsAny<AccountCreateParameters>()))
89+
.Returns(fakeResponse)
90+
.Callback((AccountCreateParameters p) => actualCreateParameters = p);
7691

92+
// Setup and run the cmdlet
7793
cmdlet.AccountName = accountName;
7894
cmdlet.ResourceGroupName = resourceGroup;
7995
cmdlet.Location = location;
8096
cmdlet.AutoStorageAccountId = storageId;
97+
cmdlet.ExecuteCmdlet();
98+
99+
// Verify the fake response was written to the pipeline and that the captured account create
100+
// parameters matched expectations.
101+
commandRuntimeMock.Verify(r => r.WriteObject(fakeResponse), Times.Once());
102+
Assert.Equal(accountName, actualCreateParameters.BatchAccount);
103+
Assert.Equal(resourceGroup, actualCreateParameters.ResourceGroup);
104+
Assert.Equal(location, actualCreateParameters.Location);
105+
Assert.Equal(storageId, actualCreateParameters.AutoStorageAccountId);
106+
}
81107

108+
[Fact]
109+
[Trait(Category.AcceptanceType, Category.CheckIn)]
110+
public void CanCreateUserSubscriptionBatchAccount()
111+
{
112+
string accountName = "account01";
113+
string resourceGroup = "resourceGroup";
114+
string location = "location";
115+
string keyVaultId = "subscriptions/0000/resourceGroups/resourceGroup/providers/Microsoft.KeyVault/vaults/myVault";
116+
string keyVaultUrl = "https://myVault.vault.azure.com";
117+
PoolAllocationMode allocationMode = PoolAllocationMode.UserSubscription;
118+
AccountCreateParameters actualCreateParameters = null;
119+
120+
// Setup the mock client to return a fake response and capture the account create parameters
121+
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, location);
122+
BatchAccountContext fakeResponse = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);
123+
124+
batchClientMock.Setup(b => b.CreateAccount(It.IsAny<AccountCreateParameters>()))
125+
.Returns(fakeResponse)
126+
.Callback((AccountCreateParameters p) => actualCreateParameters = p);
127+
128+
// Setup and run the cmdlet
129+
cmdlet.AccountName = accountName;
130+
cmdlet.ResourceGroupName = resourceGroup;
131+
cmdlet.Location = location;
132+
cmdlet.PoolAllocationMode = allocationMode;
133+
cmdlet.KeyVaultId = keyVaultId;
134+
cmdlet.KeyVaultUrl = keyVaultUrl;
82135
cmdlet.ExecuteCmdlet();
83136

84-
commandRuntimeMock.Verify(r => r.WriteObject(expected), Times.Once());
137+
// Verify the fake response was written to the pipeline and that the captured account create
138+
// parameters matched expectations.
139+
commandRuntimeMock.Verify(r => r.WriteObject(fakeResponse), Times.Once());
140+
Assert.Equal(accountName, actualCreateParameters.BatchAccount);
141+
Assert.Equal(resourceGroup, actualCreateParameters.ResourceGroup);
142+
Assert.Equal(location, actualCreateParameters.Location);
143+
Assert.Equal(allocationMode, actualCreateParameters.PoolAllocationMode);
144+
Assert.Equal(keyVaultId, actualCreateParameters.KeyVaultId);
145+
Assert.Equal(keyVaultUrl, actualCreateParameters.KeyVaultUrl);
85146
}
86147
}
87148
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchAccounts/SetBatchAccountCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void UpdateAccountTest()
5454
{"Value", "tagValue"}
5555
};
5656

57-
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, tags);
57+
BatchAccount accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, tags: tags);
5858
BatchAccountContext expected = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);
5959
batchClientMock.Setup(b => b.UpdateAccount(resourceGroup, accountName, tags, storageId)).Returns(expected);
6060

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

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public static class BatchTestHelpers
4646
/// <summary>
4747
/// Builds an AccountResource object using the specified parameters
4848
/// </summary>
49-
public static BatchAccount CreateAccountResource(string accountName, string resourceGroupName, Hashtable tags = null, string storageId = null)
49+
public static BatchAccount CreateAccountResource(string accountName, string resourceGroupName, string location = "location",
50+
Hashtable tags = null, string storageId = null)
5051
{
5152
string tenantUrlEnding = "batch-test.windows-int.net";
5253
string endpoint = string.Format("{0}.{1}", accountName, tenantUrlEnding);
@@ -61,17 +62,11 @@ public static BatchAccount CreateAccountResource(string accountName, string reso
6162
activeJobAndJobScheduleQuota: DefaultQuotaCount,
6263
accountEndpoint: endpoint,
6364
id: id,
64-
type: "type")
65-
{
66-
Location = "location",
67-
ProvisioningState = ProvisioningState.Succeeded,
68-
AutoStorage = new AutoStorageProperties() { StorageAccountId = storageId }
69-
};
70-
71-
if (tags != null)
72-
{
73-
resource.Tags = TagsConversionHelper.CreateTagDictionary(tags, true);
74-
}
65+
type: "type",
66+
location: location,
67+
provisioningState: ProvisioningState.Succeeded,
68+
autoStorage: new AutoStorageProperties() { StorageAccountId = storageId },
69+
tags: tags == null ? null : TagsConversionHelper.CreateTagDictionary(tags, true));
7570

7671
return resource;
7772
}
@@ -259,10 +254,10 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromTaskResponseI
259254

260255
propRequest.ServiceRequestFunc = (cancellationToken) =>
261256
{
262-
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromTaskHeaders>();
263-
response.Headers = new ProxyModels.FileGetNodeFilePropertiesFromTaskHeaders();
257+
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromTaskHeaders>();
258+
response.Headers = new ProxyModels.FileGetPropertiesFromTaskHeaders();
264259

265-
Task<AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromTaskHeaders>> task = Task.FromResult(response);
260+
Task<AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromTaskHeaders>> task = Task.FromResult(response);
266261

267262
return task;
268263
};
@@ -301,10 +296,10 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
301296

302297
propRequest.ServiceRequestFunc = (cancellationToken) =>
303298
{
304-
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromComputeNodeHeaders>();
305-
response.Headers = new ProxyModels.FileGetNodeFilePropertiesFromComputeNodeHeaders();
299+
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromComputeNodeHeaders>();
300+
response.Headers = new ProxyModels.FileGetPropertiesFromComputeNodeHeaders();
306301

307-
Task<AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromComputeNodeHeaders>> task = Task.FromResult(response);
302+
Task<AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromComputeNodeHeaders>> task = Task.FromResult(response);
308303

309304
return task;
310305
};
@@ -406,7 +401,7 @@ public static RequestInterceptor ExamineRequestInterceptor<T>(Action<T> assertAc
406401
/// <summary>
407402
/// Builds a CloudPoolUsageMetricsResponse object. Note: The lengths of all three lists must be the same.
408403
/// </summary>
409-
public static AzureOperationResponse<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders> CreatePoolListUsageMetricsResponse(
404+
public static AzureOperationResponse<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListUsageMetricsHeaders> CreatePoolListUsageMetricsResponse(
410405
IEnumerable<string> poolIds,
411406
IEnumerable<DateTime> startTimes,
412407
IEnumerable<DateTime> endTimes)
@@ -435,7 +430,7 @@ public static RequestInterceptor ExamineRequestInterceptor<T>(Action<T> assertAc
435430
}
436431

437432
var response = new AzureOperationResponse
438-
<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders>()
433+
<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListUsageMetricsHeaders>()
439434
{
440435
Response = new HttpResponseMessage(HttpStatusCode.OK),
441436
Body = new MockPagedEnumerable<ProxyModels.PoolUsageMetrics>(poolUsageList)
@@ -447,7 +442,7 @@ public static RequestInterceptor ExamineRequestInterceptor<T>(Action<T> assertAc
447442
/// <summary>
448443
/// Builds a CloudPoolStatisticsResponse object. Note: Using avgCPUPercentage and startTime for validating if the pipeline return the correct values
449444
/// </summary>
450-
public static AzureOperationResponse<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders> CreatePoolStatisticsResponse(
445+
public static AzureOperationResponse<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllLifetimeStatisticsHeaders> CreatePoolStatisticsResponse(
451446
double avgCPUPercentage,
452447
DateTime startTime)
453448
{
@@ -458,7 +453,7 @@ public static RequestInterceptor ExamineRequestInterceptor<T>(Action<T> assertAc
458453
};
459454

460455
var response = new AzureOperationResponse
461-
<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders>()
456+
<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllLifetimeStatisticsHeaders>()
462457
{
463458
Body = stats,
464459
Response = new HttpResponseMessage(HttpStatusCode.Accepted)
@@ -470,15 +465,15 @@ public static RequestInterceptor ExamineRequestInterceptor<T>(Action<T> assertAc
470465
/// <summary>
471466
/// Builds a CloudJobStatisticsResponse object.Note: Using startTime for validating if the pipeline return the correct values
472467
/// </summary>
473-
public static AzureOperationResponse<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders> CreateJobStatisticsResponse(DateTime startTime)
468+
public static AzureOperationResponse<ProxyModels.JobStatistics, ProxyModels.JobGetAllLifetimeStatisticsHeaders> CreateJobStatisticsResponse(DateTime startTime)
474469
{
475470
var stats = new ProxyModels.JobStatistics()
476471
{
477472
StartTime = startTime
478473
};
479474

480475
var response = new AzureOperationResponse
481-
<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders>()
476+
<ProxyModels.JobStatistics, ProxyModels.JobGetAllLifetimeStatisticsHeaders>()
482477
{
483478
Body = stats,
484479
Response = new HttpResponseMessage(HttpStatusCode.Accepted)
@@ -794,22 +789,22 @@ public static AzureOperationResponse<
794789
/// <summary>
795790
/// Builds a NodeFileGetPropertiesFromTaskResponse object
796791
/// </summary>
797-
public static AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromTaskHeaders> CreateNodeFileGetPropertiesByTaskResponse()
792+
public static AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromTaskHeaders> CreateNodeFileGetPropertiesByTaskResponse()
798793
{
799-
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromTaskHeaders>();
794+
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromTaskHeaders>();
800795
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
801-
response.Headers = new ProxyModels.FileGetNodeFilePropertiesFromTaskHeaders();
796+
response.Headers = new ProxyModels.FileGetPropertiesFromTaskHeaders();
802797
return response;
803798
}
804799

805800
/// <summary>
806801
/// Builds a NodeFileGetPropertiesFromComputeNodeResponse object
807802
/// </summary>
808-
public static AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromComputeNodeHeaders> CreateNodeFileGetPropertiesByComputeNodeResponse()
803+
public static AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromComputeNodeHeaders> CreateNodeFileGetPropertiesByComputeNodeResponse()
809804
{
810-
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetNodeFilePropertiesFromComputeNodeHeaders>();
805+
var response = new AzureOperationHeaderResponse<ProxyModels.FileGetPropertiesFromComputeNodeHeaders>();
811806
response.Response = new HttpResponseMessage(HttpStatusCode.OK);
812-
response.Headers = new ProxyModels.FileGetNodeFilePropertiesFromComputeNodeHeaders();
807+
response.Headers = new ProxyModels.FileGetPropertiesFromComputeNodeHeaders();
813808
return response;
814809
}
815810

0 commit comments

Comments
 (0)