diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 index 89a4fbfe6149..7ced50d94972 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1 @@ -25,7 +25,7 @@ function Test-AvailabilitySet { # Common $loc = 'West US'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; $asetName = 'avs' + $rgname; $nonDefaultUD = 2; diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest1.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest1.ps1 index a7d2d3a0e6d3..25cc694d4553 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest1.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest1.ps1 @@ -132,7 +132,7 @@ function ps_vm_dynamic_test_func_1_pstestrg1016 $st = Write-Verbose "Running Test ps_vm_dynamic_test_func_1_pstestrg1016 - Start ${rgname}, ${loc} & ${vmsize}"; $st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_pstestrg1016 - Creating Resource Group'; - $st = New-AzureResourceGroup -Location $loc -Name $rgname; + $st = New-AzureResourceGroup -Location $loc -Name $rgname -Force; $vmconfig = create_and_setup_vm_config_object $loc $rgname $vmsize; diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest2.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest2.ps1 index 8e8b3487a2af..dbb800833343 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest2.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest2.ps1 @@ -132,7 +132,7 @@ function ps_vm_dynamic_test_func_2_pstestrg4940 $st = Write-Verbose "Running Test ps_vm_dynamic_test_func_2_pstestrg4940 - Start ${rgname}, ${loc} & ${vmsize}"; $st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_2_pstestrg4940 - Creating Resource Group'; - $st = New-AzureResourceGroup -Location $loc -Name $rgname; + $st = New-AzureResourceGroup -Location $loc -Name $rgname -Force; $vmconfig = create_and_setup_vm_config_object $loc $rgname $vmsize; diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest3.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest3.ps1 index b922f4d09c0a..e21bda4249c6 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest3.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest3.ps1 @@ -132,7 +132,7 @@ function ps_vm_dynamic_test_func_3_pstestrg575 $st = Write-Verbose "Running Test ps_vm_dynamic_test_func_3_pstestrg575 - Start ${rgname}, ${loc} & ${vmsize}"; $st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_3_pstestrg575 - Creating Resource Group'; - $st = New-AzureResourceGroup -Location $loc -Name $rgname; + $st = New-AzureResourceGroup -Location $loc -Name $rgname -Force; $vmconfig = create_and_setup_vm_config_object $loc $rgname $vmsize; diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VMDynamicTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VMDynamicTests.ps1 index 44f771fb88b2..2d912f1c3b3f 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VMDynamicTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VMDynamicTests.ps1 @@ -335,7 +335,7 @@ function ${generated_func_name} `$st = Write-Verbose `"Running Test ${generated_func_name} - Start `${rgname}, `${loc} & `${vmsize}`"; `$st = Write-Verbose 'Running Test ${generated_func_name} - Creating Resource Group'; - `$st = New-AzureResourceGroup -Location `$loc -Name `$rgname; + `$st = New-AzureResourceGroup -Location `$loc -Name `$rgname -Force; `$vmconfig = create_and_setup_vm_config_object `$loc `$rgname `$vmsize; diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1 index 250a011ced19..a35215f7fe14 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1 @@ -26,7 +26,7 @@ function Test-VirtualMachineExtension { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A2'; @@ -203,7 +203,7 @@ function Test-VirtualMachineCustomScriptExtension { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; @@ -359,7 +359,7 @@ function Test-VirtualMachineAccessExtension { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineNetworkInterfaceTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineNetworkInterfaceTests.ps1 index f7605a2f2524..38ce4ab0e91e 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineNetworkInterfaceTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineNetworkInterfaceTests.ps1 @@ -25,7 +25,7 @@ function Test-SingleNetworkInterface { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A2'; @@ -148,7 +148,7 @@ function Test-SingleNetworkInterfaceDnsSettings { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A2'; @@ -255,7 +255,7 @@ function Test-MultipleNetworkInterface { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; diff --git a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 index a0775a08d1f5..5e650cfa7c05 100644 --- a/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 +++ b/src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineTests.ps1 @@ -25,7 +25,7 @@ function Test-VirtualMachine { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; @@ -373,7 +373,7 @@ function Test-VirtualMachineSizeAndUsage { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # Availability Set $asetName = 'aset' + $rgname; @@ -544,7 +544,7 @@ function Test-VirtualMachinePIRv2 { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; @@ -654,7 +654,7 @@ function Test-VirtualMachineCapture { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; @@ -770,7 +770,7 @@ function Test-VirtualMachineDataDisk { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A0'; @@ -851,7 +851,7 @@ function Test-VirtualMachinePlan { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A0'; @@ -935,7 +935,7 @@ function Test-VirtualMachinePlan2 { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A0'; @@ -1021,7 +1021,7 @@ function Test-VirtualMachineTags { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A0'; @@ -1096,7 +1096,7 @@ function Test-VirtualMachineWithVMAgentAutoUpdate { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; @@ -1190,7 +1190,7 @@ function Test-LinuxVirtualMachine { # Common $loc = 'westus'; - New-AzureResourceGroup -Name $rgname -Location $loc; + New-AzureResourceGroup -Name $rgname -Location $loc -Force; # VM Profile & Hardware $vmsize = 'Standard_A4'; diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs index c70998bd8e6d..b1955c2ee152 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs @@ -539,9 +539,13 @@ public void AzureDeploymentTest() Assert.IsTrue(File.Exists(configPath3.FullName), "file not exist={0}", configPath3); string deploymentName = "deployment1"; + string deploymentName2 = "deployment2"; string deploymentLabel = "label1"; DeploymentInfoContext result; + PSCredential cred = new PSCredential(username, Utilities.convertToSecureString(password)); + ExtensionConfigurationInput rdpExtCfg = vmPowershellCmdlets.NewAzureServiceRemoteDesktopExtensionConfig(cred); + try { vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName); @@ -549,13 +553,15 @@ public void AzureDeploymentTest() Utilities.RetryActionUntilSuccess(() => { - vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false); + vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false, rdpExtCfg); }, "Windows Azure is currently performing an operation on this hosted service that requires exclusive access.", 10, 30); result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging); pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Staging, null, 1); Console.WriteLine("successfully deployed the package"); + ExtensionContext extResult0 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Staging)[0]; + Utilities.PrintContext(extResult0); // Move the deployment from 'Staging' to 'Production' Utilities.RetryActionUntilSuccess(() => @@ -564,9 +570,60 @@ public void AzureDeploymentTest() }, "The server encountered an internal error. Please retry the request.", 10, 30); result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production); pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 1); - Console.WriteLine("successfully moved"); + Console.WriteLine("successfully moved."); + + ExtensionContext extResult1 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Production)[0]; + Utilities.PrintContext(extResult1); + + Assert.IsTrue(string.Equals(extResult0.Id, extResult1.Id)); + + // Check until the deployment moving is done, and the staging slot is empty. + Utilities.RetryActionUntilSuccess(() => + { + try + { + result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging); + Assert.IsNull(result); + } + catch (Exception e) + { + const string errorMessage = "No deployments were found."; + Assert.IsTrue(e.ToString().Contains(errorMessage) || (e.InnerException != null && e.InnerException.ToString().Contains(errorMessage))); + } + }, "Assert", 10, 60); + Console.WriteLine("successfully checked original deployment has been moved away."); + + // Re-create the Staging depoyment with the extension + Utilities.RetryActionUntilSuccess(() => + { + vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath2.FullName, configPath2.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName2, false, false, rdpExtCfg); + }, "Windows Azure is currently performing an operation on this hosted service that requires exclusive access.", 10, 60); + + result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging); + pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName2, deploymentLabel, DeploymentSlotType.Staging, null, 2); + Console.WriteLine(string.Format("Successfully re-deployed the package #2 to the {0} slot.", DeploymentSlotType.Staging)); + + ExtensionContext extResult2 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Staging)[0]; + Utilities.PrintContext(extResult2); + + // Update the deployment with the extension + Utilities.RetryActionUntilSuccess(() => + { + vmPowershellCmdlets.SetAzureDeploymentConfig(serviceName, DeploymentSlotType.Staging, configPath2.FullName, rdpExtCfg); + }, "The server encountered an internal error. Please retry the request.", 10, 30); + result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging); + pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName2, deploymentLabel, DeploymentSlotType.Staging, null, 2); + Console.WriteLine("successfully updated the deployment #2"); + + ExtensionContext extResult3 = vmPowershellCmdlets.GetAzureServiceExtension(serviceName, DeploymentSlotType.Staging)[0]; + Utilities.PrintContext(extResult3); + + Assert.IsTrue(!string.Equals(extResult2.Id, extResult3.Id)); + + // Remove the deployment #2 + vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Staging, true); - // Set the deployment status to 'Suspended' + // Set the deployment #1 status to 'Suspended' Utilities.RetryActionUntilSuccess(() => { vmPowershellCmdlets.SetAzureDeploymentStatus(serviceName, DeploymentSlotType.Production, DeploymentStatus.Suspended); @@ -575,7 +632,7 @@ public void AzureDeploymentTest() pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, DeploymentStatus.Suspended, 1); Console.WriteLine("successfully changed the status"); - // Update the deployment + // Update the deployment #1 Utilities.RetryActionUntilSuccess(() => { vmPowershellCmdlets.SetAzureDeploymentConfig(serviceName, DeploymentSlotType.Production, configPath2.FullName); @@ -584,7 +641,7 @@ public void AzureDeploymentTest() pass &= Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2); Console.WriteLine("successfully updated the deployment"); - // Upgrade the deployment + // Upgrade the deployment #1 DateTime start = DateTime.Now; Utilities.RetryActionUntilSuccess(() => { diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureDeploymentCmdletInfo.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureDeploymentCmdletInfo.cs index 73e71a6fb535..b770db9b0af9 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureDeploymentCmdletInfo.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/SetAzureDeploymentCmdletInfo.cs @@ -12,6 +12,7 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions; using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.PowershellCore; namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.IaasCmdletInfo @@ -38,13 +39,18 @@ public static SetAzureDeploymentCmdletInfo SetAzureDeploymentStatusCmdletInfo(st } - public static SetAzureDeploymentCmdletInfo SetAzureDeploymentConfigCmdletInfo(string serviceName, string slot, string configPath) + public static SetAzureDeploymentCmdletInfo SetAzureDeploymentConfigCmdletInfo(string serviceName, string slot, string configPath, ExtensionConfigurationInput extConfig = null) { SetAzureDeploymentCmdletInfo result = new SetAzureDeploymentCmdletInfo(serviceName, slot); result.cmdletParams.Add(new CmdletParam("Config")); result.cmdletParams.Add(new CmdletParam("Configuration", configPath)); + if (extConfig != null) + { + result.cmdletParams.Add(new CmdletParam("ExtensionConfiguration", extConfig)); + } + return result; } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs index 75537a22ab2d..67749028f22d 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs @@ -454,9 +454,9 @@ public ManagementOperationContext SetAzureDeploymentStatus(string serviceName, s return SetAzureDeployment(SetAzureDeploymentCmdletInfo.SetAzureDeploymentStatusCmdletInfo(serviceName, slot, newStatus)); } - public ManagementOperationContext SetAzureDeploymentConfig(string serviceName, string slot, string configPath) + public ManagementOperationContext SetAzureDeploymentConfig(string serviceName, string slot, string configPath, ExtensionConfigurationInput extConfig = null) { - return SetAzureDeployment(SetAzureDeploymentCmdletInfo.SetAzureDeploymentConfigCmdletInfo(serviceName, slot, configPath)); + return SetAzureDeployment(SetAzureDeploymentCmdletInfo.SetAzureDeploymentConfigCmdletInfo(serviceName, slot, configPath, extConfig)); } public ManagementOperationContext SetAzureDeploymentUpgrade(string serviceName, string slot, string mode, string packagePath, string configPath) diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/ADDomain/SetAzureServiceADDomainExtension.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/ADDomain/SetAzureServiceADDomainExtension.cs index 84e31ad1140b..9ab48953b43a 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/ADDomain/SetAzureServiceADDomainExtension.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/ADDomain/SetAzureServiceADDomainExtension.cs @@ -238,7 +238,7 @@ public void ExecuteCommand() Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1)) }; - var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration); + var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, PeerDeployment.ExtensionConfiguration); ChangeDeployment(extConfig); } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/BaseAzureServiceExtensionCmdlet.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/BaseAzureServiceExtensionCmdlet.cs index a24bfa9c41d6..8c5fa36ebeb3 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/BaseAzureServiceExtensionCmdlet.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/BaseAzureServiceExtensionCmdlet.cs @@ -50,6 +50,7 @@ public abstract class BaseAzureServiceExtensionCmdlet : ServiceManagementBaseCmd protected XDocument PublicConfigurationXml { get; set; } protected XDocument PrivateConfigurationXml { get; set; } protected DeploymentGetResponse Deployment { get; set; } + protected DeploymentGetResponse PeerDeployment { get; set; } public virtual string ServiceName { get; set; } public virtual string Slot { get; set; } @@ -109,6 +110,8 @@ protected void ValidateDeployment() } Deployment.ExtensionConfiguration = Deployment.ExtensionConfiguration ?? new Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration(); } + + PeerDeployment = GetPeerDeployment(Slot); } protected void ValidateRoles() @@ -285,6 +288,15 @@ protected DeploymentGetResponse GetDeployment(string slot) return d; } + protected DeploymentGetResponse GetPeerDeployment(string currentSlot) + { + var currentSlotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), currentSlot, true); + var peerSlot = currentSlotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production; + var peerSlotStr = peerSlot.ToString(); + + return GetDeployment(peerSlotStr); + } + protected SecureString GetSecurePassword(string password) { SecureString securePassword = new SecureString(); diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs index 2a4d98eff417..5301543f405a 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs @@ -147,7 +147,7 @@ private void GetThumbprintAndAlgorithm(IList new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1)) }; - var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration); + var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, PeerDeployment.ExtensionConfiguration); ChangeDeployment(extConfig); } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/RemoveAzureServiceAntimalwareExtension.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/RemoveAzureServiceAntimalwareExtension.cs index bfbf480dfdf7..6a6e60182b97 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/RemoveAzureServiceAntimalwareExtension.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/RemoveAzureServiceAntimalwareExtension.cs @@ -81,7 +81,7 @@ public void ExecuteCommand() // process any pending deployment changes if (extConfigInputs != null) { - ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, extConfigInputs, Slot); + ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, PeerDeployment, extConfigInputs, Slot); ChangeDeployment(newExtConfig); } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/SetAzureServiceAntimalwareExtension.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/SetAzureServiceAntimalwareExtension.cs index 15c4c996695a..8f17331a15bd 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/SetAzureServiceAntimalwareExtension.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/MicrosoftAntimalware/SetAzureServiceAntimalwareExtension.cs @@ -444,7 +444,7 @@ public void ExecuteCommand() // process any pending deployment changes if (extConfigInputs != null) { - ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, extConfigInputs, Slot); + ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, PeerDeployment, extConfigInputs, Slot); ChangeDeployment(newExtConfig); } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/RDP/SetAzureServiceRemoteDesktopExtension.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/RDP/SetAzureServiceRemoteDesktopExtension.cs index 36ac0f8a9e85..6e01f6e32ffe 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/RDP/SetAzureServiceRemoteDesktopExtension.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/RDP/SetAzureServiceRemoteDesktopExtension.cs @@ -132,7 +132,7 @@ public void ExecuteCommand() Version = Version, Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1)) }; - var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration); + var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, PeerDeployment.ExtensionConfiguration); ChangeDeployment(extConfig); } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/NewAzureDeployment.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/NewAzureDeployment.cs index 3d168eb176dd..8a3990f92697 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/NewAzureDeployment.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/NewAzureDeployment.cs @@ -159,14 +159,12 @@ public virtual void NewPaaSDeploymentProcess() } } - - var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true); - DeploymentGetResponse d = null; - InvokeInOperationContext(() => + Func func = t => { + DeploymentGetResponse d = null; try { - d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType); + d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, t); } catch (CloudException ex) { @@ -175,10 +173,20 @@ public virtual void NewPaaSDeploymentProcess() this.WriteExceptionDetails(ex); } } - }); + + return d; + }; + + var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true); + DeploymentGetResponse currentDeployment = null; + InvokeInOperationContext(() => currentDeployment = func(slotType)); + + var peerSlottype = slotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production; + DeploymentGetResponse peerDeployment = null; + InvokeInOperationContext(() => peerDeployment = func(peerSlottype)); ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName); - extConfig = extensionMgr.Set(d, ExtensionConfiguration, this.Slot); + extConfig = extensionMgr.Set(currentDeployment, peerDeployment, ExtensionConfiguration, this.Slot); } var deploymentInput = new DeploymentCreateParameters diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/SetAzureDeployment.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/SetAzureDeployment.cs index 7d34c6d4dee8..54655bc57ea4 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/SetAzureDeployment.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/HostedServices/SetAzureDeployment.cs @@ -164,13 +164,12 @@ public void ExecuteCommand() } } - var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true); - DeploymentGetResponse d = null; - InvokeInOperationContext(() => + Func func = t => { + DeploymentGetResponse d = null; try { - d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, slotType); + d = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, t); } catch (CloudException ex) { @@ -179,10 +178,20 @@ public void ExecuteCommand() this.WriteExceptionDetails(ex); } } - }); + + return d; + }; + + var slotType = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), this.Slot, true); + DeploymentGetResponse currentDeployment = null; + InvokeInOperationContext(() => currentDeployment = func(slotType)); + + var peerSlottype = slotType == DeploymentSlot.Production ? DeploymentSlot.Staging : DeploymentSlot.Production; + DeploymentGetResponse peerDeployment = null; + InvokeInOperationContext(() => peerDeployment = func(peerSlottype)); ExtensionManager extensionMgr = new ExtensionManager(this, ServiceName); - extConfig = extensionMgr.Add(d, ExtensionConfiguration, this.Slot); + extConfig = extensionMgr.Add(currentDeployment, peerDeployment, ExtensionConfiguration, this.Slot); } // Upgrade Parameter Set