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

Dev #145

Merged
merged 28 commits into from
Oct 7, 2015
Merged

Dev #145

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ddd00c4
[fixes #103630362] Add version check scripts to Profile module
jianghaolu Sep 29, 2015
59172d7
Add tests on Profile module version check
jianghaolu Sep 29, 2015
83d33b1
Fix test on checking profile versions
jianghaolu Oct 2, 2015
81dbb31
Add dummy session record
jianghaolu Oct 5, 2015
5d59732
Save all
jianghaolu Oct 5, 2015
cb0fd30
Update help file for AzureRmResourceGroup operations
Oct 6, 2015
392af20
Print inner exceptions for profile module test
jianghaolu Oct 6, 2015
409e636
Merge branch 'dev' of github.com:Azure/azure-powershell into script
jianghaolu Oct 6, 2015
710ff46
Add nuget bootstrap to profile module test
jianghaolu Oct 6, 2015
eaa365a
Misc. fixes for install and uninstall
stankovski Oct 7, 2015
f0d05ba
Remove legacy object format from resource cmdlets
vivsriaus Oct 7, 2015
19bcef2
Merge branch 'dev' of https://github.com/Azure/azure-powershell into …
Oct 7, 2015
ffaf229
Changed install to be single-threaded
stankovski Oct 7, 2015
4909ad0
Merge pull request #1074 from stankovski/dev
Oct 7, 2015
f2f9f61
Merge pull request #143 from Azure/dev
huangpf Oct 7, 2015
1926b62
Fix login issues, serialization issues with profile, and issues with …
markcowl Oct 7, 2015
7e23309
removing unintended change to azure account
markcowl Oct 7, 2015
aa01623
remove SkuName parameter from the ExpressRouteCmdlet, fix test
deepakswifty Oct 7, 2015
2321bdb
Comments and class resources cleanup
markcowl Oct 7, 2015
cef5395
Merge pull request #1002 from jianghaolu/script
Oct 7, 2015
1c7b941
Merge pull request #1067 from chidmdxx/AddParametersToHelp
Oct 7, 2015
80e9e91
Merge pull request #1075 from vivsriaus/RemoveLegacyObject
Oct 7, 2015
4e7a1f8
Responding to review feedback
markcowl Oct 7, 2015
5ce4649
Merge pull request #1077 from DeepakRajendranMsft/SkUBugER
ogail Oct 7, 2015
1f870bf
Merge pull request #1078 from markcowl/loginfix
markcowl Oct 7, 2015
bfc1a5e
Added uninstall for AzureRM from MSI
stankovski Oct 7, 2015
5c624bc
Merge pull request #1080 from stankovski/dev
markcowl Oct 7, 2015
3b08900
Merge pull request #144 from Azure/dev
huangpf Oct 7, 2015
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
16 changes: 13 additions & 3 deletions setup-powershellget/Setup/ShortcutStartup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ This may take some time...
$DefaultPSRepository = "PSGallery"
}

Install-Module AzureRM -Repository $DefaultPSRepository
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."
$_InstallationPolicy = (Get-PSRepository -Name $DefaultPSRepository).InstallationPolicy
try
{
Set-PSRepository -Name $DefaultPSRepository -InstallationPolicy Trusted

Install-Module AzureRM -Repository $DefaultPSRepository
Write-Output "AzureRM $((Get-InstalledModule -Name AzureRM)[0].Version) installed..."

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

Uninstall-AzureRM
Uninstall-Module -Name AzureRM -Confirm:$false -Force
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/Common/Commands.Common/AzureRmProfileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;

namespace Microsoft.WindowsAzure.Commands.Common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public abstract class AzureRMCmdlet : AzurePSCmdlet
/// </summary>
static AzureRMCmdlet()
{
if (AzureSession.DataStore == null)
if (!TestMockSupport.RunningMocked)
{
AzureSession.DataStore = new DiskDataStore();
}
}
}

public AzureRMCmdlet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Test-ExpressRouteCircuitCRUD
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $rglocation

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

# get Circuit
$getCircuit = Get-AzureRmExpressRouteCircuit -Name $circuitName -ResourceGroupName $rgname
Expand All @@ -42,7 +42,7 @@ function Test-ExpressRouteCircuitCRUD
Assert-NotNull $getCircuit.Location
Assert-NotNull $getCircuit.Etag
Assert-AreEqual 0 @($getCircuit.Peerings).Count
Assert-AreEqual "standard_meteredData" $getCircuit.Sku.Name
Assert-AreEqual "Standard_MeteredData" $getCircuit.Sku.Name
Assert-AreEqual "Standard" $getCircuit.Sku.Tier
Assert-AreEqual "MeteredData" $getCircuit.Sku.Family
Assert-AreEqual "equinix" $getCircuit.ServiceProviderProperties.ServiceProviderName
Expand Down Expand Up @@ -108,15 +108,15 @@ function Test-ExpressRouteCircuitPeeringCRUD

# Create the ExpressRouteCircuit with peering
$peering = New-AzureRmExpressRouteCircuitPeeringConfig -Name AzurePrivatePeering -PeeringType AzurePrivatePeering -PeerASN 100 -PrimaryPeerAddressPrefix "192.168.1.0/30" -SecondaryPeerAddressPrefix "192.168.2.0/30" -VlanId 200
$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
$circuit = New-AzureRmExpressRouteCircuit -Name $circuitName -Location $location -ResourceGroupName $rgname -SkuTier Standard -SkuFamily MeteredData -ServiceProviderName "equinix" -PeeringLocation "Silicon Valley" -BandwidthInMbps 1000 -Peering $peering

#verification
Assert-AreEqual $rgName $circuit.ResourceGroupName
Assert-AreEqual $circuitName $circuit.Name
Assert-NotNull $circuit.Location
Assert-NotNull $circuit.Etag
Assert-AreEqual 1 @($circuit.Peerings).Count
Assert-AreEqual "standard_meteredData" $circuit.Sku.Name
Assert-AreEqual "Standard_MeteredData" $circuit.Sku.Name
Assert-AreEqual "Standard" $circuit.Sku.Tier
Assert-AreEqual "MeteredData" $circuit.Sku.Family
Assert-AreEqual "equinix" $circuit.ServiceProviderProperties.ServiceProviderName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public class NewAzureExpressRouteCircuitCommand : ExpressRouteCircuitBaseCmdlet
[ValidateNotNullOrEmpty]
public virtual string Location { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
public string SkuName { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
Expand Down Expand Up @@ -136,12 +131,12 @@ private PSExpressRouteCircuit CreateExpressRouteCircuit()
circuit.Location = this.Location;

// Construct sku
if (!string.IsNullOrEmpty(this.SkuName))
if (!string.IsNullOrEmpty(this.SkuTier))
{
circuit.Sku = new PSExpressRouteCircuitSku();
circuit.Sku.Name = this.SkuName;
circuit.Sku.Tier = this.SkuTier;
circuit.Sku.Family = this.SkuFamily;
circuit.Sku.Name = this.SkuTier + "_" + this.SkuFamily;
}

// construct the service provider properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ protected override void ProcessRecord()
}

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

// Execute the Create ExpressRouteCircuit call
this.ExpressRouteCircuitClient.CreateOrUpdate(this.ExpressRouteCircuit.ResourceGroupName, this.ExpressRouteCircuit.Name, vnetModel);
this.ExpressRouteCircuitClient.CreateOrUpdate(this.ExpressRouteCircuit.ResourceGroupName, this.ExpressRouteCircuit.Name, erModel);

var getExpressRouteCircuit = this.GetExpressRouteCircuit(this.ExpressRouteCircuit.ResourceGroupName, this.ExpressRouteCircuit.Name);
WriteObject(getExpressRouteCircuit);
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceManager/Profile/AzureRM.Profile.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RequiredModules = @()
RequiredAssemblies = @()

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

# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()
Expand Down
63 changes: 63 additions & 0 deletions src/ResourceManager/Profile/CheckVersions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
$AzureRMModules = @(
"AzureRM.ApiManagement";
"AzureRM.Automation";
"AzureRM.Backup";
"AzureRM.Batch";
"AzureRM.Compute";
"AzureRM.DataFactories";
"AzureRM.Dns";
"AzureRM.HDInsight";
"AzureRM.Insights";
"AzureRM.KeyVault";
"AzureRM.Network";
"AzureRM.OperationalInsights";
"AzureRM.RedisCache";
"AzureRM.Resources";
"AzureRM.SiteRecovery";
"AzureRM.Sql";
"AzureRM.Storage";
"AzureRM.StreamAnalytics";
"AzureRM.Tags";
"AzureRM.TrafficManager";
"AzureRM.UsageAggregates";
"AzureRM.Websites"
)

$global:AvailableModules = @()

function CheckVersions {
$profile = GetModuleInfo("AzureRM.Profile")
if (-not $profile)
{
exit 0
}
ForEach ($moduleName in $AzureRMModules) {
$module = GetModuleInfo($moduleName)
if ($module)
{
$module.RequiredModules | Where-Object {$_.Name -eq "AzureRM.Profile"} | ForEach {
if ($profile.Version.Major -ne $_.Version.Major) {
Write-Warning("$moduleName $($module.Version) is not compatible with $profile $($profile.Version)!")
}
}
}
}
}

function GetModuleInfo {
param(
[Parameter(Position=0)]
[string]
$ModuleName)

if ($global:AvailableModules.Length -eq 0)
{
$global:AvailableModules = Get-Module -ListAvailable
}

return $global:AvailableModules `
| Where-Object { $_.Name -eq $ModuleName} `
| Select-Object -first 1
}

CheckVersions
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
<Compile Include="EnvironmentCmdletTests.cs" />
<Compile Include="MockSubscriptionClientFactory.cs" />
<Compile Include="ProfileController.cs" />
<Compile Include="ProfileModuleTests.cs" />
<Compile Include="RPRegistrationDelegatingHandlerTests.cs" />
<Compile Include="SubscriptionCmdletTests.cs" />
<Compile Include="TenantCmdletTests.cs" />
Expand All @@ -196,6 +197,15 @@
</Content>
<None Include="MSSharedLibKey.snk" />
<None Include="packages.config" />
<None Include="FakeModuleRepo\AzureRM.ApiManagement.998.9.8.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="FakeModuleRepo\AzureRM.Profile.999.9.8.nupkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Profile.Test.ProfileModuleTests\WarningOnIncompatibleVersions.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Profile.Test.SubscriptionCmdletTests\AllParameterSetsSucceed.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -205,6 +215,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Profile.Test.SubscriptionCmdletTests\SetAzureRmContextWorks.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="ProfileModuleTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">
Expand All @@ -227,4 +240,4 @@
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<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')" />
</Project>
</Project>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources
using Microsoft.Azure.Commands.Resources.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.Profile.Test
{
/// <summary>
/// The resource object format
/// </summary>
public enum ResourceObjectFormat
public class ProfileModuleTests
{
/// <summary>
/// The legacy format.
/// </summary>
Legacy = 0,

/// <summary>
/// The new format.
/// </summary>
New = 1
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void WarningOnIncompatibleVersions()
{
ProfileController.NewInstance.RunPsTest("db1ab6f0-4769-4b27-930e-01e2ef9c123c", "Test-LoadProfileModule");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ----------------------------------------------------------------------------------
#
# 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 warning gets printed on incompatible modules with profile
#>
function Test-LoadProfileModule
{
# Push current profile module
Get-PackageProvider -Name NuGet -ForceBootstrap
$global:pushedProfileModule = $(Get-Module AzureRM.Profile).Path
Remove-Module AzureRM.Profile
try {
Register-PSRepository -Name "ProfileModuleTest" -SourceLocation (Resolve-Path .\FakeModuleRepo).Path -InstallationPolicy Trusted
try {
Install-Module AzureRM.ApiManagement -Scope CurrentUser -Repository ProfileModuleTest -RequiredVersion 998.9.8
$global:buffer = Import-Module $global:pushedProfileModule 2>&1 3>&1 | Out-String
Write-Warning $global:buffer
Assert-True { $global:buffer -Like "*AzureRM.ApiManagement 998.9.8 is not compatible with AzureRM.Profile*" }
} catch [system.exception] {
Write-Error $_ -ErrorAction Continue
} finally {
Uninstall-Module AzureRM.ApiManagement -ErrorAction Ignore
Uninstall-Module AzureRM.Profile -ErrorAction Ignore
}
} catch [system.exception] {
Write-Error $_ -ErrorAction Continue
} finally {
Unregister-PSRepository -Name "ProfileModuleTest"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Entries": [],
"Names": {},
"Variables": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ public class AddAzureRMAccountCommand : AzureRMCmdlet , IModuleAssemblyInitializ
[ValidateNotNullOrEmpty]
public string AccessToken { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Subscription")]
[Parameter(ParameterSetName = "AccessToken", Mandatory = true, HelpMessage = "Account Id for access token")]
[ValidateNotNullOrEmpty]
public string AccountId { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Subscription Id")]
[ValidateNotNullOrEmpty]
public string SubscriptionId { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Subscription")]
[Parameter(Mandatory = false, HelpMessage = "Subscription name")]
[ValidateNotNullOrEmpty]
public string SubscriptionName { get; set; }

Expand Down Expand Up @@ -97,7 +101,14 @@ protected override void ProcessRecord()

if (!string.IsNullOrEmpty(AccessToken))
{
if (string.IsNullOrWhiteSpace(AccountId) )
{
throw new PSInvalidOperationException(Resources.AccountIdRequired);
}

azureAccount.Type = AzureAccount.AccountType.AccessToken;
azureAccount.Id = AccountId;
azureAccount.SetProperty(AzureAccount.Property.AccessToken, AccessToken);
}
else if (ServicePrincipal.IsPresent)
{
Expand Down Expand Up @@ -127,7 +138,8 @@ protected override void ProcessRecord()

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

WriteObject((PSAzureProfile)profileClient.Login(azureAccount, Environment, Tenant, SubscriptionId, SubscriptionName, password));
WriteObject((PSAzureProfile)profileClient.Login(azureAccount, Environment, Tenant, SubscriptionId,
SubscriptionName, password));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<Compile Include="Models\PSAzureSubscription.cs" />
<Compile Include="Models\PSAzureTenant.cs" />
<Compile Include="Models\RMProfileClient.cs" />
<Compile Include="Models\SimpleAccessToken.cs" />
<Compile Include="Subscription\GetAzureRMSubscription.cs" />
<Compile Include="Account\AddAzureRmAccount.cs" />
<Compile Include="Context\GetAzureRMContext.cs" />
Expand All @@ -169,6 +170,10 @@
<Link>AzureRM.Profile.psd1</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\CheckVersions.ps1">
<Link>CheckVersions.ps1</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="AzureRmProfileStartup.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Loading