Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public GetBatchApplicationCommandTests()
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void ListBatchApplicationsTest()
{
List<BatchAccountContext> pipelineOutput = new List<BatchAccountContext>();

string accountName01 = "account01";
string resourceGroup = "resourceGroup";

Expand Down
5 changes: 3 additions & 2 deletions src/Batch/Batch.Test/Batch.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="9.0.0" />
<PackageReference Include="Microsoft.Azure.Batch" Version="13.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="10.0.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.21.1-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/Batch/Batch.Test/ScenarioTests/BatchAccountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@ public void TestGetBatchSupportedImages()
{
BatchController.NewInstance.RunPsTest(_logger, "Test-GetBatchSupportedImage");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreateNewBatchAccountWithNoPublicIp()
{
BatchController.NewInstance.RunPsTest(_logger, "Test-CreateNewBatchAccountWithNoPublicIp");
}
}
}
36 changes: 34 additions & 2 deletions src/Batch/Batch.Test/ScenarioTests/BatchAccountTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ function Test-BatchAccountEndToEnd
Assert-AreEqual $location $createdAccount.Location
Assert-AreEqual 1 $createdAccount.Tags.Count
Assert-AreEqual $tagValue $createdAccount.Tags[$tagName]
Assert-True { $createdAccount.DedicatedCoreQuota -gt 0 }
Assert-True { $createdAccount.LowPriorityCoreQuota -gt 0 }
Assert-True { $createdAccount.PoolQuota -gt 0 }
Assert-True { $createdAccount.ActiveJobAndJobScheduleQuota -gt 0 }

Expand Down Expand Up @@ -113,4 +111,38 @@ function Test-GetBatchSupportedImage
Assert-True { $supportedImage.OSType -in "linux","windows" }
Assert-AreNotEqual $null $supportedImage.VerificationType
}
}

<#
.SYNOPSIS
Tests creating an account without public network access (note that as of the time of writing this test, it must be run in canary)
#>
function Test-CreateNewBatchAccountWithNoPublicIp
{
# Setup
$accountName = Get-BatchAccountName
$resourceGroup = Get-ResourceGroupName

try
{
$location = Get-BatchAccountProviderLocation
# Create a Batch account
New-AzResourceGroup -Name $resourceGroup -Location $location
$createdAccount = New-AzBatchAccount -Name $accountName -ResourceGroupName $resourceGroup -Location $location -PublicNetworkAccess Disabled

$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name "mysubnet" -AddressPrefix "11.0.1.0/24" -PrivateEndpointNetworkPolicies "Disabled"
New-AzVirtualNetwork -ResourceGroupName $resourceGroup -Name "myvnet" -Location $location -AddressPrefix "11.0.0.0/16" -Subnet $subnetConfig
$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroup -Name "myvnet"

$privateLinkResource = Get-AzPrivateLinkResource -PrivateLinkResourceId $createdAccount.Id

$plsConnection = New-AzPrivateLinkServiceConnection -Name "myplsconnection" -PrivateLinkServiceId $createdAccount.Id -GroupId $privateLinkResource.GroupId
New-AzPrivateEndpoint -ResourceGroupName $resourceGroup -Name "mypec" -Location $location -Subnet $vnet.subnets[0] -PrivateLinkServiceConnection $plsConnection -ByManualRequest

$connection = Get-AzPrivateEndpointConnection -PrivateLinkResourceId $createdAccount.Id
}
finally
{
Remove-AzResourceGroup $resourceGroup
}
}
18 changes: 16 additions & 2 deletions src/Batch/Batch.Test/ScenarioTests/BatchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.Internal.Common;
using Microsoft.Azure.Management.Batch;
using Microsoft.Azure.Management.Internal.Resources;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
Expand All @@ -42,6 +44,10 @@ public class BatchController

public BatchManagementClient BatchManagementClient { get; private set; }

public NetworkManagementClient NetworkManagementClient { get; private set; }

public AzureRestClient AzureRestClient { get; private set; }

public static BatchController NewInstance => new BatchController();

public BatchController()
Expand Down Expand Up @@ -102,7 +108,8 @@ public void RunPsTestWorkflow(
"ScenarioTests\\Common.ps1",
"ScenarioTests\\" + callingClassName + ".ps1",
_helper.RMProfileModule,
_helper.GetRMModulePath("AzureRM.Batch.psd1"),
_helper.GetRMModulePath("Az.Batch.psd1"),
_helper.GetRMModulePath("Az.Network.psd1"),
"AzureRM.Resources.ps1");

try
Expand All @@ -125,15 +132,22 @@ private void SetupManagementClients(MockContext context)
{
ResourceManagementClient = GetResourceManagementClient(context);
BatchManagementClient = GetBatchManagementClient(context);
NetworkManagementClient = GetNetworkManagementClient(context);
AzureRestClient = context.GetServiceClient<AzureRestClient>(TestEnvironmentFactory.GetTestEnvironment());

_helper.SetupManagementClients(ResourceManagementClient, BatchManagementClient);
_helper.SetupManagementClients(ResourceManagementClient, BatchManagementClient, NetworkManagementClient, AzureRestClient);
}

private ResourceManagementClient GetResourceManagementClient(MockContext context)
{
return context.GetServiceClient<ResourceManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
}

private NetworkManagementClient GetNetworkManagementClient(MockContext context)
{
return context.GetServiceClient<NetworkManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
}

private BatchManagementClient GetBatchManagementClient(MockContext context)
{
if (HttpMockServer.Mode == HttpRecorderMode.Record)
Expand Down
4 changes: 1 addition & 3 deletions src/Batch/Batch.Test/ScenarioTests/CertificateTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ function Test-CertificateCrudOperations
$localDir = ($pwd).Path # Use $pwd to get the local directory. If $pwd is not used, paths are relative to [Environment]::CurrentDirectory, which can be different

$certPathVs = $localDir + "/Resources/BatchTestCert01.cer"
# $certPathConsole = [System.IO.Path]::GetDirectoryName($PSScriptRoot) + "/Resources/BatchTestCert01.cer"
# $certPath = if (Test-Path $certPathVs -PathType Leaf) { $certPathVs } Else { $certPathConsole }
$x509cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList $certPathVs

# Add the cert
$x509cert | New-AzBatchCertificate -BatchContext $context
$x509cert | New-AzBatchCertificate -Kind "Cer" -BatchContext $context

# Get the cert and ensure its properties match expectations
$addedCert = Get-AzBatchCertificate $thumbprintAlgorithm $x509cert.Thumbprint -BatchContext $context
Expand Down
2 changes: 1 addition & 1 deletion src/Batch/Batch.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Get-BatchAccountProviderLocation($index)
$type = "batchAccounts"
$r = Get-AzResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
$location = $r.Locations

if ($location -eq $null)
{
return "westus"
Expand Down
2 changes: 1 addition & 1 deletion src/Batch/Batch.Test/ScenarioTests/JobScheduleTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Test-JobScheduleCRUD
$jobSpec2.PoolInformation = New-Object Microsoft.Azure.Commands.Batch.Models.PSPoolInformation
$jobSpec2.PoolInformation.PoolId = "testPool2"
$schedule2 = New-Object Microsoft.Azure.Commands.Batch.Models.PSSchedule
$schedule2.DoNotRunUntil = New-Object System.DateTime -ArgumentList @(2020, 01, 01, 12, 30, 0)
$schedule2.DoNotRunUntil = New-Object System.DateTime -ArgumentList @(2023, 01, 01, 12, 30, 0)
New-AzBatchJobSchedule -Id $jsId2 -JobSpecification $jobSpec2 -Schedule $schedule2 -BatchContext $context

# List the job schedules to ensure they were created
Expand Down
13 changes: 12 additions & 1 deletion src/Batch/Batch.Test/ScenarioTests/ScenarioTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ namespace Microsoft.Azure.Commands.Batch.Test.ScenarioTests
/// </summary>
public static class ScenarioTestHelpers
{
// We expect that the following pools be created, with a configuration like:
// testPool:
// - 2 nodes
// - PAAS
// - A start task with: "cmd /c "echo hello""

// testIaasPool
// - 1 node
// - IAAS (Ubuntu 18.04)

internal const string SharedPool = "testPool";
internal const string SharedIaasPool = "testIaasPool";
internal const string SharedPoolStartTaskStdOut = "startup\\stdout.txt";
Expand Down Expand Up @@ -124,7 +134,8 @@ public static string AddTestCertificate(BatchController controller, BatchAccount
}
}

NewCertificateParameters parameters = new NewCertificateParameters(context, null, cert.RawData);
NewCertificateParameters parameters = new NewCertificateParameters(
context, null, cert.RawData, PSCertificateKind.Cer);

client.AddCertificate(parameters);

Expand Down

Large diffs are not rendered by default.

Loading