Skip to content

Commit be176bb

Browse files
author
jasper-schneider
committed
Cleanup Batch MPI tests
1 parent 69c7f30 commit be176bb

File tree

7 files changed

+11525
-923
lines changed

7 files changed

+11525
-923
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,6 @@
665665
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListAllTasks.json">
666666
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
667667
</None>
668-
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListSubtasksWithMaxCount.json">
669-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
670-
</None>
671668
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.TaskTests\TestListTaskPipeline.json">
672669
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
673670
</None>

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/ScenarioTestHelpers.cs

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,8 @@ public static class ScenarioTestHelpers
5454
internal const string SharedPoolStartTaskStdOut = "startup\\stdout.txt";
5555
internal const string SharedPoolStartTaskStdOutContent = "hello";
5656

57-
// MPI requires a special pool configuration. When recording, the Storage environment variables need to be
58-
// set so we can upload the MPI installer for use as a start task resource file.
57+
// MPI requires a special pool configuration, so a dedicated pool is used.
5958
internal const string MpiPoolId = "mpiPool";
60-
internal const string MpiSetupFileContainer = "mpi";
61-
internal const string MpiSetupFileName = "MSMpiSetup.exe";
62-
internal const string MpiSetupFileLocalPath = "Resources\\MSMpiSetup.exe";
63-
internal const string StorageAccountEnvVar = "AZURE_STORAGE_ACCOUNT";
64-
internal const string StorageKeyEnvVar = "AZURE_STORAGE_ACCESS_KEY";
6559

6660
internal const string BatchAccountName = "AZURE_BATCH_ACCOUNT";
6761
internal const string BatchAccountKey = "AZURE_BATCH_ACCESS_KEY";
@@ -229,27 +223,17 @@ public static void CreateMpiPoolIfNotExists(BatchController controller, BatchAcc
229223
client.ListPools(listOptions);
230224
return; // The call returned without throwing an exception, so the pool exists
231225
}
232-
catch (AggregateException aex)
226+
catch (BatchException ex)
233227
{
234-
BatchException innerException = aex.InnerException as BatchException;
235-
if (innerException == null || innerException.RequestInformation == null || innerException.RequestInformation.BatchError == null ||
236-
innerException.RequestInformation.BatchError.Code != BatchErrorCodeStrings.PoolNotFound)
228+
if (ex.RequestInformation == null || ex.RequestInformation.BatchError == null ||
229+
ex.RequestInformation.BatchError.Code != BatchErrorCodeStrings.PoolNotFound)
237230
{
238231
throw;
239232
}
240233
// We got the pool not found error, so continue and create the pool
241234
}
242235

243-
string blobUrl = UploadBlobAndGetUrl(MpiSetupFileContainer, MpiSetupFileName, MpiSetupFileLocalPath);
244-
245-
StartTask startTask = new StartTask();
246-
startTask.CommandLine = string.Format("cmd /c set & {0} -unattend -force", MpiSetupFileName);
247-
startTask.ResourceFiles = new List<ResourceFile>();
248-
startTask.ResourceFiles.Add(new ResourceFile(blobUrl, MpiSetupFileName));
249-
startTask.RunElevated = true;
250-
startTask.WaitForSuccess = true;
251-
252-
CreateTestPool(controller, context, MpiPoolId, targetDedicated, startTask: startTask);
236+
CreateTestPool(controller, context, MpiPoolId, targetDedicated);
253237
}
254238

255239

@@ -602,43 +586,6 @@ public static void DeleteComputeNodeUser(BatchController controller, BatchAccoun
602586
client.DeleteComputeNodeUser(parameters);
603587
}
604588

605-
/// <summary>
606-
/// Uploads a blob to Storage if it doesn't exist and gets the url
607-
/// </summary>
608-
private static string UploadBlobAndGetUrl(string containerName, string blobName, string localFilePath)
609-
{
610-
string blobUrl = "https://defaultUrl.blob.core.windows.net/blobName";
611-
612-
if (HttpMockServer.Mode == HttpRecorderMode.Record)
613-
{
614-
// Create container and upload blob if they don't exist
615-
string storageAccountName = Environment.GetEnvironmentVariable(StorageAccountEnvVar);
616-
string storageKey = Environment.GetEnvironmentVariable(StorageKeyEnvVar);
617-
StorageCredentials creds = new StorageCredentials(storageAccountName, storageKey);
618-
CloudStorageAccount storageAccount = new CloudStorageAccount(creds, true);
619-
620-
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
621-
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
622-
container.CreateIfNotExists();
623-
624-
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
625-
if (!blob.Exists())
626-
{
627-
blob.UploadFromFile(localFilePath, System.IO.FileMode.Open);
628-
}
629-
630-
// Get blob url with SAS string
631-
SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy();
632-
sasPolicy.Permissions = SharedAccessBlobPermissions.Read;
633-
sasPolicy.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(10);
634-
string sasString = container.GetSharedAccessSignature(sasPolicy);
635-
636-
blobUrl = string.Format("{0}/{1}{2}", container.Uri, blobName, sasString);
637-
}
638-
639-
return blobUrl;
640-
}
641-
642589
/// <summary>
643590
/// Uploads an application package to Storage
644591
/// </summary>

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/TaskTests.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -324,33 +324,6 @@ public void TestTerminateTask()
324324
TestUtilities.GetCurrentMethodName());
325325
}
326326

327-
[Fact]
328-
public void TestListSubtasksWithMaxCount()
329-
{
330-
BatchController controller = BatchController.NewInstance;
331-
string jobId = "maxCountSubtaskJob";
332-
string taskId = "testTask";
333-
int numInstances = 3;
334-
int maxCount = 1;
335-
BatchAccountContext context = null;
336-
controller.RunPsTestWorkflow(
337-
() => { return new string[] { string.Format("Test-ListSubtasksWithMaxCount '{0}' '{1}' '{2}'", jobId, taskId, maxCount) }; },
338-
() =>
339-
{
340-
context = new ScenarioTestContext();
341-
ScenarioTestHelpers.CreateMpiPoolIfNotExists(controller, context);
342-
ScenarioTestHelpers.CreateTestJob(controller, context, jobId, ScenarioTestHelpers.MpiPoolId);
343-
ScenarioTestHelpers.CreateTestTask(controller, context, jobId, taskId, "cmd /c hostname", numInstances);
344-
ScenarioTestHelpers.WaitForTaskCompletion(controller, context, jobId, taskId);
345-
},
346-
() =>
347-
{
348-
ScenarioTestHelpers.DeleteJob(controller, context, jobId);
349-
},
350-
TestUtilities.GetCallingClass(),
351-
TestUtilities.GetCurrentMethodName());
352-
}
353-
354327
[Fact]
355328
public void TestListAllSubtasks()
356329
{

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/TaskTests.ps1

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -396,26 +396,6 @@ function Test-TerminateTask
396396
}
397397
}
398398

399-
<#
400-
.SYNOPSIS
401-
Tests querying for Batch subtasks and supplying a max count
402-
#>
403-
function Test-ListSubtasksWithMaxCount
404-
{
405-
param([string]$jobId, [string]$taskId, [string]$maxCount)
406-
407-
$context = New-Object Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ScenarioTestContext
408-
$subtasks = Get-AzureBatchSubtask $jobId $taskId -MaxCount $maxCount -BatchContext $context
409-
410-
Assert-AreEqual $maxCount $subtasks.Length
411-
412-
# Verify parent object parameter set also works
413-
$task = Get-AzureBatchTask $jobId $taskId -BatchContext $context
414-
$subtasks = $task | Get-AzureBatchSubtask -MaxCount $maxCount -BatchContext $context
415-
416-
Assert-AreEqual $maxCount $subtasks.Length
417-
}
418-
419399
<#
420400
.SYNOPSIS
421401
Tests querying for all subtasks under a task

0 commit comments

Comments
 (0)