Skip to content

Commit a8f3d57

Browse files
hyonholeemarkcowl
authored andcommitted
Update Compute project with storage library reference to 4.1.0-preview (#2615)
1 parent c6e5885 commit a8f3d57

28 files changed

+4740
-95
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 Microsoft.Azure.Management.Storage;
16+
using Microsoft.WindowsAzure.Commands.Common.Storage;
17+
18+
namespace Microsoft.Azure.Commands.Management.Storage.Models
19+
{
20+
public class ARMStorageProvider : IStorageServiceProvider
21+
{
22+
IStorageManagementClient _client;
23+
24+
public ARMStorageProvider(IStorageManagementClient client)
25+
{
26+
_client = client;
27+
}
28+
public IStorageService GetStorageService(string name, string resourceGroupName)
29+
{
30+
var account = _client.StorageAccounts.GetProperties(resourceGroupName, name);
31+
var keys = _client.StorageAccounts.ListKeys(resourceGroupName, name);
32+
return new ARMStorageService(account, keys.Key1,
33+
keys.Key2);
34+
}
35+
}
36+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 Microsoft.WindowsAzure.Commands.Common.Storage;
16+
using System;
17+
using System.Collections.Generic;
18+
19+
namespace Microsoft.Azure.Commands.Management.Storage.Models
20+
{
21+
public class ARMStorageService : IStorageService
22+
{
23+
Azure.Management.Storage.Models.StorageAccount _account;
24+
List<string> _authenticationKeys = new List<string>();
25+
public ARMStorageService(Azure.Management.Storage.Models.StorageAccount account,
26+
params string[] authenticationKeys)
27+
{
28+
_account = account;
29+
foreach (var key in authenticationKeys)
30+
{
31+
_authenticationKeys.Add(key);
32+
}
33+
}
34+
35+
public Uri BlobEndpoint
36+
{
37+
get { return new Uri(_account.PrimaryEndpoints.Blob); }
38+
}
39+
40+
public Uri FileEndpoint
41+
{
42+
get { return new Uri(_account.PrimaryEndpoints.File); }
43+
}
44+
45+
public Uri QueueEndpoint
46+
{
47+
get { return new Uri(_account.PrimaryEndpoints.Queue); }
48+
}
49+
50+
public Uri TableEndpoint
51+
{
52+
get { return new Uri(_account.PrimaryEndpoints.Table); }
53+
}
54+
55+
public string Name
56+
{
57+
get { return _account.Name; }
58+
}
59+
60+
public List<string> AuthenticationKeys
61+
{
62+
get { return _authenticationKeys; }
63+
}
64+
65+
/// <summary>
66+
/// Get the resource group name from a storage account resource Id
67+
/// </summary>
68+
/// <param name="resourceId">The resource Id for the storage account</param>
69+
/// <returns>The resource group containing the storage account</returns>
70+
public static string ParseResourceGroupFromId(string resourceId)
71+
{
72+
if (!string.IsNullOrEmpty(resourceId))
73+
{
74+
string[] tokens = resourceId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
75+
if (tokens == null || tokens.Length < 4)
76+
{
77+
throw new ArgumentOutOfRangeException("resourceId");
78+
}
79+
80+
return tokens[3];
81+
}
82+
83+
return null;
84+
}
85+
86+
}
87+
}

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/AzureRM.Storage.ps1

Lines changed: 89 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ function Get-AzureRmStorageAccount
88
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
99
BEGIN {
1010
$context = Get-Context
11-
$client = Get-StorageClient $context
11+
$client = Get-StorageClient $context
12+
$version = $client.GetType().Assembly.GetName().Version
1213
}
1314
PROCESS {
14-
$getTask = $client.StorageAccounts.GetPropertiesAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
15-
$sa = $getTask.Result
16-
$account = Get-StorageAccount $ResourceGroupName $Name
17-
Write-Output $account
15+
if ($version.Major -gt 3)
16+
{
17+
$getTask = $client.StorageAccounts.GetPropertiesWithHttpMessagesAsync($ResourceGroupName, $name, $null, [System.Threading.CancellationToken]::None)
18+
}
19+
else
20+
{
21+
$getTask = $client.StorageAccounts.GetPropertiesAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
22+
}
23+
$sa = $getTask.Result
24+
$account = Get-StorageAccount $ResourceGroupName $Name
25+
Write-Output $account
1826
}
1927
END {}
2028

@@ -26,11 +34,12 @@ function New-AzureRmStorageAccount
2634
param(
2735
[string] [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] $ResourceGroupName,
2836
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)][alias("StorageAccountName")] $Name,
29-
[string] [Parameter(Position=2, ValueFromPipelineByPropertyName=$true)] $Location,
37+
[string] [Parameter(Position=2, ValueFromPipelineByPropertyName=$true)] $Location,
3038
[string] [Parameter(Position=3, ValueFromPipelineByPropertyName=$true)] $typeString)
3139
BEGIN {
3240
$context = Get-Context
33-
$client = Get-StorageClient $context
41+
$client = Get-StorageClient $context
42+
$version = $client.GetType().Assembly.GetName().Version
3443
}
3544
PROCESS {
3645
$createParms = New-Object -Type Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters
@@ -41,12 +50,19 @@ function New-AzureRmStorageAccount
4150
else
4251
{
4352
$Type = Parse-Type $typeString
44-
}
53+
}
4554

46-
$createParms.AccountType = $Type
47-
$createParms.Location = $Location
48-
$getTask = $client.StorageAccounts.CreateAsync($ResourceGroupName, $name, $createParms, [System.Threading.CancellationToken]::None)
49-
$sa = $getTask.Result
55+
$createParms.AccountType = $Type
56+
$createParms.Location = $Location
57+
if ($version.Major -gt 3)
58+
{
59+
$getTask = $client.StorageAccounts.CreateWithHttpMessagesAsync($ResourceGroupName, $name, $createParms, $null, [System.Threading.CancellationToken]::None)
60+
}
61+
else
62+
{
63+
$getTask = $client.StorageAccounts.CreateAsync($ResourceGroupName, $name, $createParms,[System.Threading.CancellationToken]::None)
64+
}
65+
$sa = $getTask.Result
5066
}
5167
END {}
5268

@@ -63,11 +79,20 @@ function Set-AzureRmStorageAccount
6379
BEGIN {
6480
$context = Get-Context
6581
$client = Get-StorageClient $context
82+
$version = $client.GetType().Assembly.GetName().Version
6683
}
6784
PROCESS {
6885
$createParms = New-Object -Type Microsoft.Azure.Management.Storage.Models.StorageAccountUpdateParameters
6986
$createParms.AccountType = [Microsoft.Azure.Management.Storage.Models.AccountType]::StandardLRS
70-
$getTask = $client.StorageAccounts.UpdateAsync($ResourceGroupName, $Name, $createParms, [System.Threading.CancellationToken]::None)
87+
88+
if ($version.Major -gt 3)
89+
{
90+
$getTask = $client.StorageAccounts.UpdateWithHttpMessagesAsync($ResourceGroupName, $Name, $createParms, $null, [System.Threading.CancellationToken]::None)
91+
}
92+
else
93+
{
94+
$getTask = $client.StorageAccounts.UpdateAsync($ResourceGroupName, $Name, $createParms, [System.Threading.CancellationToken]::None)
95+
}
7196
$sa = $getTask.Result
7297
}
7398
END {}
@@ -82,11 +107,21 @@ function Get-AzureRmStorageAccountKey
82107
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
83108
BEGIN {
84109
$context = Get-Context
85-
$client = Get-StorageClient $context
110+
$client = Get-StorageClient $context
111+
$version = $client.GetType().Assembly.GetName().Version
86112
}
87-
PROCESS {
88-
$getTask = $client.StorageAccounts.ListKeysAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
89-
Write-Output $getTask.Result.StorageAccountKeys
113+
PROCESS {
114+
if ($version.Major -gt 3)
115+
{
116+
$getTask = $client.StorageAccounts.ListKeysWithHttpMessagesAsync($ResourceGroupName, $name, $null, [System.Threading.CancellationToken]::None)
117+
$result = $getTask.GetAwaiter().GetResult()
118+
Write-Output $result.Body
119+
}
120+
else
121+
{
122+
$getTask = $client.StorageAccounts.ListKeysAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
123+
Write-Output $getTask.Result.StorageAccountKeys
124+
}
90125
}
91126
END {}
92127
}
@@ -100,11 +135,19 @@ function Remove-AzureRmStorageAccount
100135
[string] [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] [alias("StorageAccountName")] $Name)
101136
BEGIN {
102137
$context = Get-Context
103-
$client = Get-StorageClient $context
138+
$client = Get-StorageClient $context
139+
$version = $client.GetType().Assembly.GetName().Version
104140
}
105141
PROCESS {
106-
$getTask = $client.StorageAccounts.DeleteAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
107-
$sa = $getTask.Result
142+
if ($version.Major -gt 3)
143+
{
144+
$getTask = $client.StorageAccounts.DeleteWithHttpMessagesAsync($ResourceGroupName, $name, $null, [System.Threading.CancellationToken]::None)
145+
}
146+
else
147+
{
148+
$getTask = $client.StorageAccounts.DeleteAsync($ResourceGroupName, $name, [System.Threading.CancellationToken]::None)
149+
}
150+
$sa = $getTask.Result
108151
}
109152
END {}
110153

@@ -114,12 +157,12 @@ function Get-Context
114157
{
115158
[Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext]$context = $null
116159
$profile = [Microsoft.WindowsAzure.Commands.Common.AzureRmProfileProvider]::Instance.Profile
117-
if ($profile -ne $null)
118-
{
119-
$context = $profile.Context
120-
}
160+
if ($profile -ne $null)
161+
{
162+
$context = $profile.Context
163+
}
121164

122-
return $context
165+
return $context
123166
}
124167

125168
function Parse-Type
@@ -133,20 +176,29 @@ function Get-Context
133176
function Get-StorageClient
134177
{
135178
param([Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext] $context)
136-
$factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::ClientFactory
137-
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext], [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]
138-
$method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory].GetMethod("CreateClient", $types)
139-
$closedMethod = $method.MakeGenericMethod([Microsoft.Azure.Management.Storage.StorageManagementClient])
140-
$arguments = $context, [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]::ResourceManager
141-
$client = $closedMethod.Invoke($factory, $arguments)
142-
return $client
179+
$factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::ClientFactory
180+
[System.Type[]]$types = [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext], [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]
181+
$storageClient = [Microsoft.Azure.Management.Storage.StorageManagementClient]
182+
$storageVersion = [System.Reflection.Assembly]::GetAssembly($storageClient).GetName().Version
183+
if ($storageVersion.Major -gt 3)
184+
{
185+
$method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory].GetMethod("CreateArmClient", $types)
186+
}
187+
else
188+
{
189+
$method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory].GetMethod("CreateClient", $types)
190+
}
191+
$closedMethod = $method.MakeGenericMethod([Microsoft.Azure.Management.Storage.StorageManagementClient])
192+
$arguments = $context, [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment+Endpoint]::ResourceManager
193+
$client = $closedMethod.Invoke($factory, $arguments)
194+
return $client
143195
}
144196

145197
function Get-StorageAccount {
146198
param([string] $resourceGroupName, [string] $name)
147-
$endpoints = New-Object PSObject -Property @{"Blob" = "https://$name.blob.core.windows.net/"}
148-
$sa = New-Object PSObject -Property @{"Name" = $name; "ResourceGroupName" = $resourceGroupName;
149-
"PrimaryEndpoints" = $endpoints
150-
}
199+
$endpoints = New-Object PSObject -Property @{"Blob" = "https://$name.blob.core.windows.net/"}
200+
$sa = New-Object PSObject -Property @{"Name" = $name; "ResourceGroupName" = $resourceGroupName;
201+
"PrimaryEndpoints" = $endpoints
202+
}
151203
return $sa
152-
}
204+
}

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.5.0.1-preview\lib\net45\Microsoft.Azure.Management.Network.dll</HintPath>
7272
<Private>True</Private>
7373
</Reference>
74-
<Reference Include="Microsoft.Azure.Management.Storage, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
74+
<Reference Include="Microsoft.Azure.Management.Storage, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7575
<SpecificVersion>False</SpecificVersion>
76-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.3.0.0\lib\net40\Microsoft.Azure.Management.Storage.dll</HintPath>
76+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.4.1.0-preview\lib\net45\Microsoft.Azure.Management.Storage.dll</HintPath>
7777
</Reference>
7878
<Reference Include="Microsoft.Azure.ResourceManager">
7979
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
@@ -371,6 +371,9 @@
371371
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\TestVirtualMachineCustomScriptExtensionSecureExecution.json">
372372
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
373373
</None>
374+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\TestVirtualMachineCustomScriptExtensionWrongStorage.json">
375+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
376+
</None>
374377
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\TestVirtualMachineExtension.json">
375378
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
376379
</None>

src/ResourceManager/Compute/Commands.Compute.Test/Common/ComputeTestController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private void SetupManagementClients(RestTestFramework.MockContext context)
179179
{
180180
ResourceManagementClient = GetResourceManagementClient();
181181
SubscriptionClient = GetSubscriptionClient();
182-
StorageClient = GetStorageManagementClient();
182+
StorageClient = GetStorageManagementClient(context);
183183
GalleryClient = GetGalleryClient();
184184
//var eventsClient = GetEventsClient();
185185
NetworkManagementClient = this.GetNetworkManagementClientClient(context);
@@ -242,10 +242,10 @@ private SubscriptionClient GetSubscriptionClient()
242242
return TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
243243
}
244244

245-
private StorageManagementClient GetStorageManagementClient()
245+
private StorageManagementClient GetStorageManagementClient(RestTestFramework.MockContext context)
246246
{
247247
return testViaCsm
248-
? TestBase.GetServiceClient<StorageManagementClient>(this.csmTestFactory)
248+
? context.GetServiceClient<StorageManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment())
249249
: TestBase.GetServiceClient<StorageManagementClient>(new RDFETestEnvironmentFactory());
250250
}
251251

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public void TestVirtualMachineCustomScriptExtension()
4545
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineCustomScriptExtension");
4646
}
4747

48+
[Fact]
49+
[Trait(Category.AcceptanceType, Category.CheckIn)]
50+
public void TestVirtualMachineCustomScriptExtensionWrongStorage()
51+
{
52+
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineCustomScriptExtensionWrongStorage");
53+
}
54+
4855
[Fact]
4956
[Trait(Category.AcceptanceType, Category.CheckIn)]
5057
public void TestVirtualMachineCustomScriptExtensionSecureExecution()

0 commit comments

Comments
 (0)