Skip to content

Commit a4359ce

Browse files
authored
Merge pull request Azure#8537 from filizt/PowershellUpdates
Initial PR for Blueprints PowerShell Module
2 parents e4535f5 + 21b3e48 commit a4359ce

File tree

62 files changed

+16436
-1
lines changed

Some content is hidden

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

62 files changed

+16436
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<PsModuleName>Blueprint</PsModuleName>
4+
</PropertyGroup>
5+
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
6+
<PropertyGroup>
7+
<RootNamespace>$(LegacyAssemblyPrefix)$(PsModuleName)$(AzTestAssemblySuffix)</RootNamespace>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Remove="Data\**" />
11+
<Compile Remove="UnitTests\**" />
12+
<EmbeddedResource Remove="Data\**" />
13+
<EmbeddedResource Remove="UnitTests\**" />
14+
<None Remove="Data\**" />
15+
<None Remove="UnitTests\**" />
16+
</ItemGroup>
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.10.0-preview" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<ProjectReference Include="..\Blueprint\Blueprint.csproj" />
22+
</ItemGroup>
23+
<ItemGroup>
24+
<None Update="SubscriptionLevelSimpleBlueprint.json">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<PackageReference Update="Microsoft.Azure.Management.ResourceManager" Version="1.9.1-preview" />
30+
</ItemGroup>
31+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Reflection;
17+
using System.Runtime.InteropServices;
18+
using Xunit;
19+
20+
// General Information about an assembly is controlled through the following
21+
// set of attributes. Change these attribute values to modify the information
22+
// associated with an assembly.
23+
[assembly: AssemblyTitle("Microsoft Azure Powershell")]
24+
[assembly: AssemblyCompany(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCompany)]
25+
[assembly: AssemblyProduct(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyProduct)]
26+
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]
27+
28+
// Setting ComVisible to false makes the types in this assembly not visible
29+
// to COM components. If you need to access a type in this assembly from
30+
// COM, set the ComVisible attribute to true on that type.
31+
[assembly: ComVisible(false)]
32+
33+
// The following GUID is for the ID of the typelib if this project is exposed to COM
34+
[assembly: Guid("b68df865-6fc0-4339-8e7a-6bcd4e76fb7f")]
35+
36+
// Version information for an assembly consists of the following four values:
37+
//
38+
// Major Version
39+
// Minor Version
40+
// Build Number
41+
// Revision
42+
//
43+
// You can specify all the values or you can default the Build and Revision Numbers
44+
// by using the '*' as shown below:
45+
46+
[assembly: AssemblyVersion("4.0.0")]
47+
[assembly: AssemblyFileVersion("4.0.0")]
48+
[assembly: CLSCompliant(false)]
49+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.Commands.ScenarioTest;
7+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
8+
using Xunit;
9+
10+
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
11+
{
12+
public class BlueprintAssignmentTests
13+
{
14+
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
15+
16+
public BlueprintAssignmentTests(Xunit.Abstractions.ITestOutputHelper output)
17+
{
18+
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
19+
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
20+
TestExecutionHelpers.SetUpSessionAndProfile();
21+
}
22+
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
public void TestGetBlueprintAssignment()
26+
{
27+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprintAssignment");
28+
}
29+
30+
[Fact(Skip = "Investigate auto-registration for RP")]
31+
[Trait(Category.AcceptanceType, Category.CheckIn)]
32+
public void TestNewBlueprintAssignmentWithSystemAssignedIdentity()
33+
{
34+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewBlueprintAssignmentWithSystemAssignedIdentity");
35+
}
36+
37+
[Fact(Skip="Investigate auto-registration for RP")]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void TestNewBlueprintAssignment()
40+
{
41+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewBlueprintAssignment");
42+
}
43+
44+
[Fact(Skip = "Investigate auto-registration for RP")]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
public void TestSetBlueprintAssignment()
47+
{
48+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SetBlueprintAssignment");
49+
}
50+
51+
[Fact(Skip = "Investigate auto-registration for RP")]
52+
[Trait(Category.AcceptanceType, Category.CheckIn)]
53+
public void TestRemoveBlueprintAssignment()
54+
{
55+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-RemoveBlueprintAssignment");
56+
}
57+
58+
}
59+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<#
2+
.SYNOPSIS
3+
Test Blueprint assignment cmdlets. Get a single Blueprint and assignment it to a subscription and delete.
4+
#>
5+
6+
function Test-GetBlueprintAssignment
7+
{
8+
$assignments = Get-AzBlueprintAssignment
9+
10+
Assert-True { $assignments.Count -ge 1 }
11+
Assert-NotNull $assignments[0].Name
12+
Assert-NotNull $assignments[0].Id
13+
Assert-NotNull $assignments[0].BlueprintId
14+
Assert-NotNull $assignments[0].Scope
15+
Assert-NotNull $assignments[0].Location
16+
}
17+
18+
function Test-NewBlueprintAssignment
19+
{
20+
$mgId = "AzBlueprintAssignTest"
21+
$blueprintName = "Filiz-Ps-Test1"
22+
$subscriptionId = "28cbf98f-381d-4425-9ac4-cf342dab9753"
23+
$assignmentName = "PS-ScenarioTest-NewAssignment"
24+
$location = "East US"
25+
$params = @{audituseofclassicvirtualmachines_effect='Audit'}
26+
$rg1 = @{name='bp-testrg';location='eastus'}
27+
$rgs = @{ResourceGroup=$rg1}
28+
$identity = "/subscriptions/996a2f3f-ee01-4ffd-9765-d2c3fc98f30a/resourceGroups/user-assigned-test/providers/Microsoft.ManagedIdentity/userAssignedIdentities/owner-identity"
29+
30+
$blueprint = Get-AzBlueprint -ManagementGroupId $mgId -Name $blueprintName -LatestPublished
31+
Assert-NotNull $blueprint
32+
33+
$assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity
34+
35+
$expectedProvisioningState = "Creating"
36+
Assert-NotNull $assignment
37+
Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState
38+
}
39+
40+
function Test-NewBlueprintAssignmentWithSystemAssignedIdentity
41+
{
42+
$subscriptionId = "0b1f6471-1bf0-4dda-aec3-cb9272f09590"
43+
$assignmentName = "PS-ScenarioTest-NewSystemAssignedIdentityAssignment"
44+
$location = "West US"
45+
$blueprintName = "PS-SimpleBlueprintDefinition"
46+
47+
#deploy blueprint
48+
$deployment = New-AzDeployment -Name $blueprintName -Location $location -TemplateFile SubscriptionLevelSimpleBlueprint.json
49+
Assert-AreEqual Succeeded $deployment.ProvisioningState
50+
51+
$blueprint = Get-AzBlueprint -SubscriptionId $subscriptionId -Name $blueprintName -LatestPublished
52+
Assert-NotNull $blueprint
53+
54+
$assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location
55+
Assert-NotNull $assignment
56+
}
57+
58+
function Test-SetBlueprintAssignment
59+
{
60+
$mgId = "AzBlueprintAssignTest"
61+
$blueprintName = "Filiz-Ps-Test1"
62+
$subscriptionId = "28cbf98f-381d-4425-9ac4-cf342dab9753"
63+
$assignmentName = "PS-ScenarioTest-SetAssignment"
64+
$location = "East US"
65+
$params = @{audituseofclassicvirtualmachines_effect='Audit'}
66+
$rg1 = @{name='bp-testrg';location='eastus'}
67+
$rgs = @{ResourceGroup=$rg1}
68+
$identity = "/subscriptions/996a2f3f-ee01-4ffd-9765-d2c3fc98f30a/resourceGroups/user-assigned-test/providers/Microsoft.ManagedIdentity/userAssignedIdentities/owner-identity"
69+
70+
# Get the test blueprint
71+
$blueprint = Get-AzBlueprint -ManagementGroupId $mgId -Name $blueprintName -LatestPublished
72+
Assert-NotNull $blueprint
73+
74+
# Assign blueprint
75+
$assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity
76+
$expectedProvisioningState = "Creating"
77+
Assert-NotNull $assignment
78+
Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState
79+
80+
# Retrieve assigned blueprint
81+
$assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName
82+
# Wait till the provisioning state changes to succeeded
83+
$assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName
84+
while($assigned.ProvisioningState -eq "Creating" -or $assigned.ProvisioningState -eq "Deploying" -or $assigned.ProvisioningState -eq "Waiting")
85+
{
86+
Wait-Seconds 10
87+
$assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName
88+
}
89+
90+
#update rg name and re-assign
91+
$newTestRg = "bp-testrg-new"
92+
$rg1 = @{name= $newTestRg;location='eastus'}
93+
$rgs = @{ResourceGroup=$rg1}
94+
$assignment = Set-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity
95+
$expectedProvisioningState = "Creating"
96+
Assert-NotNull $assignment
97+
Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState
98+
}
99+
100+
function Test-RemoveBlueprintAssignment
101+
{
102+
$mgId = "AzBlueprintAssignTest"
103+
$blueprintName = "Filiz-Ps-Test1"
104+
$subscriptionId = "28cbf98f-381d-4425-9ac4-cf342dab9753"
105+
$assignmentName = "PS-ScenarioTest-RemoveAssignment"
106+
$location = "East US"
107+
$params = @{audituseofclassicvirtualmachines_effect='Audit'}
108+
$rg1 = @{name='bp-testrg';location='eastus'}
109+
$rgs = @{ResourceGroup=$rg1}
110+
$identity = "/subscriptions/996a2f3f-ee01-4ffd-9765-d2c3fc98f30a/resourceGroups/user-assigned-test/providers/Microsoft.ManagedIdentity/userAssignedIdentities/owner-identity"
111+
112+
# Get the test blueprint
113+
$blueprint = Get-AzBlueprint -ManagementGroupId $mgId -Name $blueprintName -LatestPublished
114+
Assert-NotNull $blueprint
115+
116+
# Assign blueprint
117+
$assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity
118+
$expectedProvisioningState = "Creating"
119+
Assert-NotNull $assignment
120+
Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState
121+
122+
# Retrieve assigned blueprint
123+
$assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName
124+
while($assigned.ProvisioningState -eq "Creating" -or $assigned.ProvisioningState -eq "Deploying" -or $assigned.ProvisioningState -eq "Waiting")
125+
{
126+
Wait-Seconds 10
127+
$assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName
128+
}
129+
130+
# remove assignment
131+
$removed = Remove-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignment.Name -PassThru
132+
$expectedProvisioningState = "Deleting"
133+
Assert-NotNull $removed
134+
Assert-AreEqual $removed.Name $assignment.Name
135+
Assert-AreEqual $removed.ProvisioningState $expectedProvisioningState
136+
}
137+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests;
7+
using Microsoft.Azure.Commands.ScenarioTest;
8+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
9+
using Xunit;
10+
11+
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
12+
{
13+
public class BlueprintTests
14+
{
15+
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
16+
17+
18+
public BlueprintTests(Xunit.Abstractions.ITestOutputHelper output)
19+
{
20+
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
21+
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
22+
TestExecutionHelpers.SetUpSessionAndProfile();
23+
}
24+
25+
[Fact(Skip = "There is a framework issue where HttpClient calls are not recorded in session records causing tests to fail in playback mode")]
26+
[Trait(Category.AcceptanceType, Category.CheckIn)]
27+
public void TestGetBlueprint()
28+
{
29+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprint");
30+
}
31+
32+
[Fact]
33+
[Trait(Category.AcceptanceType, Category.CheckIn)]
34+
public void TestGetBlueprintWithDefinitionLocationNameAndVersion()
35+
{
36+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprintWithDefinitionLocationNameAndVersion");
37+
}
38+
39+
[Fact]
40+
[Trait(Category.AcceptanceType, Category.CheckIn)]
41+
public void TestGetBlueprintWithDefinitionLocationNameAndLatestPublished()
42+
{
43+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetBlueprintWithDefinitionLocationNameAndLatestPublished");
44+
}
45+
}
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<#
2+
.SYNOPSIS
3+
Test Blueprint cmdlets. Get a single Blueprint and list of Blueprints.
4+
#>
5+
function Test-GetBlueprint
6+
{
7+
$blueprints = Get-AzBlueprint
8+
9+
Assert-True {$blueprints.Count -ge 1}
10+
Assert-NotNull $blueprints[0].Name
11+
Assert-NotNull $blueprints[0].Id
12+
Assert-NotNull $blueprints[0].Scope
13+
Assert-NotNull $blueprints[0].DefinitionLocationId
14+
Assert-NotNull $blueprints[0].TargetScope
15+
Assert-NotNull $blueprints[0].Description
16+
}
17+
18+
function Test-GetBlueprintWithDefinitionLocationNameAndVersion
19+
{
20+
$mgId = "AzBlueprint"
21+
$name = "Filiz_Powershell_Test"
22+
$version = "6.0"
23+
$blueprintByMG = Get-AzBlueprint -ManagementGroupId $mgId -Name $name -Version $version
24+
25+
Assert-NotNull $blueprintByMG
26+
Assert-NotNull $blueprintByMG.Id
27+
Assert-NotNull $blueprintByMG.Scope
28+
Assert-NotNull $blueprintByMG.DefinitionLocationId
29+
Assert-NotNull $blueprintByMG.TargetScope
30+
}
31+
32+
function Test-GetBlueprintWithDefinitionLocationNameAndLatestPublished
33+
{
34+
$mgId = "AzBlueprint"
35+
$name = "Filiz_Powershell_Test"
36+
$blueprintByMG = Get-AzBlueprint -ManagementGroupId $mgId -Name $name -LatestPublished
37+
38+
Assert-NotNull $blueprintByMG
39+
Assert-NotNull $blueprintByMG.Id
40+
Assert-NotNull $blueprintByMG.Scope
41+
Assert-NotNull $blueprintByMG.DefinitionLocationId
42+
Assert-NotNull $blueprintByMG.TargetScope
43+
}

0 commit comments

Comments
 (0)