Skip to content
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

Use Entra ID auth in Azure tests when possible #9027

Merged
merged 1 commit into from
May 29, 2024
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
@@ -1,5 +1,6 @@
using Azure.Identity;
using Orleans.Configuration;
using Tester.AzureUtils;
using TestExtensions;

namespace ServiceBus.Tests
Expand All @@ -19,5 +20,11 @@ public static EventHubOptions ConfigureTestDefaults(this EventHubOptions options

return options;
}

public static AzureTableStreamCheckpointerOptions ConfigureTestDefaults(this AzureTableStreamCheckpointerOptions options)
{
options.TableServiceClient = AzureStorageOperationOptionsExtensions.GetTableServiceClient();
return options;
}
}
}
1 change: 1 addition & 0 deletions test/Extensions/ServiceBus.Tests/ServiceBus.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<ProjectReference Include="$(SourceRoot)src\Azure\Orleans.Streaming.EventHubs\Orleans.Streaming.EventHubs.csproj" />
<ProjectReference Include="$(SourceRoot)src\Azure\Orleans.Streaming.AzureStorage\Orleans.Streaming.AzureStorage.csproj" />
<ProjectReference Include="$(SourceRoot)test\Tester\Tester.csproj" />
<ProjectReference Include="..\TesterAzureUtils\Tester.AzureUtils.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
b.ConfigurePullingAgent(ob => ob.Configure(options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Configure(ISiloBuilder hostBuilder)
EventHubCheckpointerFactory.CreateFactory,
ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(1);
}));
b.UseDynamicClusterConfigDeploymentBalancer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
});
Expand All @@ -49,7 +49,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(1);
}));
b.UseDynamicClusterConfigDeploymentBalancer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.ConfigureEventHub(ob => ob.Configure(options =>
{
options.ConfigureEventHubConnection(TestDefaultConfiguration.EventHubConnectionString, EHPath, EHConsumerGroup);
options.ConfigureTestDefaults(EHPath, EHConsumerGroup);
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
b.UseDataAdapter((sp, n) => ActivatorUtilities.CreateInstance<EventHubDataAdapter>(sp));
Expand All @@ -68,7 +68,7 @@ public void Configure(IConfiguration configuration, IClientBuilder clientBuilder
{
b.ConfigureEventHub(ob => ob.Configure(options =>
{
options.ConfigureEventHubConnection(TestDefaultConfiguration.EventHubConnectionString, EHPath, EHConsumerGroup);
options.ConfigureTestDefaults(EHPath, EHConsumerGroup);
}));
b.UseDataAdapter((sp, n) => ActivatorUtilities.CreateInstance<EventHubDataAdapter>(sp));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(1);
}));
b.UseDynamicClusterConfigDeploymentBalancer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Xunit;
using Orleans.Configuration;
using Tester;
using Tester.AzureUtils;

namespace ServiceBus.Tests.StreamingTests
{
Expand Down Expand Up @@ -40,7 +41,7 @@ public void Configure(ISiloBuilder hostBuilder)
ImplicitSubscription_RecoverableStream_CollectorGrain.StorageProviderName,
(AzureBlobStorageOptions options) =>
{
options.BlobServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
})
.AddEventHubStreams(StreamProviderName, b=>
{
Expand All @@ -55,7 +56,7 @@ public void Configure(ISiloBuilder hostBuilder)

b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(1);
}));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.ConfigureEventHub(ob => ob.Configure(options =>
{
options.ConfigureEventHubConnection(TestDefaultConfiguration.EventHubConnectionString, EHPath, EHConsumerGroup);
options.ConfigureTestDefaults(EHPath, EHConsumerGroup);
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
b.UseDataAdapter((sp, n) => ActivatorUtilities.CreateInstance<EventHubDataAdapter>(sp));
Expand All @@ -50,7 +50,7 @@ public void Configure(IConfiguration configuration, IClientBuilder clientBuilder
{
b.ConfigureEventHub(ob => ob.Configure(options =>
{
options.ConfigureEventHubConnection(TestDefaultConfiguration.EventHubConnectionString, EHPath, EHConsumerGroup);
options.ConfigureTestDefaults(EHPath, EHConsumerGroup);
}));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(1);
}));
b.UseDynamicClusterConfigDeploymentBalancer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
b.ConfigureStreamPubSub(StreamPubSubType.ImplicitOnly);
Expand All @@ -53,7 +53,7 @@ public void Configure(ISiloBuilder hostBuilder)
}));
b.UseAzureTableCheckpointer(ob => ob.Configure(options =>
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
options.ConfigureTestDefaults();
options.PersistInterval = TimeSpan.FromSeconds(10);
}));
b.ConfigureStreamPubSub(StreamPubSubType.ImplicitOnly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Orleans.Streaming.EventHubs;
using Orleans.Streams;
using TestExtensions;
using Tester.AzureUtils;

namespace ServiceBus.Tests.TestStreamProviders.EventHub
{
Expand Down Expand Up @@ -44,29 +45,15 @@ private static AzureTableDataManager<TableEntity> GetDataManager()
private static AzureStorageOperationOptions GetAzureStorageOperationOptions()
{
var options = new AzureStorageOperationOptions { TableName = TableName };
if (TestDefaultConfiguration.UseAadAuthentication)
{
options.TableServiceClient = new(TestDefaultConfiguration.TableEndpoint, new DefaultAzureCredential());
}
else
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
}
options.TableServiceClient = AzureStorageOperationOptionsExtensions.GetTableServiceClient();

return options;
}

private static Orleans.Streaming.AzureStorage.AzureStorageOperationOptions GetStreamingAzureStorageOperationOptions()
{
var options = new Orleans.Streaming.AzureStorage.AzureStorageOperationOptions { TableName = TableName };
if (TestDefaultConfiguration.UseAadAuthentication)
{
options.TableServiceClient = new(TestDefaultConfiguration.TableEndpoint, new DefaultAzureCredential());
}
else
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
}
options.TableServiceClient = AzureStorageOperationOptionsExtensions.GetTableServiceClient();

return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override IGatewayListProvider CreateGatewayListProvider(ILogger logger
protected override Task<string> GetConnectionString()
{
TestUtils.CheckForAzureStorage();
return Task.FromResult(TestDefaultConfiguration.DataConnectionString);
return Task.FromResult("not used");
}

[SkippableFact, TestCategory("Functional")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override IReminderTable CreateRemindersTable()
protected override Task<string> GetConnectionString()
{
TestUtils.CheckForAzureStorage();
return Task.FromResult(TestDefaultConfiguration.DataConnectionString);
return Task.FromResult("not used");
}

[SkippableFact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Azure.Data.Tables;
using Azure.Identity;
using Microsoft.Extensions.Options;
using TestExtensions;

namespace Tester.AzureUtils
Expand All @@ -7,56 +9,35 @@ public static class AzureStorageOperationOptionsExtensions
{
public static Orleans.Clustering.AzureStorage.AzureStorageOperationOptions ConfigureTestDefaults(this Orleans.Clustering.AzureStorage.AzureStorageOperationOptions options)
{
if (TestDefaultConfiguration.UseAadAuthentication)
{
options.TableServiceClient = new(TestDefaultConfiguration.TableEndpoint, new DefaultAzureCredential());
}
else
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
}
options.TableServiceClient = GetTableServiceClient();

return options;
}

public static TableServiceClient GetTableServiceClient()
{
return TestDefaultConfiguration.UseAadAuthentication
? new(TestDefaultConfiguration.TableEndpoint, new DefaultAzureCredential())
: new(TestDefaultConfiguration.DataConnectionString);
}

public static Orleans.GrainDirectory.AzureStorage.AzureStorageOperationOptions ConfigureTestDefaults(this Orleans.GrainDirectory.AzureStorage.AzureStorageOperationOptions options)
{
if (TestDefaultConfiguration.UseAadAuthentication)
{
options.TableServiceClient = new(TestDefaultConfiguration.TableEndpoint, new DefaultAzureCredential());
}
else
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
}
options.TableServiceClient = GetTableServiceClient();

return options;
}

public static Orleans.Persistence.AzureStorage.AzureStorageOperationOptions ConfigureTestDefaults(this Orleans.Persistence.AzureStorage.AzureStorageOperationOptions options)
{
if (TestDefaultConfiguration.UseAadAuthentication)
{
options.TableServiceClient = new(TestDefaultConfiguration.TableEndpoint, new DefaultAzureCredential());
}
else
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
}
options.TableServiceClient = GetTableServiceClient();

return options;
}

public static Orleans.Reminders.AzureStorage.AzureStorageOperationOptions ConfigureTestDefaults(this Orleans.Reminders.AzureStorage.AzureStorageOperationOptions options)
{
if (TestDefaultConfiguration.UseAadAuthentication)
{
options.TableServiceClient = new(TestDefaultConfiguration.TableEndpoint, new DefaultAzureCredential());
}
else
{
options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString);
}
options.TableServiceClient = GetTableServiceClient();

return options;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Orleans.TestingHost;
using TestExtensions;
using Tester.AzureUtils;
using UnitTests.Grains.Directories;

namespace Tester.Directories
Expand All @@ -13,7 +14,7 @@ public void Configure(ISiloBuilder siloBuilder)
{
siloBuilder.AddAzureTableGrainDirectory(
CustomDirectoryGrain.DIRECTORY,
options => options.TableServiceClient = new(TestDefaultConfiguration.DataConnectionString));
options => options.TableServiceClient = AzureStorageOperationOptionsExtensions.GetTableServiceClient());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ public void Configure(ISiloBuilder hostBuilder)
public override async Task DisposeAsync()
{
await base.DisposeAsync();
if (!string.IsNullOrWhiteSpace(TestDefaultConfiguration.DataConnectionString))
try
{
TestUtils.CheckForAzureStorage();
var serviceId = this.HostedCluster.Client.ServiceProvider.GetRequiredService<IOptions<ClusterOptions>>().Value.ServiceId;
await AzureQueueStreamProviderUtils.DeleteAllUsedAzureQueues(NullLoggerFactory.Instance, AzureQueueStreamProviderUtils.GenerateDefaultAzureQueueNames(serviceId, AQStreamProviderName),
new AzureQueueOptions().ConfigureTestDefaults());
await TestAzureTableStorageStreamFailureHandler.DeleteAll();
}
catch (SkipException)
{
// Ignore
}
}

[SkippableFact(Skip="https://github.com/dotnet/orleans/issues/5639"), TestCategory("Functional"), TestCategory("AzureStorage"), TestCategory("Storage"), TestCategory("Streaming")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ public override async Task DisposeAsync()
await base.DisposeAsync();

// Only perform cleanup if this suite was not skipped.
if (!string.IsNullOrWhiteSpace(TestDefaultConfiguration.DataConnectionString))
try
{
TestUtils.CheckForAzureStorage();
await AzureQueueStreamProviderUtils.DeleteAllUsedAzureQueues(NullLoggerFactory.Instance,
AzureQueueUtilities.GenerateQueueNames(this.HostedCluster.Options.ClusterId, queueCount), new AzureQueueOptions().ConfigureTestDefaults());
await AzureQueueStreamProviderUtils.DeleteAllUsedAzureQueues(NullLoggerFactory.Instance,
AzureQueueUtilities.GenerateQueueNames($"{this.HostedCluster.Options.ClusterId}2", queueCount), new AzureQueueOptions().ConfigureTestDefaults());
}
catch (SkipException)
{
// ignore
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ protected override void CheckPreconditionsOrThrow()

public async Task DisposeAsync()
{
if (!string.IsNullOrWhiteSpace(TestDefaultConfiguration.DataConnectionString))
try
{
TestUtils.CheckForAzureStorage();
await AzureQueueStreamProviderUtils.ClearAllUsedAzureQueues(
NullLoggerFactory.Instance,
AzureQueueUtilities.GenerateQueueNames(this.fixture.HostedCluster.Options.ClusterId, queueCount),
new AzureQueueOptions().ConfigureTestDefaults());
}
catch (SkipException)
{
// Ignore
}
}
}
}
Loading
Loading