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

[Az Eventgrid] Add new features for 2021-12-31 release #17608

Merged
merged 20 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 18 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
2 changes: 1 addition & 1 deletion src/EventGrid/EventGrid.Test/EventGrid.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.EventGrid" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Management.EventGrid" Version="7.0.0" />
<PackageReference Include="Microsoft.Azure.Management.EventHub" Version="4.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Relay" Version="2.0.2" />
<PackageReference Include="Microsoft.Azure.Management.ServiceBus" Version="3.0.0" />
Expand Down
10 changes: 10 additions & 0 deletions src/EventGrid/EventGrid.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ function Get-DeadletterResourceId($ResourceGroupName, $StorageAccountName, $Cont
return "/subscriptions/$subId/resourceGroups/$ResourceGroupName/providers/Microsoft.Storage/storageAccounts/$StorageAccountName/blobServices/default/containers/$ContainerName"
}

<#
.SYNOPSIS
Get Storage Account ResourceId
#>
function Get-StorageAccountResourceId($ResourceGroupName, $StorageAccountName)
{
$subId = Get-SubscriptionID
return "/subscriptions/$subId/resourceGroups/$ResourceGroupName/providers/Microsoft.Storage/storageAccounts/$StorageAccountName"
}

<#
.SYNOPSIS
Create new Storage Blob
Expand Down
11 changes: 9 additions & 2 deletions src/EventGrid/EventGrid.Test/ScenarioTests/DomainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public void EventGrid_DomainsCreateGetAndDelete()
EventGridController.NewInstance.RunPsTest(_logger, "DomainTests");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventGrid_DomainsidentityTests()
{
EventGridController.NewInstance.RunPsTest(_logger, "DomainIdentityTests");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventGrid_DomainsGetKey()
Expand All @@ -59,11 +66,11 @@ public void EventGrid_DomainsInputMappingCreateGetAndDelete()
EventGridController.NewInstance.RunPsTest(_logger, "DomainInputMappingTests");
}

[Fact]
/*[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventGrid_DomainTopics()
{
EventGridController.NewInstance.RunPsTest(_logger, "DomainTopicTests");
}
}*/
}
}
67 changes: 67 additions & 0 deletions src/EventGrid/EventGrid.Test/ScenarioTests/DomainTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,73 @@ function DomainTests {
}
}

<#
.SYNOPSIS
Tests EventGrid Domain Identity
#>
function DomainIdentityTests {
# Setup
$location = Get-LocationForEventGrid
$domainName = Get-DomainName
$domainName2 = Get-DomainName
$domainName3 = Get-DomainName
$domainName4 = Get-DomainName

$resourceGroupName = Get-ResourceGroupName
$secondResourceGroup = Get-ResourceGroupName

$subscriptionId = Get-SubscriptionId

New-ResourceGroup $resourceGroupName $location

New-ResourceGroup $secondResourceGroup $location

try
{
Write-Debug "Creating a new EventGrid domain: $domainName in resource group $resourceGroupName"
Write-Debug "Domain: $domainName"
$result = New-AzEventGridDomain -ResourceGroup $resourceGroupName -Name $domainName -Location $location -IdentityType 'SystemAssigned'
Assert-True {$result.ProvisioningState -eq "Succeeded"}
Assert-True {$result.Identity.IdentityType -eq "SystemAssigned"}

Write-Debug "Creating a second EventGrid domain: $domainName2 in resource group $secondResourceGroup with tags and none Identity"
$result = New-AzEventGridDomain -ResourceGroup $secondResourceGroup -Name $domainName2 -Location $location -Tag @{ Dept = "IT"; Environment = "Test" } -IdentityType 'None'
Assert-True {$result.ProvisioningState -eq "Succeeded"}
Assert-True {$result.Identity.IdentityType -eq "None"}

Write-Debug "Creating a third EventGrid domain: $domainName3 in resource group $secondResourceGroup with user assigned identity"
$userIdentity = "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/amh/providers/Microsoft.ManagedIdentity/userAssignedIdentities/testIdentity1"
$result = New-AzEventGridDomain -ResourceGroup $secondResourceGroup -Name $domainName3 -Location $location -IdentityType 'UserAssigned' -IdentityId $userIdentity
Assert-True {$result.ProvisioningState -eq "Succeeded"}
Assert-True {$result.Identity.IdentityType -eq "UserAssigned"} "Domain not created with user identity"



Write-Debug "Deleting domain: $domainName"
Remove-AzEventGridDomain -ResourceGroup $resourceGroupName -Name $domainName

Write-Debug "Deleting domain: $domainName2 using the ResourceID parameter set"
Remove-AzEventGridDomain -ResourceId "/subscriptions/$subscriptionId/resourceGroups/$secondResourceGroup/providers/Microsoft.EventGrid/domains/$domainName2"

Write-Debug "Deleting domain: $domainName3 using the ResourceID parameter"
Remove-AzEventGridDomain -ResourceId "/subscriptions/$subscriptionId/resourceGroups/$secondResourceGroup/providers/Microsoft.EventGrid/domains/$domainName3"

# Remove-AzEventGridDomain -ResourceGroup $secondResourceGroup -Name $domainName3

# Verify that all domains have been deleted correctly
$returnedDomains1 = Get-AzEventGridDomain -ResourceGroup $resourceGroupName
Assert-True {$returnedDomains1.PsDomainsList.Count -eq 0}

$returnedDomains2 = Get-AzEventGridDomain -ResourceGroup $secondResourceGroup
Assert-True {$returnedDomains2.PsDomainsList.Count -eq 0}
}
finally
{
Remove-ResourceGroup $resourceGroupName
Remove-ResourceGroup $secondResourceGroup
}
}

<#
.SYNOPSIS
Tests EventGrid Domain Key retrieval related operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public void EventGrid_EventSubscription_CustomTopics_WebhookBatching()
EventGridController.NewInstance.RunPsTest(_logger, "EventSubscriptionTests_CustomTopic_Webhook_Batching");
}

[Fact]
/* not applicable [Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventGrid_EventSubscription_CustomTopics_WebhookAad()
{
EventGridController.NewInstance.RunPsTest(_logger, "EventSubscriptionTests_CustomTopic_Webhook_AAD");
}
}*/

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
Expand Down Expand Up @@ -110,11 +110,11 @@ public void EventGrid_EventSubscription_Domains()
EventGridController.NewInstance.RunPsTest(_logger, "EventSubscriptionTests_Domains");
}

[Fact]
/* no longer applicable[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventGrid_EventSubscription_DomainTopics()
{
EventGridController.NewInstance.RunPsTest(_logger, "EventSubscriptionTests_DomainTopics");
}
}*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 Microsoft.Azure.Commands.EventGrid.Test.ScenarioTests;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.EventGrid.Test.ScenarioTests
{
public class SystemTopicEventSubscriptionTests : RMTestBase
{
public XunitTracingInterceptor _logger;

public SystemTopicEventSubscriptionTests(ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SystemTopicEventSubscriptionTests_CRUDTest()
{
EventGridController.NewInstance.RunPsTest(_logger, "SystemTopicEventSubscriptionTests");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests EventGrid Topic Create, Get and List operations.
#>
function SystemTopicEventSubscriptionTests {
# Setup
$location = Get-LocationForEventGrid
$topicName = Get-TopicName
$topicName2 = Get-TopicName
$topicName3 = Get-TopicName
$topicName4 = Get-TopicName
$eventSubscriptionName = Get-EventSubscriptionName
$eventSubscriptionName2 = Get-EventSubscriptionName
$eventSubscriptionName3 = Get-EventSubscriptionName
$resourceGroupName = Get-ResourceGroupName
$secondResourceGroup = Get-ResourceGroupName
$subscriptionId = Get-SubscriptionId

New-ResourceGroup $resourceGroupName $location

New-ResourceGroup $secondResourceGroup $location

$eventSubscriptionEndpoint = Get-EventSubscriptionWebhookEndpoint
$eventSubscriptionEndpointCloudEvent = Get-EventSubscriptionWebhookEndpointWithCloudEvent

$storageAccountName = Get-StorageAccountName
$storageContainerName = Get-StorageBlobName

New-StorageBlob $resourceGroupName $storageAccountName $storageContainerName $location
$storageAccountResourceId = Get-StorageAccountResourceId $resourceGroupName $storageAccountName
try
{
Write-Debug "Creating a new EventGrid SystemTopic: $topicName in resource group $resourceGroupName"
Write-Debug "Topic: $topicName"
$result = New-AzEventGridSystemTopic -ResourceGroup $resourceGroupName -Name $topicName -Source $storageAccountResourceId -TopicType 'microsoft.storage.storageaccounts' -Location $location
Assert-True {$result.ProvisioningState -eq "Succeeded"}

Write-Debug "Getting the created topic within the resource group"
$createdTopic = Get-AzEventGridSystemTopic -ResourceGroup $resourceGroupName -Name $topicName
Assert-True {$createdTopic.Count -eq 1}
Assert-True {$createdTopic.TopicName -eq $topicName} "System Topic created earlier is not found."

#Write-Debug "Creating a second EventGrid SystemTopic: $topicName2 in resource group $secondResourceGroup"
#$result = New-AzEventGridSystemTopic -ResourceGroup $secondResourceGroup -Name $topicName2 -Source $sbNamespace1InRg2.Id -TopicType 'Microsoft.ServiceBus.Namespaces' -Location $location -Tag @{ Dept = "IT"; Environment = "Test" }
#Assert-True {$result.ProvisioningState -eq "Succeeded"}

Write-Debug "Creating a new EventSubscription $eventSubscriptionName to topic $topicName in resource group $resourceGroupName"
$result = New-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Endpoint $eventSubscriptionEndpoint -EventSubscriptionName $eventSubscriptionName
Assert-True {$result.ProvisioningState -eq "Succeeded"}

Write-Debug "Get event subscription created for system topic : $topicName"
$createdEventSubscription = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName
Assert-True {$createdEventSubscription.EventSubscriptionName -eq $eventSubscriptionName} "Event subscription created earlier is not found in the list"

Write-Debug "Creating 2nd EventSubscription $eventSubscriptionName2 to topic $topicName in resource group $resourceGroupName"
$result = New-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Endpoint $eventSubscriptionEndpoint -EventSubscriptionName $eventSubscriptionName2
Assert-True {$result.ProvisioningState -eq "Succeeded"}

Write-Debug "Get event subscription created for system topic : $topicName"
$createdEventSubscription2 = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName
Assert-True {$createdEventSubscription2.Count -ge 0} "Event subscription created earlier is not found in the list"

Write-Debug "Get event subscription created for system topic : $topicName"
$createdEventSubscription = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Top 1
Assert-True {$createdEventSubscription.NextLink -ne $null } "NextLink should not be null as more event subscription should be available under system topic"

Write-Debug "Get event subscription created for system topic : $topicName with nextlink"
$createdEventSubscription = Get-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -NextLink $createdEventSubscription.NextLink
Assert-True {$createdEventSubscription -ne $null } "Event subscription should not be null as more event subscription should be available under system topic"

$labels = "Finance", "HR"
Write-Debug "Updating a EventGrid SystemTopic Eventsubscription with TopicName: $topicName in resource group $resourceGroupName and EventSubscriptionName: $eventSubscriptionName"
$result = Update-AzEventGridSystemTopicEventSubscription -EventSubscriptionName $eventSubscriptionName -ResourceGroup $resourceGroupName -SystemTopicName $topicName -Label $labels
Assert-True {$result.ProvisioningState -eq "Succeeded"}
$updatedLabels = $result.Labels
Assert-AreEqual 2 $updatedLabels.Count;
Assert-AreEqual "Finance" $updatedLabels[0];
Assert-AreEqual "HR" $updatedLabels[1];

Write-Debug "Get Delivery attributes for topic: $topicName and Eventsubscription $eventSubscriptionName"
$createdEventSubscriptionDa = Get-AzEventGridSystemTopicEventSubscriptionDeliveryAttribute -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName

Write-Debug "Get full url for topic: $topicName and Eventsubscription $eventSubscriptionName"
$createdEventSubscriptionDa = Get-AzEventGridFullUrlForSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName




Write-Debug "Deleting event subscription : $eventSubscriptionName for system topic : $topicName"
Remove-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName -Force

Write-Debug "Deleting event subscription : $eventSubscriptionName for system topic : $topicName"
Remove-AzEventGridSystemTopicEventSubscription -ResourceGroup $resourceGroupName -SystemTopicName $topicName -EventSubscriptionName $eventSubscriptionName2 -Force


Write-Debug "Deleting topic: $topicName"
Remove-AzEventGridSystemTopic -ResourceGroup $resourceGroupName -Name $topicName -Force

#Write-Debug "Deleting topic: $topicName"
#Remove-AzEventGridSystemTopic -ResourceGroup $secondResourceGroup -Name $topicName2


}
finally
{
Remove-StorageContainerResources $resourceGroupName $storageAccountName $storageContainerName

Remove-ResourceGroup $resourceGroupName
Remove-ResourceGroup $secondResourceGroup
}
}

48 changes: 48 additions & 0 deletions src/EventGrid/EventGrid.Test/ScenarioTests/SystemTopicTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ----------------------------------------------------------------------------------
//
// 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 Microsoft.Azure.Commands.EventGrid.Test.ScenarioTests;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.EventGrid.Test.ScenarioTests
{
public class SystemTopicTests : RMTestBase
{
public XunitTracingInterceptor _logger;

public SystemTopicTests(ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventGrid_SystemTopicsCRUD()
{
EventGridController.NewInstance.RunPsTest(_logger, "SystemTopicTests");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void EventGrid_SystemTopicsIdentityTests()
{
EventGridController.NewInstance.RunPsTest(_logger, "SystemTopicIdentityTests");
}
}
}
Loading