Skip to content

Commit 0e64614

Browse files
committed
Merge pull request #37 from hyonholee/dev
Test fixes
2 parents 2d643e9 + 94916b9 commit 0e64614

File tree

19 files changed

+305
-55
lines changed

19 files changed

+305
-55
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,15 @@
264264
<Compile Include="Models\PSVirtualMachineSize.cs" />
265265
<Compile Include="Common\LocationStringExtensions.cs" />
266266
<Compile Include="Models\UploadParameters.cs" />
267+
<Compile Include="Models\VhdDownloadContext.cs" />
268+
<Compile Include="Models\VhdDownloaderModel.cs" />
267269
<Compile Include="Models\VhdUploadContext.cs" />
268270
<Compile Include="Models\VhdUploaderModel.cs" />
269271
<Compile Include="RemoteDesktop\VirtualMachineRemoteDesktopBaseCmdlet.cs" />
270272
<Compile Include="RemoteDesktop\GetAzureRemoteDesktopFileCommand.cs" />
271273
<Compile Include="StorageServices\AddAzureVhdCommand.cs" />
272274
<Compile Include="StorageServices\CloudPageBlobObjectFactory.cs" />
275+
<Compile Include="StorageServices\SaveAzureVhdCommand.cs" />
273276
<Compile Include="StorageServices\StorageCredentialsFactory.cs" />
274277
<Compile Include="Usage\GetAzureVMUsageCommand.cs" />
275278
<Compile Include="Usage\VirtualMachineUsageBaseCmdlet.cs" />

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static class ValidateSetValues
4747
{
4848
public const string ReadOnly = "ReadOnly";
4949
public const string ReadWrite = "ReadWrite";
50+
public const string None = "None";
5051
}
5152

5253
public static class ProfileNouns
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 System;
16+
using System.IO;
17+
18+
namespace Microsoft.Azure.Commands.Compute.Models
19+
{
20+
public class VhdDownloadContext
21+
{
22+
public FileInfo LocalFilePath { get; set; }
23+
public Uri Source { get; set; }
24+
}
25+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.Sync;
16+
using Microsoft.WindowsAzure.Commands.Sync.Download;
17+
using System.IO;
18+
19+
namespace Microsoft.Azure.Commands.Compute.Models
20+
{
21+
public class VhdDownloaderModel
22+
{
23+
public static VhdDownloadContext Download(DownloaderParameters downloadParameters, ComputeClientBaseCmdlet cmdlet)
24+
{
25+
Program.SyncOutput = new PSSyncOutputEvents(cmdlet);
26+
27+
downloadParameters.ProgressDownloadComplete = Program.SyncOutput.ProgressDownloadComplete;
28+
downloadParameters.ProgressDownloadStatus = Program.SyncOutput.ProgressDownloadStatus;
29+
30+
var downloader = new Downloader(downloadParameters);
31+
downloader.Download();
32+
33+
return new VhdDownloadContext
34+
{
35+
LocalFilePath = new FileInfo(downloadParameters.LocalFilePath),
36+
Source = downloadParameters.BlobUri.Uri
37+
};
38+
}
39+
}
40+
}

src/ResourceManager/Compute/Commands.Compute/StorageServices/AddAzureVhdCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public UploadParameters ValidateParameters()
131131
}
132132
}
133133

134-
var storageCredentialsFactory = CreateStorageCredentialsFactory(destinationUri);
134+
var storageCredentialsFactory = CreateStorageCredentialsFactory();
135135

136136
PathIntrinsics currentPath = SessionState.Path;
137137
var filePath = new FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(LocalFilePath.ToString()));
@@ -147,7 +147,7 @@ public UploadParameters ValidateParameters()
147147
return parameters;
148148
}
149149

150-
private StorageCredentialsFactory CreateStorageCredentialsFactory(BlobUri destinationUri)
150+
private StorageCredentialsFactory CreateStorageCredentialsFactory()
151151
{
152152
StorageCredentialsFactory storageCredentialsFactory;
153153

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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.Commands.Compute.Common;
16+
using Microsoft.Azure.Commands.Compute.Models;
17+
using Microsoft.Azure.Common.Authentication;
18+
using Microsoft.Azure.Common.Authentication.Models;
19+
using Microsoft.Azure.Management.Storage;
20+
using Microsoft.WindowsAzure.Commands.Sync.Download;
21+
using System;
22+
using System.IO;
23+
using System.Management.Automation;
24+
25+
namespace Microsoft.Azure.Commands.Compute.StorageServices
26+
{
27+
[Cmdlet(VerbsData.Save, ProfileNouns.Vhd), OutputType(typeof(VhdDownloadContext))]
28+
public class SaveAzureVhdCommand : ComputeClientBaseCmdlet
29+
{
30+
private const int DefaultNumberOfUploaderThreads = 8;
31+
private const string ResourceGroupParameterSet = "ResourceGroupParameterSetName";
32+
private const string StorageKeyParameterSet = "StorageKeyParameterSetName";
33+
34+
[Parameter(
35+
Position = 0,
36+
Mandatory = true,
37+
ParameterSetName = ResourceGroupParameterSet,
38+
ValueFromPipelineByPropertyName = true)]
39+
[ValidateNotNullOrEmpty]
40+
public string ResourceGroupName { get; set; }
41+
42+
[Parameter(
43+
Position = 0,
44+
Mandatory = true,
45+
ParameterSetName = StorageKeyParameterSet,
46+
HelpMessage = "Key of the storage account")]
47+
[ValidateNotNullOrEmpty]
48+
[Alias("sk")]
49+
public string StorageKey
50+
{
51+
get;
52+
set;
53+
}
54+
55+
[Parameter(
56+
Position = 1,
57+
Mandatory = true,
58+
ValueFromPipelineByPropertyName = true,
59+
HelpMessage = "Uri to blob")]
60+
[ValidateNotNullOrEmpty]
61+
[Alias("src")]
62+
public Uri Source
63+
{
64+
get;
65+
set;
66+
}
67+
68+
[Parameter(
69+
Position = 2,
70+
Mandatory = true,
71+
HelpMessage = "Local path of the vhd file")]
72+
[ValidateNotNullOrEmpty]
73+
[Alias("lf")]
74+
public FileInfo LocalFilePath
75+
{
76+
get;
77+
set;
78+
}
79+
80+
private int numberOfThreads = DefaultNumberOfUploaderThreads;
81+
82+
[Parameter(
83+
Position = 3,
84+
Mandatory = false,
85+
HelpMessage = "Number of downloader threads")]
86+
[ValidateNotNullOrEmpty]
87+
[ValidateRange(1, 64)]
88+
[Alias("th")]
89+
public int NumberOfThreads
90+
{
91+
get { return this.numberOfThreads; }
92+
set { this.numberOfThreads = value; }
93+
}
94+
95+
[Parameter(
96+
Position = 4,
97+
Mandatory = false,
98+
HelpMessage = "Delete the local file if already exists")]
99+
[ValidateNotNullOrEmpty]
100+
[Alias("o")]
101+
public SwitchParameter OverWrite
102+
{
103+
get;
104+
set;
105+
}
106+
107+
protected override void ProcessRecord()
108+
{
109+
BlobUri blobUri;
110+
if (!BlobUri.TryParseUri(Source, out blobUri))
111+
{
112+
throw new ArgumentOutOfRangeException("Source", Source.ToString());
113+
}
114+
115+
var storageKey = this.StorageKey;
116+
if (this.StorageKey == null)
117+
{
118+
var storageClient = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(
119+
DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);
120+
121+
122+
var storageService = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, blobUri.StorageAccountName);
123+
if (storageService != null)
124+
{
125+
var storageKeys = storageClient.StorageAccounts.ListKeys(this.ResourceGroupName, storageService.StorageAccount.Name);
126+
storageKey = storageKeys.StorageAccountKeys.Key1;
127+
}
128+
}
129+
130+
var downloaderParameters = new DownloaderParameters
131+
{
132+
BlobUri = blobUri,
133+
LocalFilePath = LocalFilePath.FullName,
134+
ConnectionLimit = NumberOfThreads,
135+
StorageAccountKey = storageKey,
136+
ValidateFreeDiskSpace = true,
137+
OverWrite = OverWrite
138+
};
139+
140+
var vhdDownloadContext = VhdDownloaderModel.Download(downloaderParameters, this);
141+
WriteObject(vhdDownloadContext);
142+
}
143+
}
144+
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class AddAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManage
6060
ValueFromPipelineByPropertyName = true,
6161
HelpMessage = HelpMessages.VMDataDiskCaching)]
6262
[ValidateNotNullOrEmpty]
63-
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite)]
63+
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)]
6464
public string Caching { get; set; }
6565

6666
[Parameter(

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class SetAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManage
6868
ValueFromPipelineByPropertyName = true,
6969
HelpMessage = HelpMessages.VMDataDiskCaching)]
7070
[ValidateNotNullOrEmpty]
71-
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite)]
71+
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)]
7272
public string Caching { get; set; }
7373

7474
[Parameter(

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.
6565
ValueFromPipelineByPropertyName = true,
6666
HelpMessage = HelpMessages.VMOSDiskCaching)]
6767
[ValidateNotNullOrEmpty]
68-
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite)]
68+
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)]
6969
public string Caching { get; set; }
7070

7171
[Alias("SourceImage")]

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using AutoMapper;
1516
using Microsoft.Azure.Commands.Compute.Common;
1617
using Microsoft.Azure.Commands.Compute.Models;
17-
using Microsoft.Azure.Commands.Tags.Model;
1818
using Microsoft.Azure.Management.Compute;
1919
using Microsoft.Azure.Management.Compute.Models;
2020
using System.Collections;
@@ -23,6 +23,7 @@
2323
namespace Microsoft.Azure.Commands.Compute
2424
{
2525
[Cmdlet(VerbsCommon.New, ProfileNouns.VirtualMachine)]
26+
[OutputType(typeof(PSComputeLongRunningOperation))]
2627
public class NewAzureVMCommand : VirtualMachineBaseCmdlet
2728
{
2829
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
@@ -61,7 +62,8 @@ protected override void ProcessRecord()
6162
};
6263

6364
var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, parameters);
64-
WriteObject(op);
65+
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
66+
WriteObject(result);
6567
});
6668
}
6769
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
15+
using AutoMapper;
1616
using Microsoft.Azure.Commands.Compute.Common;
1717
using Microsoft.Azure.Commands.Compute.Models;
1818
using Microsoft.Azure.Management.Compute;
@@ -22,7 +22,8 @@
2222

2323
namespace Microsoft.Azure.Commands.Compute
2424
{
25-
[Cmdlet(VerbsData.Update, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)]
25+
[Cmdlet(VerbsData.Update, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)]
26+
[OutputType(typeof(PSComputeLongRunningOperation))]
2627
public class UpdateAzureVMCommand : VirtualMachineActionBaseCmdlet
2728
{
2829
[Alias("VMProfile")]
@@ -53,7 +54,8 @@ protected override void ProcessRecord()
5354
};
5455

5556
var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, parameters);
56-
WriteObject(op);
57+
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
58+
WriteObject(result);
5759
});
5860
}
5961
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ public void AzureIaaSBVT()
379379
//
380380
// Remove-AzureVM
381381
//
382+
vmPowershellCmdlets.RemoveAzureVM(newAzureVMName, serviceName, false, true);
383+
Assert.AreNotEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName));
384+
382385
vmPowershellCmdlets.RemoveAzureVM(newAzureVMName, serviceName);
383386

384387
RecordTimeTaken(ref prevTime);

0 commit comments

Comments
 (0)