Skip to content

Commit 7839c83

Browse files
committed
Merge pull request #145 from huangpf/dev
Dev
2 parents bc90ea7 + 3b08900 commit 7839c83

File tree

39 files changed

+582
-1101
lines changed

39 files changed

+582
-1101
lines changed

setup-powershellget/Setup/ShortcutStartup.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,19 @@ This may take some time...
5757
$DefaultPSRepository = "PSGallery"
5858
}
5959

60-
Install-Module AzureRM -Repository $DefaultPSRepository
61-
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."
60+
$_InstallationPolicy = (Get-PSRepository -Name $DefaultPSRepository).InstallationPolicy
61+
try
62+
{
63+
Set-PSRepository -Name $DefaultPSRepository -InstallationPolicy Trusted
64+
65+
Install-Module AzureRM -Repository $DefaultPSRepository
66+
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."
6267

63-
Update-AzureRM -Repository $DefaultPSRepository
68+
Update-AzureRM -Repository $DefaultPSRepository
69+
} finally {
70+
# Clean up
71+
Set-PSRepository -Name $DefaultPSRepository -InstallationPolicy $_InstallationPolicy
72+
}
6473
}
6574
elseif ($Uninstall.IsPresent)
6675
{
@@ -72,6 +81,7 @@ This may take some time...
7281
$env:PSModulePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules;$env:ProgramFiles\WindowsPowerShell\Modules;$env:SystemRoot\system32\WindowsPowerShell\v1.0\Modules\"
7382

7483
Uninstall-AzureRM
84+
Uninstall-Module -Name AzureRM -Confirm:$false -Force
7585
}
7686
else
7787
{

src/Common/Commands.Common/AzureRmProfileProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Common.Authentication;
1516
using Microsoft.Azure.Common.Authentication.Models;
1617

1718
namespace Microsoft.WindowsAzure.Commands.Common

src/ResourceManager/Common/Commands.ResourceManager.Common/AzureRMCmdlet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public abstract class AzureRMCmdlet : AzurePSCmdlet
3737
/// </summary>
3838
static AzureRMCmdlet()
3939
{
40-
if (AzureSession.DataStore == null)
40+
if (!TestMockSupport.RunningMocked)
4141
{
4242
AzureSession.DataStore = new DiskDataStore();
43-
}
43+
}
4444
}
4545

4646
public AzureRMCmdlet()

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/ExpressRouteCircuitTests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Test-ExpressRouteCircuitCRUD
3131
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation
3232

3333
# Create the ExpressRouteCircuit
34-
$circuit = New-AzureRmExpressRouteCircuit -Name $circuitName -Location $location -ResourceGroupName $rgname -SkuName "standard_meteredData" -SkuTier Standard -SkuFamily MeteredData -ServiceProviderName "equinix" -PeeringLocation "Silicon Valley" -BandwidthInMbps 1000;
34+
$circuit = New-AzureRmExpressRouteCircuit -Name $circuitName -Location $location -ResourceGroupName $rgname -SkuTier Standard -SkuFamily MeteredData -ServiceProviderName "equinix" -PeeringLocation "Silicon Valley" -BandwidthInMbps 1000;
3535

3636
# get Circuit
3737
$getCircuit = Get-AzureRmExpressRouteCircuit -Name $circuitName -ResourceGroupName $rgname
@@ -42,7 +42,7 @@ function Test-ExpressRouteCircuitCRUD
4242
Assert-NotNull $getCircuit.Location
4343
Assert-NotNull $getCircuit.Etag
4444
Assert-AreEqual 0 @($getCircuit.Peerings).Count
45-
Assert-AreEqual "standard_meteredData" $getCircuit.Sku.Name
45+
Assert-AreEqual "Standard_MeteredData" $getCircuit.Sku.Name
4646
Assert-AreEqual "Standard" $getCircuit.Sku.Tier
4747
Assert-AreEqual "MeteredData" $getCircuit.Sku.Family
4848
Assert-AreEqual "equinix" $getCircuit.ServiceProviderProperties.ServiceProviderName
@@ -108,15 +108,15 @@ function Test-ExpressRouteCircuitPeeringCRUD
108108

109109
# Create the ExpressRouteCircuit with peering
110110
$peering = New-AzureRmExpressRouteCircuitPeeringConfig -Name AzurePrivatePeering -PeeringType AzurePrivatePeering -PeerASN 100 -PrimaryPeerAddressPrefix "192.168.1.0/30" -SecondaryPeerAddressPrefix "192.168.2.0/30" -VlanId 200
111-
$circuit = New-AzureRmExpressRouteCircuit -Name $circuitName -Location $location -ResourceGroupName $rgname -SkuName "standard_meteredData" -SkuTier Standard -SkuFamily MeteredData -ServiceProviderName "equinix" -PeeringLocation "Silicon Valley" -BandwidthInMbps 1000 -Peering $peering
111+
$circuit = New-AzureRmExpressRouteCircuit -Name $circuitName -Location $location -ResourceGroupName $rgname -SkuTier Standard -SkuFamily MeteredData -ServiceProviderName "equinix" -PeeringLocation "Silicon Valley" -BandwidthInMbps 1000 -Peering $peering
112112

113113
#verification
114114
Assert-AreEqual $rgName $circuit.ResourceGroupName
115115
Assert-AreEqual $circuitName $circuit.Name
116116
Assert-NotNull $circuit.Location
117117
Assert-NotNull $circuit.Etag
118118
Assert-AreEqual 1 @($circuit.Peerings).Count
119-
Assert-AreEqual "standard_meteredData" $circuit.Sku.Name
119+
Assert-AreEqual "Standard_MeteredData" $circuit.Sku.Name
120120
Assert-AreEqual "Standard" $circuit.Sku.Tier
121121
Assert-AreEqual "MeteredData" $circuit.Sku.Family
122122
Assert-AreEqual "equinix" $circuit.ServiceProviderProperties.ServiceProviderName

src/ResourceManager/Network/Commands.Network/ExpressRouteCircuit/NewAzureExpressRouteCircuitCommand.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ public class NewAzureExpressRouteCircuitCommand : ExpressRouteCircuitBaseCmdlet
5050
[ValidateNotNullOrEmpty]
5151
public virtual string Location { get; set; }
5252

53-
[Parameter(
54-
Mandatory = false,
55-
ValueFromPipelineByPropertyName = true)]
56-
public string SkuName { get; set; }
57-
5853
[Parameter(
5954
Mandatory = false,
6055
ValueFromPipelineByPropertyName = true)]
@@ -136,12 +131,12 @@ private PSExpressRouteCircuit CreateExpressRouteCircuit()
136131
circuit.Location = this.Location;
137132

138133
// Construct sku
139-
if (!string.IsNullOrEmpty(this.SkuName))
134+
if (!string.IsNullOrEmpty(this.SkuTier))
140135
{
141136
circuit.Sku = new PSExpressRouteCircuitSku();
142-
circuit.Sku.Name = this.SkuName;
143137
circuit.Sku.Tier = this.SkuTier;
144138
circuit.Sku.Family = this.SkuFamily;
139+
circuit.Sku.Name = this.SkuTier + "_" + this.SkuFamily;
145140
}
146141

147142
// construct the service provider properties

src/ResourceManager/Network/Commands.Network/ExpressRouteCircuit/SetAzureExpressRouteCircuitCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ protected override void ProcessRecord()
4141
}
4242

4343
// Map to the sdk object
44-
var vnetModel = Mapper.Map<MNM.ExpressRouteCircuit>(this.ExpressRouteCircuit);
45-
vnetModel.Type = Microsoft.Azure.Commands.Network.Properties.Resources.ExpressRouteCircuitType;
46-
vnetModel.Tags = TagsConversionHelper.CreateTagDictionary(this.ExpressRouteCircuit.Tag, validate: true);
44+
var erModel = Mapper.Map<MNM.ExpressRouteCircuit>(this.ExpressRouteCircuit);
45+
erModel.Type = Microsoft.Azure.Commands.Network.Properties.Resources.ExpressRouteCircuitType;
46+
erModel.Tags = TagsConversionHelper.CreateTagDictionary(this.ExpressRouteCircuit.Tag, validate: true);
4747

4848
// Execute the Create ExpressRouteCircuit call
49-
this.ExpressRouteCircuitClient.CreateOrUpdate(this.ExpressRouteCircuit.ResourceGroupName, this.ExpressRouteCircuit.Name, vnetModel);
49+
this.ExpressRouteCircuitClient.CreateOrUpdate(this.ExpressRouteCircuit.ResourceGroupName, this.ExpressRouteCircuit.Name, erModel);
5050

5151
var getExpressRouteCircuit = this.GetExpressRouteCircuit(this.ExpressRouteCircuit.ResourceGroupName, this.ExpressRouteCircuit.Name);
5252
WriteObject(getExpressRouteCircuit);

src/ResourceManager/Profile/AzureRM.Profile.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RequiredModules = @()
5151
RequiredAssemblies = @()
5252

5353
# Script files (.ps1) that are run in the caller's environment prior to importing this module
54-
ScriptsToProcess = @()
54+
ScriptsToProcess = @('CheckVersions.ps1')
5555

5656
# Type files (.ps1xml) to be loaded when importing this module
5757
TypesToProcess = @()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
$AzureRMModules = @(
2+
"AzureRM.ApiManagement";
3+
"AzureRM.Automation";
4+
"AzureRM.Backup";
5+
"AzureRM.Batch";
6+
"AzureRM.Compute";
7+
"AzureRM.DataFactories";
8+
"AzureRM.Dns";
9+
"AzureRM.HDInsight";
10+
"AzureRM.Insights";
11+
"AzureRM.KeyVault";
12+
"AzureRM.Network";
13+
"AzureRM.OperationalInsights";
14+
"AzureRM.RedisCache";
15+
"AzureRM.Resources";
16+
"AzureRM.SiteRecovery";
17+
"AzureRM.Sql";
18+
"AzureRM.Storage";
19+
"AzureRM.StreamAnalytics";
20+
"AzureRM.Tags";
21+
"AzureRM.TrafficManager";
22+
"AzureRM.UsageAggregates";
23+
"AzureRM.Websites"
24+
)
25+
26+
$global:AvailableModules = @()
27+
28+
function CheckVersions {
29+
$profile = GetModuleInfo("AzureRM.Profile")
30+
if (-not $profile)
31+
{
32+
exit 0
33+
}
34+
ForEach ($moduleName in $AzureRMModules) {
35+
$module = GetModuleInfo($moduleName)
36+
if ($module)
37+
{
38+
$module.RequiredModules | Where-Object {$_.Name -eq "AzureRM.Profile"} | ForEach {
39+
if ($profile.Version.Major -ne $_.Version.Major) {
40+
Write-Warning("$moduleName $($module.Version) is not compatible with $profile $($profile.Version)!")
41+
}
42+
}
43+
}
44+
}
45+
}
46+
47+
function GetModuleInfo {
48+
param(
49+
[Parameter(Position=0)]
50+
[string]
51+
$ModuleName)
52+
53+
if ($global:AvailableModules.Length -eq 0)
54+
{
55+
$global:AvailableModules = Get-Module -ListAvailable
56+
}
57+
58+
return $global:AvailableModules `
59+
| Where-Object { $_.Name -eq $ModuleName} `
60+
| Select-Object -first 1
61+
}
62+
63+
CheckVersions

src/ResourceManager/Profile/Commands.Profile.Test/Commands.Profile.Test.csproj

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
<Compile Include="EnvironmentCmdletTests.cs" />
182182
<Compile Include="MockSubscriptionClientFactory.cs" />
183183
<Compile Include="ProfileController.cs" />
184+
<Compile Include="ProfileModuleTests.cs" />
184185
<Compile Include="RPRegistrationDelegatingHandlerTests.cs" />
185186
<Compile Include="SubscriptionCmdletTests.cs" />
186187
<Compile Include="TenantCmdletTests.cs" />
@@ -196,6 +197,15 @@
196197
</Content>
197198
<None Include="MSSharedLibKey.snk" />
198199
<None Include="packages.config" />
200+
<None Include="FakeModuleRepo\AzureRM.ApiManagement.998.9.8.nupkg">
201+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
202+
</None>
203+
<None Include="FakeModuleRepo\AzureRM.Profile.999.9.8.nupkg">
204+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
205+
</None>
206+
<None Include="SessionRecords\Microsoft.Azure.Commands.Profile.Test.ProfileModuleTests\WarningOnIncompatibleVersions.json">
207+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
208+
</None>
199209
<None Include="SessionRecords\Microsoft.Azure.Commands.Profile.Test.SubscriptionCmdletTests\AllParameterSetsSucceed.json">
200210
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
201211
</None>
@@ -205,6 +215,9 @@
205215
<None Include="SessionRecords\Microsoft.Azure.Commands.Profile.Test.SubscriptionCmdletTests\SetAzureRmContextWorks.json">
206216
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
207217
</None>
218+
<Content Include="ProfileModuleTests.ps1">
219+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
220+
</Content>
208221
</ItemGroup>
209222
<ItemGroup>
210223
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">
@@ -227,4 +240,4 @@
227240
<ItemGroup />
228241
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
229242
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
230-
</Project>
243+
</Project>
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources
15+
using Microsoft.Azure.Commands.Resources.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
19+
namespace Microsoft.Azure.Commands.Profile.Test
1620
{
17-
/// <summary>
18-
/// The resource object format
19-
/// </summary>
20-
public enum ResourceObjectFormat
21+
public class ProfileModuleTests
2122
{
22-
/// <summary>
23-
/// The legacy format.
24-
/// </summary>
25-
Legacy = 0,
26-
27-
/// <summary>
28-
/// The new format.
29-
/// </summary>
30-
New = 1
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
public void WarningOnIncompatibleVersions()
26+
{
27+
ProfileController.NewInstance.RunPsTest("db1ab6f0-4769-4b27-930e-01e2ef9c123c", "Test-LoadProfileModule");
28+
}
3129
}
3230
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
<#
16+
.SYNOPSIS
17+
Tests warning gets printed on incompatible modules with profile
18+
#>
19+
function Test-LoadProfileModule
20+
{
21+
# Push current profile module
22+
Get-PackageProvider -Name NuGet -ForceBootstrap
23+
$global:pushedProfileModule = $(Get-Module AzureRM.Profile).Path
24+
Remove-Module AzureRM.Profile
25+
try {
26+
Register-PSRepository -Name "ProfileModuleTest" -SourceLocation (Resolve-Path .\FakeModuleRepo).Path -InstallationPolicy Trusted
27+
try {
28+
Install-Module AzureRM.ApiManagement -Scope CurrentUser -Repository ProfileModuleTest -RequiredVersion 998.9.8
29+
$global:buffer = Import-Module $global:pushedProfileModule 2>&1 3>&1 | Out-String
30+
Write-Warning $global:buffer
31+
Assert-True { $global:buffer -Like "*AzureRM.ApiManagement 998.9.8 is not compatible with AzureRM.Profile*" }
32+
} catch [system.exception] {
33+
Write-Error $_ -ErrorAction Continue
34+
} finally {
35+
Uninstall-Module AzureRM.ApiManagement -ErrorAction Ignore
36+
Uninstall-Module AzureRM.Profile -ErrorAction Ignore
37+
}
38+
} catch [system.exception] {
39+
Write-Error $_ -ErrorAction Continue
40+
} finally {
41+
Unregister-PSRepository -Name "ProfileModuleTest"
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Entries": [],
3+
"Names": {},
4+
"Variables": {}
5+
}

src/ResourceManager/Profile/Commands.Profile/Account/AddAzureRmAccount.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ public class AddAzureRMAccountCommand : AzureRMCmdlet , IModuleAssemblyInitializ
5555
[ValidateNotNullOrEmpty]
5656
public string AccessToken { get; set; }
5757

58-
[Parameter(Mandatory = false, HelpMessage = "Subscription")]
58+
[Parameter(ParameterSetName = "AccessToken", Mandatory = true, HelpMessage = "Account Id for access token")]
59+
[ValidateNotNullOrEmpty]
60+
public string AccountId { get; set; }
61+
62+
[Parameter(Mandatory = false, HelpMessage = "Subscription Id")]
5963
[ValidateNotNullOrEmpty]
6064
public string SubscriptionId { get; set; }
6165

62-
[Parameter(Mandatory = false, HelpMessage = "Subscription")]
66+
[Parameter(Mandatory = false, HelpMessage = "Subscription name")]
6367
[ValidateNotNullOrEmpty]
6468
public string SubscriptionName { get; set; }
6569

@@ -97,7 +101,14 @@ protected override void ProcessRecord()
97101

98102
if (!string.IsNullOrEmpty(AccessToken))
99103
{
104+
if (string.IsNullOrWhiteSpace(AccountId) )
105+
{
106+
throw new PSInvalidOperationException(Resources.AccountIdRequired);
107+
}
108+
100109
azureAccount.Type = AzureAccount.AccountType.AccessToken;
110+
azureAccount.Id = AccountId;
111+
azureAccount.SetProperty(AzureAccount.Property.AccessToken, AccessToken);
101112
}
102113
else if (ServicePrincipal.IsPresent)
103114
{
@@ -127,7 +138,8 @@ protected override void ProcessRecord()
127138

128139
var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
129140

130-
WriteObject((PSAzureProfile)profileClient.Login(azureAccount, Environment, Tenant, SubscriptionId, SubscriptionName, password));
141+
WriteObject((PSAzureProfile)profileClient.Login(azureAccount, Environment, Tenant, SubscriptionId,
142+
SubscriptionName, password));
131143
}
132144

133145
/// <summary>

src/ResourceManager/Profile/Commands.Profile/Commands.Profile.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<Compile Include="Models\PSAzureSubscription.cs" />
147147
<Compile Include="Models\PSAzureTenant.cs" />
148148
<Compile Include="Models\RMProfileClient.cs" />
149+
<Compile Include="Models\SimpleAccessToken.cs" />
149150
<Compile Include="Subscription\GetAzureRMSubscription.cs" />
150151
<Compile Include="Account\AddAzureRmAccount.cs" />
151152
<Compile Include="Context\GetAzureRMContext.cs" />
@@ -169,6 +170,10 @@
169170
<Link>AzureRM.Profile.psd1</Link>
170171
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
171172
</None>
173+
<None Include="..\CheckVersions.ps1">
174+
<Link>CheckVersions.ps1</Link>
175+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
176+
</None>
172177
<None Include="AzureRmProfileStartup.ps1">
173178
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
174179
</None>

0 commit comments

Comments
 (0)