Skip to content

Commit 94ce335

Browse files
committed
Merge pull request Azure#98 from jasper-schneider/getvmfiles
Download VM files and code reorganization
2 parents bf43293 + de8f587 commit 94ce335

File tree

112 files changed

+4332
-1369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+4332
-1369
lines changed

ChangeLog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Added cmdlets
44
* New-AzureBatchVMUser
55
* Remove-AzureBatchVMUser
6+
* Get-AzureBatchRDPFile
7+
* Get-AzureBatchVMFileContents
68

79
2015.03.31 version 0.8.16
810
* Azure Data Factory:

src/ResourceManager/Batch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,11 @@
154154
<Compile Include="Accounts\RemoveBatchAccountCommandTests.cs" />
155155
<Compile Include="Accounts\SetBatchAccountCommandTests.cs" />
156156
<Compile Include="BatchTestHelpers.cs" />
157+
<Compile Include="Files\GetBatchRDPFileCommandTests.cs" />
157158
<Compile Include="Files\GetBatchTaskFileCommandTests.cs" />
158159
<Compile Include="Files\GetBatchTaskFileContentCommandTests.cs" />
159160
<Compile Include="Files\GetBatchVMFileCommandTests.cs" />
161+
<Compile Include="Files\GetBatchVMFileContentCommandTests.cs" />
160162
<Compile Include="Jobs\GetBatchJobCommandTests.cs" />
161163
<Compile Include="Jobs\RemoveBatchJobCommandTests.cs" />
162164
<Compile Include="Models\BatchAccountContextTest.cs" />
@@ -237,6 +239,12 @@
237239
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.BatchAccountTests\TestUpdatesExistingBatchAccount.json">
238240
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
239241
</None>
242+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetRDPFileByName.json">
243+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
244+
</None>
245+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetRDPFilePipeline.json">
246+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
247+
</None>
240248
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetTaskFileByName.json">
241249
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
242250
</None>
@@ -249,6 +257,12 @@
249257
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetVMFileByName.json">
250258
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
251259
</None>
260+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetVMFileContentByName.json">
261+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
262+
</None>
263+
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestGetVMFileContentPipeline.json">
264+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
265+
</None>
252266
<None Include="SessionRecords\Microsoft.Azure.Commands.Batch.Test.ScenarioTests.FileTests\TestListAllTaskFiles.json">
253267
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
254268
</None>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
using Microsoft.Azure.Batch;
18+
using Microsoft.Azure.Batch.Common;
19+
using Microsoft.Azure.Batch.Protocol;
20+
using Microsoft.Azure.Batch.Protocol.Entities;
21+
using Microsoft.Azure.Commands.Batch.Models;
22+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
23+
using Moq;
24+
using System.Collections.Generic;
25+
using System.Linq;
26+
using System.Management.Automation;
27+
using System.Threading.Tasks;
28+
using Xunit;
29+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
30+
31+
namespace Microsoft.Azure.Commands.Batch.Test.Files
32+
{
33+
public class GetBatchRDPFileCommandTests
34+
{
35+
private GetBatchRDPFileCommand cmdlet;
36+
private Mock<BatchClient> batchClientMock;
37+
private Mock<ICommandRuntime> commandRuntimeMock;
38+
39+
public GetBatchRDPFileCommandTests()
40+
{
41+
batchClientMock = new Mock<BatchClient>();
42+
commandRuntimeMock = new Mock<ICommandRuntime>();
43+
cmdlet = new GetBatchRDPFileCommand()
44+
{
45+
CommandRuntime = commandRuntimeMock.Object,
46+
BatchClient = batchClientMock.Object,
47+
};
48+
}
49+
50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
public void GetBatchRDPFileParametersTest()
53+
{
54+
// Setup cmdlet without required parameters
55+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
56+
cmdlet.BatchContext = context;
57+
cmdlet.PoolName = null;
58+
cmdlet.VMName = null;
59+
cmdlet.VM = null;
60+
cmdlet.DestinationPath = null;
61+
62+
// Don't go to the service on a GetTVMRDPFile call
63+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
64+
{
65+
if (request is GetTVMRDPFileRequest)
66+
{
67+
GetTVMRDPFileResponse response = new GetTVMRDPFileResponse();
68+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
69+
return task;
70+
}
71+
return null;
72+
});
73+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
74+
75+
using (MemoryStream memStream = new MemoryStream())
76+
{
77+
// Don't hit the file system during unit tests
78+
cmdlet.DestinationStream = memStream;
79+
80+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
81+
82+
// Fill required Task file details
83+
cmdlet.PoolName = "pool";
84+
cmdlet.VMName = "vm1";
85+
86+
// Verify no exceptions occur
87+
cmdlet.ExecuteCmdlet();
88+
}
89+
}
90+
}
91+
}

src/ResourceManager/Batch/Commands.Batch.Test/Files/GetBatchTaskFileContentCommandTests.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ public void GetBatchTaskFileParametersTest()
6363

6464
string fileName = "stdout.txt";
6565

66-
// Don't hit the file system during unit tests
67-
cmdlet.Stream = new MemoryStream();
68-
6966
// Don't go to the service on a GetTaskFile call or GetTaskFileProperties call
7067
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
7168
{
@@ -85,23 +82,22 @@ public void GetBatchTaskFileParametersTest()
8582
});
8683
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
8784

88-
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
85+
using (MemoryStream memStream = new MemoryStream())
86+
{
87+
// Don't hit the file system during unit tests
88+
cmdlet.DestinationStream = memStream;
8989

90-
// Fill required Task file details
91-
cmdlet.WorkItemName = "workItem";
92-
cmdlet.JobName = "job-0000000001";
93-
cmdlet.TaskName = "task";
94-
cmdlet.Name = fileName;
90+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
91+
92+
// Fill required Task file details
93+
cmdlet.WorkItemName = "workItem";
94+
cmdlet.JobName = "job-0000000001";
95+
cmdlet.TaskName = "task";
96+
cmdlet.Name = fileName;
9597

96-
try
97-
{
9898
// Verify no exceptions occur
9999
cmdlet.ExecuteCmdlet();
100100
}
101-
finally
102-
{
103-
cmdlet.Stream.Dispose();
104-
}
105101
}
106102
}
107103
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
using Microsoft.Azure.Batch;
18+
using Microsoft.Azure.Batch.Common;
19+
using Microsoft.Azure.Batch.Protocol;
20+
using Microsoft.Azure.Batch.Protocol.Entities;
21+
using Microsoft.Azure.Commands.Batch.Models;
22+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
23+
using Moq;
24+
using System.Collections.Generic;
25+
using System.Linq;
26+
using System.Management.Automation;
27+
using System.Threading.Tasks;
28+
using Xunit;
29+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
30+
31+
namespace Microsoft.Azure.Commands.Batch.Test.Files
32+
{
33+
public class GetBatchVMFileContentCommandTests
34+
{
35+
private GetBatchVMFileContentCommand cmdlet;
36+
private Mock<BatchClient> batchClientMock;
37+
private Mock<ICommandRuntime> commandRuntimeMock;
38+
39+
public GetBatchVMFileContentCommandTests()
40+
{
41+
batchClientMock = new Mock<BatchClient>();
42+
commandRuntimeMock = new Mock<ICommandRuntime>();
43+
cmdlet = new GetBatchVMFileContentCommand()
44+
{
45+
CommandRuntime = commandRuntimeMock.Object,
46+
BatchClient = batchClientMock.Object,
47+
};
48+
}
49+
50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
public void GetBatchVMFileContentParametersTest()
53+
{
54+
// Setup cmdlet without required parameters
55+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
56+
cmdlet.BatchContext = context;
57+
cmdlet.PoolName = null;
58+
cmdlet.VMName = null;
59+
cmdlet.Name = null;
60+
cmdlet.InputObject = null;
61+
cmdlet.DestinationPath = null;
62+
63+
string fileName = "startup\\stdout.txt";
64+
65+
// Don't go to the service on a GetTVMFile call or GetTVMFileProperties call
66+
YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
67+
{
68+
if (request is GetTVMFilePropertiesRequest)
69+
{
70+
GetTVMFilePropertiesResponse response = BatchTestHelpers.CreateGetTVMFilePropertiesResponse(fileName);
71+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
72+
return task;
73+
}
74+
if (request is GetTVMFileRequest)
75+
{
76+
GetTVMFileResponse response = new GetTVMFileResponse();
77+
Task<object> task = Task<object>.Factory.StartNew(() => { return response; });
78+
return task;
79+
}
80+
return null;
81+
});
82+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
83+
84+
using (MemoryStream memStream = new MemoryStream())
85+
{
86+
// Don't hit the file system during unit tests
87+
cmdlet.DestinationStream = memStream;
88+
89+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
90+
91+
// Fill required Task file details
92+
cmdlet.PoolName = "pool";
93+
cmdlet.VMName = "vm1";
94+
cmdlet.Name = fileName;
95+
96+
// Verify no exceptions occur
97+
cmdlet.ExecuteCmdlet();
98+
}
99+
}
100+
}
101+
}

src/ResourceManager/Batch/Commands.Batch.Test/Jobs/RemoveBatchJobCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void RemoveBatchJobParametersTest()
5555
cmdlet.Force = true;
5656
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
5757

58-
Assert.Throws<ArgumentException>(() => cmdlet.ExecuteCmdlet());
58+
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
5959

6060
cmdlet.WorkItemName = "testWorkItem";
6161
cmdlet.Name = "job-0000000001";

src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/FileTests.cs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class FileTests
3939
private const string accountName = "filetests";
4040
private const string poolName = "testPool";
4141
private const string vmName = "tvm-1900272697_1-20150331t200107z"; // Use the following command to get a VM name: (Get-AzureBatchVM -PoolName "testPool" -BatchContext $context)[0].Name
42+
private const string startTaskStdOutName = "startup\\stdout.txt";
43+
private const string startTaskStdOutContent = "hello";
4244

4345
[Fact]
4446
[Trait(Category.AcceptanceType, Category.CheckIn)]
@@ -324,6 +326,38 @@ public void TestListVMFilePipeline()
324326
int count = 3; // shared, startup, workitems
325327
controller.RunPsTest(string.Format("Test-ListVMFilePipeline '{0}' '{1}' '{2}' '{3}'", accountName, poolName, vmName, count));
326328
}
329+
330+
[Fact]
331+
[Trait(Category.AcceptanceType, Category.CheckIn)]
332+
public void TestGetVMFileContentByName()
333+
{
334+
BatchController controller = BatchController.NewInstance;
335+
controller.RunPsTest(string.Format("Test-GetVMFileContentByName '{0}' '{1}' '{2}' '{3}' '{4}'", accountName, poolName, vmName, startTaskStdOutName, startTaskStdOutContent));
336+
}
337+
338+
[Fact]
339+
[Trait(Category.AcceptanceType, Category.CheckIn)]
340+
public void TestGetVMFileContentPipeline()
341+
{
342+
BatchController controller = BatchController.NewInstance;
343+
controller.RunPsTest(string.Format("Test-GetVMFileContentPipeline '{0}' '{1}' '{2}' '{3}' '{4}'", accountName, poolName, vmName, startTaskStdOutName, startTaskStdOutContent));
344+
}
345+
346+
[Fact]
347+
[Trait(Category.AcceptanceType, Category.CheckIn)]
348+
public void TestGetRDPFileByName()
349+
{
350+
BatchController controller = BatchController.NewInstance;
351+
controller.RunPsTest(string.Format("Test-GetRDPFileByName '{0}' '{1}' '{2}'", accountName, poolName, vmName));
352+
}
353+
354+
[Fact]
355+
[Trait(Category.AcceptanceType, Category.CheckIn)]
356+
public void TestGetRDPFilePipeline()
357+
{
358+
BatchController controller = BatchController.NewInstance;
359+
controller.RunPsTest(string.Format("Test-GetRDPFilePipeline '{0}' '{1}' '{2}'", accountName, poolName, vmName));
360+
}
327361
}
328362

329363
// Cmdlets that use the HTTP Recorder interceptor for use with scenario tests
@@ -340,12 +374,8 @@ public override void ExecuteCmdlet()
340374
[Cmdlet(VerbsCommon.Get, "AzureBatchTaskFileContent_ST")]
341375
public class GetBatchTaskFileContentScenarioTestCommand : GetBatchTaskFileContentCommand
342376
{
343-
[Parameter]
344-
public MemoryStream MemStream { get; set; }
345-
346377
public override void ExecuteCmdlet()
347378
{
348-
this.Stream = MemStream;
349379
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
350380
base.ExecuteCmdlet();
351381
}
@@ -360,4 +390,24 @@ public override void ExecuteCmdlet()
360390
base.ExecuteCmdlet();
361391
}
362392
}
393+
394+
[Cmdlet(VerbsCommon.Get, "AzureBatchVMFileContent_ST")]
395+
public class GetBatchVMFileContentScenarioTestCommand : GetBatchVMFileContentCommand
396+
{
397+
public override void ExecuteCmdlet()
398+
{
399+
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
400+
base.ExecuteCmdlet();
401+
}
402+
}
403+
404+
[Cmdlet(VerbsCommon.Get, "AzureBatchRDPFile_ST")]
405+
public class GetBatchRDPFileScenarioTestCommand : GetBatchRDPFileCommand
406+
{
407+
public override void ExecuteCmdlet()
408+
{
409+
AdditionalBehaviors = new List<BatchClientBehavior>() { ScenarioTestHelpers.CreateHttpRecordingInterceptor() };
410+
base.ExecuteCmdlet();
411+
}
412+
}
363413
}

0 commit comments

Comments
 (0)