Skip to content

Commit 4fc9070

Browse files
hyonholeeHovsep
authored andcommitted
Add -Redeploy parameter for Restart-AzureVM, add -Validate paramter for migration cmdlets, and add tests. (#2586)
Fix validate migration cmdlets to show the validation result Remove ErrorMessages, ServiceName, OperationDescription paramters from MigrationValidateContext
1 parent 066e454 commit 4fc9070

File tree

9 files changed

+1459
-8
lines changed

9 files changed

+1459
-8
lines changed

src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@
331331
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\TestMigrationAbortAzureVNet.json">
332332
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
333333
</None>
334+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\TestMigrationValidateAzureDeployment.json">
335+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
336+
</None>
334337
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\TestNewAzureVMWithBYOL.json">
335338
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
336339
</None>
@@ -645,4 +648,4 @@
645648
<ItemGroup />
646649
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
647650
<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')" />
648-
</Project>
651+
</Project>

src/ServiceManagement/Common/Commands.ScenarioTest/Resources/ServiceManagement/ServiceManagementTests.ps1

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ function Test-MigrationAbortAzureDeployment
673673
New-AzureQuickVM -Windows -ImageName $imgName -Name $vmName -ServiceName $svcName -AdminUsername "pstestuser" -Password $PLACEHOLDER -WaitForBoot;
674674
Get-AzureVM -ServiceName $svcName -Name $vmName;
675675

676-
Move-AzureService -Validate -ServiceName $svcName -DeploymentName $svcName -CreateNewVirtualNetwork;
676+
$result = Move-AzureService -Validate -ServiceName $svcName -DeploymentName $svcName -CreateNewVirtualNetwork;
677+
Assert-AreEqual "Succeeded" $result.Result;
677678
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName;
678679

679680
Move-AzureService -Prepare -ServiceName $svcName -DeploymentName $svcName -CreateNewVirtualNetwork;
@@ -688,6 +689,33 @@ function Test-MigrationAbortAzureDeployment
688689
Cleanup-CloudService $svcName;
689690
}
690691

692+
<#
693+
.SYNOPSIS
694+
Tests Move-AzureService with Abort
695+
#>
696+
function Test-MigrationValidateAzureDeployment
697+
{
698+
# Setup
699+
$location = Get-DefaultLocation;
700+
$imgName = Get-DefaultImage $location;
701+
702+
$storageName = getAssetName;
703+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location;
704+
Set-CurrentStorageAccountName $storageName;
705+
706+
$vmName = "vm1";
707+
$svcName = Get-CloudServiceName;
708+
709+
# Test
710+
New-AzureService -ServiceName $svcName -Location $location;
711+
New-AzureQuickVM -Windows -ImageName $imgName -Name $vmName -ServiceName $svcName -AdminUsername "pstestuser" -Password $PLACEHOLDER;
712+
Get-AzureVM -ServiceName $svcName -Name $vmName;
713+
714+
$result = Move-AzureService -Validate -ServiceName $svcName -DeploymentName $svcName -CreateNewVirtualNetwork;
715+
Assert-AreNotEqual "Succeeded" $result.Result;
716+
Assert-AreNotEqual 0 $result.ValidationMessages.Count;
717+
}
718+
691719
<#
692720
.SYNOPSIS
693721
Tests Move-AzureVirtualNetwork with Prepare and Commit
@@ -737,7 +765,8 @@ function Test-MigrationAbortAzureVNet
737765
Set-AzureVNetConfig -ConfigurationPath $vnetConfigPath;
738766
Get-AzureVNetSite;
739767

740-
Move-AzureVirtualNetwork -Validate -VirtualNetworkName $vnetName;
768+
$result = Move-AzureVirtualNetwork -Validate -VirtualNetworkName $vnetName;
769+
Assert-AreEqual "Succeeded" $result.Result;
741770
Get-AzureVNetSite;
742771

743772
Move-AzureVirtualNetwork -Prepare -VirtualNetworkName $vnetName;
@@ -783,7 +812,8 @@ function Test-MigrationAbortAzureStorageAccount
783812
Get-AzureStorageAccount -StorageAccountName $storageName;
784813

785814
# Test
786-
Move-AzureStorageAccount -Validate -StorageAccountName $storageName;
815+
$result = Move-AzureStorageAccount -Validate -StorageAccountName $storageName;
816+
Assert-AreEqual "Succeeded" $result.Result;
787817
Get-AzureStorageAccount -StorageAccountName $storageName;
788818

789819
Move-AzureStorageAccount -Prepare -StorageAccountName $storageName;

src/ServiceManagement/Common/Commands.ScenarioTest/ServiceManagement/ScenarioTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ public void TestMigrationAbortAzureDeployment()
160160
this.RunPowerShellTest("Test-MigrationAbortAzureDeployment");
161161
}
162162

163+
[Fact]
164+
[Trait(Category.Service, Category.ServiceManagement)]
165+
[Trait(Category.AcceptanceType, Category.CheckIn)]
166+
[Trait(Category.AcceptanceType, Category.BVT)]
167+
public void TestMigrationValidateAzureDeployment()
168+
{
169+
this.RunPowerShellTest("Test-MigrationValidateAzureDeployment");
170+
}
171+
163172
[Fact]
164173
[Trait(Category.Service, Category.ServiceManagement)]
165174
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ServiceManagement/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests/TestMigrationValidateAzureDeployment.json

Lines changed: 1248 additions & 0 deletions
Large diffs are not rendered by default.

src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
<Compile Include="Model\DeploymentRebootEventContext.cs" />
288288
<Compile Include="Model\InternalLoadBalancerSetting.cs" />
289289
<Compile Include="Model\InternalLoadBalancerContext.cs" />
290+
<Compile Include="Model\MigrationValidateContext.cs" />
290291
<Compile Include="Model\PSStorageService.cs" />
291292
<Compile Include="Model\VirtualMachineImageDiskConfigSet.cs" />
292293
<Compile Include="Model\VirtualMachineImageType.cs" />

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureService.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure;
16+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
1617
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1718
using Microsoft.WindowsAzure.Management.Compute;
1819
using Microsoft.WindowsAzure.Management.Compute.Models;
@@ -247,7 +248,12 @@ protected override void OnProcessRecord()
247248
ExecuteClientActionNewSM(
248249
null,
249250
CommandRuntime.ToString(),
250-
() => this.ComputeClient.Deployments.ValidateMigration(this.ServiceName, DeploymentName, parameter));
251+
() => this.ComputeClient.Deployments.ValidateMigration(this.ServiceName, DeploymentName, parameter),
252+
(operation, service) =>
253+
{
254+
var context = ConvertToContext(operation, service);
255+
return context;
256+
});
251257
}
252258
else
253259
{
@@ -258,5 +264,41 @@ protected override void OnProcessRecord()
258264
}
259265
}
260266
}
267+
268+
private MigrationValidateContext ConvertToContext(
269+
OperationStatusResponse operationResponse, XrpMigrationValidateDeploymentResponse validationResponse)
270+
{
271+
if (operationResponse == null) return null;
272+
273+
var result = new MigrationValidateContext
274+
{
275+
OperationId = operationResponse.Id,
276+
Result = operationResponse.Status.ToString()
277+
};
278+
279+
if (validationResponse == null || validationResponse.ValidateDeploymentMessages == null) return result;
280+
281+
var errorCount = validationResponse.ValidateDeploymentMessages.Count;
282+
283+
if (errorCount > 0)
284+
{
285+
result.ValidationMessages = new ValidationMessage[errorCount];
286+
287+
for (int i = 0; i < errorCount; i++)
288+
{
289+
result.ValidationMessages[i] = new ValidationMessage
290+
{
291+
ResourceName = validationResponse.ValidateDeploymentMessages[i].ResourceName,
292+
ResourceType = validationResponse.ValidateDeploymentMessages[i].ResourceType,
293+
Category = validationResponse.ValidateDeploymentMessages[i].Category,
294+
Message = validationResponse.ValidateDeploymentMessages[i].Message,
295+
VirtualMachineName = validationResponse.ValidateDeploymentMessages[i].VirtualMachineName
296+
};
297+
}
298+
result.Result = "Validation failed. Please see ValidationMessages for details";
299+
}
300+
301+
return result;
302+
}
261303
}
262304
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureStorageAccount.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure;
16+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
1617
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1718
using Microsoft.WindowsAzure.Management.Storage;
19+
using Microsoft.WindowsAzure.Management.Storage.Models;
1820
using System.Management.Automation;
1921

2022
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.StorageServices
@@ -94,7 +96,12 @@ protected override void OnProcessRecord()
9496
ExecuteClientActionNewSM(
9597
null,
9698
CommandRuntime.ToString(),
97-
() => this.StorageClient.StorageAccounts.ValidateMigration(this.StorageAccountName));
99+
() => this.StorageClient.StorageAccounts.ValidateMigration(this.StorageAccountName),
100+
(operation, service) =>
101+
{
102+
var context = ConvertToContext(operation, service);
103+
return context;
104+
});
98105
}
99106
else if (this.Abort.IsPresent)
100107
{
@@ -118,5 +125,41 @@ protected override void OnProcessRecord()
118125
() => this.StorageClient.StorageAccounts.PrepareMigration(this.StorageAccountName));
119126
}
120127
}
128+
129+
private MigrationValidateContext ConvertToContext(
130+
OperationStatusResponse operationResponse, XrpMigrationValidateStorageResponse validationResponse)
131+
{
132+
if (operationResponse == null) return null;
133+
134+
var result = new MigrationValidateContext
135+
{
136+
OperationId = operationResponse.Id,
137+
Result = operationResponse.Status.ToString()
138+
};
139+
140+
if (validationResponse == null || validationResponse.ValidateStorageMessages == null) return result;
141+
142+
var errorCount = validationResponse.ValidateStorageMessages.Count;
143+
144+
if (errorCount > 0)
145+
{
146+
result.ValidationMessages = new ValidationMessage[errorCount];
147+
148+
for (int i = 0; i < errorCount; i++)
149+
{
150+
result.ValidationMessages[i] = new ValidationMessage
151+
{
152+
ResourceName = validationResponse.ValidateStorageMessages[i].ResourceName,
153+
ResourceType = validationResponse.ValidateStorageMessages[i].ResourceType,
154+
Category = validationResponse.ValidateStorageMessages[i].Category,
155+
Message = validationResponse.ValidateStorageMessages[i].Message,
156+
VirtualMachineName = validationResponse.ValidateStorageMessages[i].VirtualMachineName
157+
};
158+
}
159+
result.Result = "Validation failed. Please see ValidationMessages for details";
160+
}
161+
162+
return result;
163+
}
121164
}
122165
}

src/ServiceManagement/Compute/Commands.ServiceManagement/Migration/MoveAzureVirtualNetwork.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure;
16+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
1617
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1718
using Microsoft.WindowsAzure.Management.Network;
19+
using Microsoft.WindowsAzure.Management.Network.Models;
1820
using System.Management.Automation;
1921

2022
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Network
@@ -94,7 +96,12 @@ protected override void OnProcessRecord()
9496
ExecuteClientActionNewSM(
9597
null,
9698
CommandRuntime.ToString(),
97-
() => this.NetworkClient.Networks.ValidateMigration(this.VirtualNetworkName));
99+
() => this.NetworkClient.Networks.ValidateMigration(this.VirtualNetworkName),
100+
(operation, service) =>
101+
{
102+
var context = ConvertToContext(operation, service);
103+
return context;
104+
});
98105
}
99106
else if (this.Abort.IsPresent)
100107
{
@@ -118,5 +125,41 @@ protected override void OnProcessRecord()
118125
() => this.NetworkClient.Networks.PrepareMigration(this.VirtualNetworkName));
119126
}
120127
}
128+
129+
private MigrationValidateContext ConvertToContext(
130+
OperationStatusResponse operationResponse, XrpMigrationValidateVirtualNetworkResponse validationResponse)
131+
{
132+
if (operationResponse == null) return null;
133+
134+
var result = new MigrationValidateContext
135+
{
136+
OperationId = operationResponse.Id,
137+
Result = operationResponse.Status.ToString()
138+
};
139+
140+
if (validationResponse == null || validationResponse.ValidateVirtualNetworkMessages == null) return result;
141+
142+
var errorCount = validationResponse.ValidateVirtualNetworkMessages.Count;
143+
144+
if (errorCount > 0)
145+
{
146+
result.ValidationMessages = new ValidationMessage[errorCount];
147+
148+
for (int i = 0; i < errorCount; i++)
149+
{
150+
result.ValidationMessages[i] = new ValidationMessage
151+
{
152+
ResourceName = validationResponse.ValidateVirtualNetworkMessages[i].ResourceName,
153+
ResourceType = validationResponse.ValidateVirtualNetworkMessages[i].ResourceType,
154+
Category = validationResponse.ValidateVirtualNetworkMessages[i].Category,
155+
Message = validationResponse.ValidateVirtualNetworkMessages[i].Message,
156+
VirtualMachineName = validationResponse.ValidateVirtualNetworkMessages[i].VirtualMachineName
157+
};
158+
}
159+
result.Result = "Validation failed. Please see ValidationMessages for details";
160+
}
161+
162+
return result;
163+
}
121164
}
122-
}
165+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Model
16+
{
17+
public class MigrationValidateContext
18+
{
19+
public ValidationMessage [] ValidationMessages { get; set; }
20+
public string OperationId { get; set; }
21+
public string Result { get; set; }
22+
}
23+
24+
public class ValidationMessage
25+
{
26+
public string ResourceType { get; set; }
27+
public string ResourceName { get; set; }
28+
public string Category { get; set; }
29+
public string Message { get; set; }
30+
public string VirtualMachineName { get; set; }
31+
}
32+
}

0 commit comments

Comments
 (0)