Skip to content

Commit 480d0da

Browse files
committed
Merge pull request #466 from huangpf/dev
AzureRT - Fix Problem of Adding Extension while using New/Set-AzureDeployment
2 parents cda75df + 6483748 commit 480d0da

20 files changed

+146
-52
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Test-AvailabilitySet
2525
{
2626
# Common
2727
$loc = 'West US';
28-
New-AzureResourceGroup -Name $rgname -Location $loc;
28+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
2929

3030
$asetName = 'avs' + $rgname;
3131
$nonDefaultUD = 2;

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest1.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function ps_vm_dynamic_test_func_1_pstestrg1016
132132
$st = Write-Verbose "Running Test ps_vm_dynamic_test_func_1_pstestrg1016 - Start ${rgname}, ${loc} & ${vmsize}";
133133

134134
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_pstestrg1016 - Creating Resource Group';
135-
$st = New-AzureResourceGroup -Location $loc -Name $rgname;
135+
$st = New-AzureResourceGroup -Location $loc -Name $rgname -Force;
136136

137137
$vmconfig = create_and_setup_vm_config_object $loc $rgname $vmsize;
138138

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest2.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function ps_vm_dynamic_test_func_2_pstestrg4940
132132
$st = Write-Verbose "Running Test ps_vm_dynamic_test_func_2_pstestrg4940 - Start ${rgname}, ${loc} & ${vmsize}";
133133

134134
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_2_pstestrg4940 - Creating Resource Group';
135-
$st = New-AzureResourceGroup -Location $loc -Name $rgname;
135+
$st = New-AzureResourceGroup -Location $loc -Name $rgname -Force;
136136

137137
$vmconfig = create_and_setup_vm_config_object $loc $rgname $vmsize;
138138

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest3.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function ps_vm_dynamic_test_func_3_pstestrg575
132132
$st = Write-Verbose "Running Test ps_vm_dynamic_test_func_3_pstestrg575 - Start ${rgname}, ${loc} & ${vmsize}";
133133

134134
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_3_pstestrg575 - Creating Resource Group';
135-
$st = New-AzureResourceGroup -Location $loc -Name $rgname;
135+
$st = New-AzureResourceGroup -Location $loc -Name $rgname -Force;
136136

137137
$vmconfig = create_and_setup_vm_config_object $loc $rgname $vmsize;
138138

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VMDynamicTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ function ${generated_func_name}
335335
`$st = Write-Verbose `"Running Test ${generated_func_name} - Start `${rgname}, `${loc} & `${vmsize}`";
336336
337337
`$st = Write-Verbose 'Running Test ${generated_func_name} - Creating Resource Group';
338-
`$st = New-AzureResourceGroup -Location `$loc -Name `$rgname;
338+
`$st = New-AzureResourceGroup -Location `$loc -Name `$rgname -Force;
339339
340340
`$vmconfig = create_and_setup_vm_config_object `$loc `$rgname `$vmsize;
341341

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Test-VirtualMachineExtension
2626
{
2727
# Common
2828
$loc = 'westus';
29-
New-AzureResourceGroup -Name $rgname -Location $loc;
29+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
3030

3131
# VM Profile & Hardware
3232
$vmsize = 'Standard_A2';
@@ -203,7 +203,7 @@ function Test-VirtualMachineCustomScriptExtension
203203
{
204204
# Common
205205
$loc = 'westus';
206-
New-AzureResourceGroup -Name $rgname -Location $loc;
206+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
207207

208208
# VM Profile & Hardware
209209
$vmsize = 'Standard_A4';
@@ -359,7 +359,7 @@ function Test-VirtualMachineAccessExtension
359359
{
360360
# Common
361361
$loc = 'westus';
362-
New-AzureResourceGroup -Name $rgname -Location $loc;
362+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
363363

364364
# VM Profile & Hardware
365365
$vmsize = 'Standard_A4';

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineNetworkInterfaceTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Test-SingleNetworkInterface
2525
{
2626
# Common
2727
$loc = 'westus';
28-
New-AzureResourceGroup -Name $rgname -Location $loc;
28+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
2929

3030
# VM Profile & Hardware
3131
$vmsize = 'Standard_A2';
@@ -148,7 +148,7 @@ function Test-SingleNetworkInterfaceDnsSettings
148148
{
149149
# Common
150150
$loc = 'westus';
151-
New-AzureResourceGroup -Name $rgname -Location $loc;
151+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
152152

153153
# VM Profile & Hardware
154154
$vmsize = 'Standard_A2';
@@ -255,7 +255,7 @@ function Test-MultipleNetworkInterface
255255
{
256256
# Common
257257
$loc = 'westus';
258-
New-AzureResourceGroup -Name $rgname -Location $loc;
258+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
259259

260260
# VM Profile & Hardware
261261
$vmsize = 'Standard_A4';

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Test-VirtualMachine
2525
{
2626
# Common
2727
$loc = 'westus';
28-
New-AzureResourceGroup -Name $rgname -Location $loc;
28+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
2929

3030
# VM Profile & Hardware
3131
$vmsize = 'Standard_A4';
@@ -373,7 +373,7 @@ function Test-VirtualMachineSizeAndUsage
373373
{
374374
# Common
375375
$loc = 'westus';
376-
New-AzureResourceGroup -Name $rgname -Location $loc;
376+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
377377

378378
# Availability Set
379379
$asetName = 'aset' + $rgname;
@@ -544,7 +544,7 @@ function Test-VirtualMachinePIRv2
544544
{
545545
# Common
546546
$loc = 'westus';
547-
New-AzureResourceGroup -Name $rgname -Location $loc;
547+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
548548

549549
# VM Profile & Hardware
550550
$vmsize = 'Standard_A4';
@@ -654,7 +654,7 @@ function Test-VirtualMachineCapture
654654
{
655655
# Common
656656
$loc = 'westus';
657-
New-AzureResourceGroup -Name $rgname -Location $loc;
657+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
658658

659659
# VM Profile & Hardware
660660
$vmsize = 'Standard_A4';
@@ -770,7 +770,7 @@ function Test-VirtualMachineDataDisk
770770
{
771771
# Common
772772
$loc = 'westus';
773-
New-AzureResourceGroup -Name $rgname -Location $loc;
773+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
774774

775775
# VM Profile & Hardware
776776
$vmsize = 'Standard_A0';
@@ -851,7 +851,7 @@ function Test-VirtualMachinePlan
851851
{
852852
# Common
853853
$loc = 'westus';
854-
New-AzureResourceGroup -Name $rgname -Location $loc;
854+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
855855

856856
# VM Profile & Hardware
857857
$vmsize = 'Standard_A0';
@@ -935,7 +935,7 @@ function Test-VirtualMachinePlan2
935935
{
936936
# Common
937937
$loc = 'westus';
938-
New-AzureResourceGroup -Name $rgname -Location $loc;
938+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
939939

940940
# VM Profile & Hardware
941941
$vmsize = 'Standard_A0';
@@ -1021,7 +1021,7 @@ function Test-VirtualMachineTags
10211021
{
10221022
# Common
10231023
$loc = 'westus';
1024-
New-AzureResourceGroup -Name $rgname -Location $loc;
1024+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
10251025

10261026
# VM Profile & Hardware
10271027
$vmsize = 'Standard_A0';
@@ -1096,7 +1096,7 @@ function Test-VirtualMachineWithVMAgentAutoUpdate
10961096
{
10971097
# Common
10981098
$loc = 'westus';
1099-
New-AzureResourceGroup -Name $rgname -Location $loc;
1099+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
11001100

11011101
# VM Profile & Hardware
11021102
$vmsize = 'Standard_A4';
@@ -1190,7 +1190,7 @@ function Test-LinuxVirtualMachine
11901190
{
11911191
# Common
11921192
$loc = 'westus';
1193-
New-AzureResourceGroup -Name $rgname -Location $loc;
1193+
New-AzureResourceGroup -Name $rgname -Location $loc -Force;
11941194

11951195
# VM Profile & Hardware
11961196
$vmsize = 'Standard_A4';

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

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,23 +539,29 @@ public void AzureDeploymentTest()
539539
Assert.IsTrue(File.Exists(configPath3.FullName), "file not exist={0}", configPath3);
540540

541541
string deploymentName = "deployment1";
542+
string deploymentName2 = "deployment2";
542543
string deploymentLabel = "label1";
543544
DeploymentInfoContext result;
544545

546+
PSCredential cred = new PSCredential(username, Utilities.convertToSecureString(password));
547+
ExtensionConfigurationInput rdpExtCfg = vmPowershellCmdlets.NewAzureServiceRemoteDesktopExtensionConfig(cred);
548+
545549
try
546550
{
547551
vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
548552
Console.WriteLine("service, {0}, is created.", serviceName);
549553

550554
Utilities.RetryActionUntilSuccess(() =>
551555
{
552-
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false);
556+
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false, rdpExtCfg);
553557
}, "Windows Azure is currently performing an operation on this hosted service that requires exclusive access.", 10, 30);
554558

555559
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
556560
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Staging, null, 1);
557561
Console.WriteLine("successfully deployed the package");
558562

563+
ExtensionContext extResult0 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Staging)[0];
564+
Utilities.PrintContext(extResult0);
559565

560566
// Move the deployment from 'Staging' to 'Production'
561567
Utilities.RetryActionUntilSuccess(() =>
@@ -564,9 +570,60 @@ public void AzureDeploymentTest()
564570
}, "The server encountered an internal error. Please retry the request.", 10, 30);
565571
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
566572
pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 1);
567-
Console.WriteLine("successfully moved");
573+
Console.WriteLine("successfully moved.");
574+
575+
ExtensionContext extResult1 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Production)[0];
576+
Utilities.PrintContext(extResult1);
577+
578+
Assert.IsTrue(string.Equals(extResult0.Id, extResult1.Id));
579+
580+
// Check until the deployment moving is done, and the staging slot is empty.
581+
Utilities.RetryActionUntilSuccess(() =>
582+
{
583+
try
584+
{
585+
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
586+
Assert.IsNull(result);
587+
}
588+
catch (Exception e)
589+
{
590+
const string errorMessage = "No deployments were found.";
591+
Assert.IsTrue(e.ToString().Contains(errorMessage) || (e.InnerException != null && e.InnerException.ToString().Contains(errorMessage)));
592+
}
593+
}, "Assert", 10, 60);
594+
Console.WriteLine("successfully checked original deployment has been moved away.");
595+
596+
// Re-create the Staging depoyment with the extension
597+
Utilities.RetryActionUntilSuccess(() =>
598+
{
599+
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath2.FullName, configPath2.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName2, false, false, rdpExtCfg);
600+
}, "Windows Azure is currently performing an operation on this hosted service that requires exclusive access.", 10, 60);
601+
602+
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
603+
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName2, deploymentLabel, DeploymentSlotType.Staging, null, 2);
604+
Console.WriteLine(string.Format("Successfully re-deployed the package #2 to the {0} slot.", DeploymentSlotType.Staging));
605+
606+
ExtensionContext extResult2 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Staging)[0];
607+
Utilities.PrintContext(extResult2);
608+
609+
// Update the deployment with the extension
610+
Utilities.RetryActionUntilSuccess(() =>
611+
{
612+
vmPowershellCmdlets.SetAzureDeploymentConfig(serviceName, DeploymentSlotType.Staging, configPath2.FullName, rdpExtCfg);
613+
}, "The server encountered an internal error. Please retry the request.", 10, 30);
614+
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
615+
pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName2, deploymentLabel, DeploymentSlotType.Staging, null, 2);
616+
Console.WriteLine("successfully updated the deployment #2");
617+
618+
ExtensionContext extResult3 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Staging)[0];
619+
Utilities.PrintContext(extResult3);
620+
621+
Assert.IsTrue(!string.Equals(extResult2.Id, extResult3.Id));
622+
623+
// Remove the deployment #2
624+
vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Staging, true);
568625

569-
// Set the deployment status to 'Suspended'
626+
// Set the deployment #1 status to 'Suspended'
570627
Utilities.RetryActionUntilSuccess(() =>
571628
{
572629
vmPowershellCmdlets.SetAzureDeploymentStatus(serviceName, DeploymentSlotType.Production, DeploymentStatus.Suspended);
@@ -575,7 +632,7 @@ public void AzureDeploymentTest()
575632
pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, DeploymentStatus.Suspended, 1);
576633
Console.WriteLine("successfully changed the status");
577634

578-
// Update the deployment
635+
// Update the deployment #1
579636
Utilities.RetryActionUntilSuccess(() =>
580637
{
581638
vmPowershellCmdlets.SetAzureDeploymentConfig(serviceName, DeploymentSlotType.Production, configPath2.FullName);
@@ -584,7 +641,7 @@ public void AzureDeploymentTest()
584641
pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
585642
Console.WriteLine("successfully updated the deployment");
586643

587-
// Upgrade the deployment
644+
// Upgrade the deployment #1
588645
DateTime start = DateTime.Now;
589646
Utilities.RetryActionUntilSuccess(() =>
590647
{

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureDeploymentCmdletInfo.cs

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

15+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions;
1516
using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.PowershellCore;
1617

1718
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.IaasCmdletInfo
@@ -38,13 +39,18 @@ public static SetAzureDeploymentCmdletInfo SetAzureDeploymentStatusCmdletInfo(st
3839
}
3940

4041

41-
public static SetAzureDeploymentCmdletInfo SetAzureDeploymentConfigCmdletInfo(string serviceName, string slot, string configPath)
42+
public static SetAzureDeploymentCmdletInfo SetAzureDeploymentConfigCmdletInfo(string serviceName, string slot, string configPath, ExtensionConfigurationInput extConfig = null)
4243
{
4344
SetAzureDeploymentCmdletInfo result = new SetAzureDeploymentCmdletInfo(serviceName, slot);
4445

4546
result.cmdletParams.Add(new CmdletParam("Config"));
4647
result.cmdletParams.Add(new CmdletParam("Configuration", configPath));
4748

49+
if (extConfig != null)
50+
{
51+
result.cmdletParams.Add(new CmdletParam("ExtensionConfiguration", extConfig));
52+
}
53+
4854
return result;
4955
}
5056

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ public ManagementOperationContext SetAzureDeploymentStatus(string serviceName, s
454454
return SetAzureDeployment(SetAzureDeploymentCmdletInfo.SetAzureDeploymentStatusCmdletInfo(serviceName, slot, newStatus));
455455
}
456456

457-
public ManagementOperationContext SetAzureDeploymentConfig(string serviceName, string slot, string configPath)
457+
public ManagementOperationContext SetAzureDeploymentConfig(string serviceName, string slot, string configPath, ExtensionConfigurationInput extConfig = null)
458458
{
459-
return SetAzureDeployment(SetAzureDeploymentCmdletInfo.SetAzureDeploymentConfigCmdletInfo(serviceName, slot, configPath));
459+
return SetAzureDeployment(SetAzureDeploymentCmdletInfo.SetAzureDeploymentConfigCmdletInfo(serviceName, slot, configPath, extConfig));
460460
}
461461

462462
public ManagementOperationContext SetAzureDeploymentUpgrade(string serviceName, string slot, string mode, string packagePath, string configPath)

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/ADDomain/SetAzureServiceADDomainExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void ExecuteCommand()
238238
Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
239239
};
240240

241-
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
241+
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, PeerDeployment.ExtensionConfiguration);
242242
ChangeDeployment(extConfig);
243243
}
244244

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/BaseAzureServiceExtensionCmdlet.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public abstract class BaseAzureServiceExtensionCmdlet : ServiceManagementBaseCmd
5050
protected XDocument PublicConfigurationXml { get; set; }
5151
protected XDocument PrivateConfigurationXml { get; set; }
5252
protected DeploymentGetResponse Deployment { get; set; }
53+
protected DeploymentGetResponse PeerDeployment { get; set; }
5354

5455
public virtual string ServiceName { get; set; }
5556
public virtual string Slot { get; set; }
@@ -109,6 +110,8 @@ protected void ValidateDeployment()
109110
}
110111
Deployment.ExtensionConfiguration = Deployment.ExtensionConfiguration ?? new Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration();
111112
}
113+
114+
PeerDeployment = GetPeerDeployment(Slot);
112115
}
113116

114117
protected void ValidateRoles()
@@ -285,6 +288,15 @@ protected DeploymentGetResponse GetDeployment(string slot)
285288
return d;
286289
}
287290

291+
protected DeploymentGetResponse GetPeerDeployment(string currentSlot)
292+
{
293+
var currentSlotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), currentSlot, true);
294+
var peerSlot = currentSlotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production;
295+
var peerSlotStr = peerSlot.ToString();
296+
297+
return GetDeployment(peerSlotStr);
298+
}
299+
288300
protected SecureString GetSecurePassword(string password)
289301
{
290302
SecureString securePassword = new SecureString();

0 commit comments

Comments
 (0)