Skip to content

Commit

Permalink
Merge pull request #1 from markcowl/storageversions
Browse files Browse the repository at this point in the history
Add script storage module to remove test setup dependencies on storage cmdlets
  • Loading branch information
blueww committed Apr 20, 2016
2 parents e16b662 + 6ad0a4c commit 53aa8a7
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Storage.ps1">
<Link>ScenarioTests\AzureRM.Storage.ps1</Link>
</None>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ private void RunPowerShellTest(params string[] scripts)
_helper.RMProfileModule,
_helper.RMResourceModule,
_helper.RMStorageDataPlaneModule,
_helper.RMStorageModule,
_helper.GetRMModulePath("AzureRM.ApiManagement.psd1"));
_helper.GetRMModulePath("AzureRM.ApiManagement.psd1"),
"AzureRM.Storage.ps1");

_helper.RunPowerShellTest(scripts);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

function Get-AzureRmStorageAccount
{

[CmdletBinding()]
param(
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
BEGIN {
$context = Get-Context
$client = Get-StorageClient $context
}
PROCESS {
$getTask = $client.StorageAccounts.GetPropertiesAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
$sa = $getTask.Result
$account = Get-StorageAccount $ResourceGroupName $Name
Write-Output $account
}
END {}

}

function New-AzureRmStorageAccount
{
[CmdletBinding()]
param(
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)][alias("StorageAccountName")] $Name,
[string] [Parameter(Position=2, ValueFromPipelineByPropertyName=$true)] $Location,
[string] [Parameter(Position=3, ValueFromPipelineByPropertyName=$true)] $Type)
BEGIN {
$context = Get-Context
$client = Get-StorageClient $context
}
PROCESS {
$createParms = New-Object -Type Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters
$createParms.AccountType = [Microsoft.Azure.Management.Storage.Models.AccountType]::StandardLRS
$createParms.Location = $Location
$getTask = $client.StorageAccounts.CreateAsync($ResourceGroupName, $name, $createParms, [System.Threading.CancellationToken]::None)
$sa = $getTask.Result
}
END {}

}

function Get-AzureRmStorageAccountKey
{
[CmdletBinding()]
param(
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
BEGIN {
$context = Get-Context
$client = Get-StorageClient $context
}
PROCESS {
$getTask = $client.StorageAccounts.ListKeysAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
Write-Output $getTask.Result.StorageAccountKeys
}
END {}
}

function Remove-AzureRmStorageAccount
{

[CmdletBinding()]
param(
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
BEGIN {
$context = Get-Context
$client = Get-StorageClient $context
}
PROCESS {
$getTask = $client.StorageAccounts.DeleteAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
$sa = $getTask.Result
}
END {}

}

function Get-Context
{
[Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext]$context = $null
$profile = [Microsoft.WindowsAzure.Commands.Common.AzureRmProfileProvider]::Instance.Profile
if ($profile -ne $null)
{
$context = $profile.Context
}

return $context
}

function Get-StorageClient
{
param([Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext] $context)
$factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::ClientFactory
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext], [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]
$method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory].GetMethod("CreateClient", $types)
$closedMethod = $method.MakeGenericMethod([Microsoft.Azure.Management.Storage.StorageManagementClient])
$arguments = $context, [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]::ResourceManager
$client = $closedMethod.Invoke($factory, $arguments)
return $client
}

function Get-StorageAccount {
param([string] $resourceGroupName, [string] $name)
$endpoints = New-Object PSObject -Property @{"Blob" = "https://$name.blob.core.windows.net/"}
$sa = New-Object PSObject -Property @{"Name" = $name; "ResourceGroupName" = $resourceGroupName;
"PrimaryEndpoints" = $endpoints
}
return $sa
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
<None Include="Assert.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="AzureRM.Storage.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Common.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@
<Link>ScenarioTests\Assert.ps1</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Storage.ps1">
<Link>ScenarioTests\AzureRM.Storage.ps1</Link>
</None>
<None Include="..\..\Resources\Commands.Resources.Test\ScenarioTests\Common.ps1">
<Link>ScenarioTests\Common.ps1</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public void RunPsTestWorkflow(
helper.RMStorageDataPlaneModule,
helper.RMStorageModule,
helper.GetRMModulePath("AzureRM.Compute.psd1"),
helper.GetRMModulePath("AzureRM.Network.psd1"));
helper.GetRMModulePath("AzureRM.Network.psd1"),
"AzureRM.Storage.ps1");

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ protected void RunPowerShellTest(params string[] scripts)
"ScenarioTests\\" + this.GetType().Name + ".ps1",
helper.RMProfileModule,
helper.RMResourceModule,
helper.RMStorageDataPlaneModule,
helper.RMStorageModule,
helper.RMStorageDataPlaneModule,
helper.GetRMModulePath(@"AzureRM.Insights.psd1"),
helper.GetRMModulePath(@"AzureRM.Sql.psd1"));
helper.GetRMModulePath(@"AzureRM.Sql.psd1"),
"AzureRM.Storage.ps1");
helper.RunPowerShellTest(scripts);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\Common\Commands.ScenarioTests.ResourceManager.Common\AzureRM.Storage.ps1">
<Link>ScenarioTests\AzureRM.Storage.ps1</Link>
</None>
<None Include="MSSharedLibKey.snk" />
<None Include="packages.config">
<SubType>Designer</SubType>
Expand Down Expand Up @@ -304,10 +307,6 @@
<Project>{e1f5201d-6067-430e-b303-4e367652991b}</Project>
<Name>Commands.Resources</Name>
</ProjectReference>
<ProjectReference Include="..\..\Storage\Commands.Management.Storage\Commands.Management.Storage.csproj">
<Project>{a50ab133-5c04-4a17-9054-f8343683ec23}</Project>
<Name>Commands.Management.Storage</Name>
</ProjectReference>
<ProjectReference Include="..\Commands.Websites\Commands.Websites.csproj">
<Project>{80a92297-7c92-456b-8ee7-9fb6ce30149d}</Project>
<Name>Commands.Websites</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public void RunPsTestWorkflow(
"ScenarioTests\\" + callingClassName + ".ps1",
helper.RMProfileModule,
helper.RMStorageDataPlaneModule,
helper.RMStorageModule,
helper.RMResourceModule,
helper.GetRMModulePath(@"AzureRM.WebSites.psd1"));
helper.GetRMModulePath(@"AzureRM.WebSites.psd1"),
"AzureRM.Storage.ps1");

try
{
Expand Down

0 comments on commit 53aa8a7

Please sign in to comment.