Skip to content
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
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
@@ -0,0 +1,30 @@
// ----------------------------------------------------------------------------------
//
// 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.Resources.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.Profile.Test
{
public class ProfileModuleTests
{
[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 @@ -169,6 +169,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