Skip to content

Commit 3f00913

Browse files
committed
fix for Azure#193 - "The extension ID Default-PaaSDiagnostics-Staging-Ext-0 is already in use for this deployment" for Set-AzureServiceDiagnosticsExtension after VIP Swap.
1 parent 1deb723 commit 3f00913

File tree

4 files changed

+97
-7
lines changed

4 files changed

+97
-7
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/PaasCmdletInfo/SetAzureServiceDiagnosticsExtensionCmdletInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorag
2626
this.cmdletName = Utilities.SetAzureServiceDiagnosticsExtensionCmdletName;
2727
this.cmdletParams.Add(new CmdletParam("ServiceName", service));
2828
this.cmdletParams.Add(new CmdletParam("StorageContext", storageContext));
29+
this.cmdletParams.Add(new CmdletParam("Slot", slot));
2930
if (roles != null)
3031
{
3132
this.cmdletParams.Add(new CmdletParam("Role", roles));

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

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,6 @@ public void AzureServiceDiagnosticsExtensionConfigScenarioTest()
10121012
[Ignore]
10131013
public void AzureServiceDiagnosticsExtensionTest()
10141014
{
1015-
10161015
StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
10171016

10181017
// Choose the package and config files from local machine
@@ -1064,6 +1063,77 @@ public void AzureServiceDiagnosticsExtensionTest()
10641063
pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
10651064
}
10661065

1066+
[TestMethod(), TestCategory(Category.Scenario), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet ((Get,Set,Remove)-AzureServiceRemoteDesktopExtension)")]
1067+
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\nodiagpackage.csv", "nodiagpackage#csv", DataAccessMethod.Sequential)]
1068+
[Ignore]
1069+
public void VipSwapWithDiagnosticsExtensionTest()
1070+
{
1071+
StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
1072+
1073+
// Choose the package and config files from local machine
1074+
string packageName = Convert.ToString(TestContext.DataRow["packageName"]);
1075+
string configName = Convert.ToString(TestContext.DataRow["configName"]);
1076+
var packagePath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + packageName);
1077+
var configPath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configName);
1078+
1079+
Assert.IsTrue(File.Exists(packagePath.FullName), "Package file not exist={0}", packagePath);
1080+
Assert.IsTrue(File.Exists(configPath.FullName), "Config file not exist={0}", configPath);
1081+
1082+
string deploymentName = "deployment1";
1083+
string deploymentLabel = "label1";
1084+
DeploymentInfoContext result;
1085+
1086+
string storage = defaultAzureSubscription.CurrentStorageAccountName;
1087+
string daConfig = @"da.xml";
1088+
1089+
string storageKey = vmPowershellCmdlets.GetAzureStorageAccountKey(storage).Primary;
1090+
StorageCredentials creds = new StorageCredentials(storage, storageKey);
1091+
CloudStorageAccount csa = new WindowsAzure.Storage.CloudStorageAccount(creds, true);
1092+
var storageContext = new AzureStorageContext(csa);
1093+
1094+
serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
1095+
vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
1096+
Console.WriteLine("service, {0}, is created.", serviceName);
1097+
1098+
// deploy staging
1099+
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath.FullName, configPath.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false);
1100+
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
1101+
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Staging, null, 2);
1102+
Console.WriteLine("successfully deployed the package");
1103+
1104+
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, slot: DeploymentSlotType.Staging);
1105+
DiagnosticExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName, slot: DeploymentSlotType.Staging)[0];
1106+
VerifyDiagExtContext(resultContext, "AllRoles", "Default-PaaSDiagnostics-Staging-Ext-0", storage, daConfig);
1107+
1108+
// swap staging -> production
1109+
// production will be retain diagnosting config from staging, named Default-PaaSDiagnostics-Staging-Ext-0
1110+
vmPowershellCmdlets.MoveAzureDeployment(serviceName);
1111+
1112+
// deploy a new staging
1113+
deploymentName = "deployment2";
1114+
deploymentLabel = "label2";
1115+
1116+
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath.FullName, configPath.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false);
1117+
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
1118+
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Staging, null, 2);
1119+
Console.WriteLine("successfully deployed the package");
1120+
1121+
// should detect that Default-PaaSDiagnostics-Staging-Ext-0 is in use
1122+
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, slot: DeploymentSlotType.Staging);
1123+
DiagnosticExtensionContext resultContext2 = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName, slot: DeploymentSlotType.Staging)[0];
1124+
VerifyDiagExtContext(resultContext2, "AllRoles", "Default-PaaSDiagnostics-Staging-Ext-1", storage, daConfig);
1125+
1126+
// execute again to make sure max number of extensions will handled correctly (1 for production and 1 for staging, 1 unused)
1127+
// should not fail due to ExtensionIdLiveCycleCount limit
1128+
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, slot: DeploymentSlotType.Staging);
1129+
DiagnosticExtensionContext resultContext3 = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName, slot: DeploymentSlotType.Staging)[0];
1130+
1131+
// azure splits config from All Roles to specific role in that case, so role name should not be validated
1132+
VerifyDiagExtContext(resultContext3, null, "Default-PaaSDiagnostics-Staging-Ext-2", storage, daConfig);
1133+
1134+
vmPowershellCmdlets.RemoveAzureService(serviceName, true);
1135+
}
1136+
10671137
#endregion
10681138

10691139

@@ -1696,10 +1766,14 @@ private void VerifyDiagExtContext(DiagnosticExtensionContext resultContext, stri
16961766
{
16971767
Utilities.PrintContext(resultContext);
16981768

1699-
Assert.AreEqual(role, resultContext.Role.RoleType.ToString(), "role is not same");
1769+
if (role != null)
1770+
{
1771+
Assert.AreEqual(role, resultContext.Role.RoleType.ToString(), "role is not same");
1772+
}
1773+
17001774
Assert.AreEqual(Utilities.PaaSDiagnosticsExtensionName, resultContext.Extension, "extension is not Diagnostics");
1775+
17011776
Assert.AreEqual(extID, resultContext.Id, "extension id is not same");
1702-
//Assert.AreEqual(storage, resultContext.StorageAccountName, "storage account name is not same");
17031777

17041778
XmlDocument doc = new XmlDocument();
17051779
doc.Load("da.xml");

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2222
using Microsoft.WindowsAzure.Management.Compute;
2323
using Microsoft.WindowsAzure.Management.Compute.Models;
24+
using DeploymentSlotType = Microsoft.WindowsAzure.Commands.ServiceManagement.Model.DeploymentSlotType;
25+
using System.Diagnostics;
2426

2527
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions
2628
{
2729
public class ExtensionManager
2830
{
29-
public const int ExtensionIdLiveCycleCount = 2;
31+
public const int ExtensionIdLiveCycleCount = 3;
3032
private const string ExtensionIdTemplate = "{0}-{1}-{2}-Ext-{3}";
3133
private const string DefaultAllRolesNameStr = "Default";
3234
private const string ExtensionCertificateSubject = "DC=Microsoft Azure Service Management for Extensions";
@@ -143,16 +145,24 @@ private void GetThumbprintAndAlgorithm(IList<HostedServiceListExtensionsResponse
143145
}
144146
}
145147

146-
public ExtensionConfiguration InstallExtension(ExtensionConfigurationInput context, string slot, Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration extConfig)
148+
public ExtensionConfiguration InstallExtension(ExtensionConfigurationInput context, string slot,
149+
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration extConfig,
150+
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration secondSlotExtConfig = null)
147151
{
148152
ExtensionConfigurationBuilder builder = GetBuilder(extConfig);
153+
ExtensionConfigurationBuilder secondSlotConfigBuilder = null;
154+
if (secondSlotExtConfig != null)
155+
{
156+
secondSlotConfigBuilder = GetBuilder(secondSlotExtConfig);
157+
}
158+
149159
foreach (ExtensionRole r in context.Roles)
150160
{
151161
var extensionIds = (from index in Enumerable.Range(0, ExtensionIdLiveCycleCount)
152162
select r.GetExtensionId(context.Type, slot, index)).ToList();
153163

154164
string availableId = (from extensionId in extensionIds
155-
where !builder.ExistAny(extensionId)
165+
where !builder.ExistAny(extensionId) && (secondSlotConfigBuilder == null || !secondSlotConfigBuilder.ExistAny(extensionId))
156166
select extensionId).FirstOrDefault();
157167

158168
var extensionList = (from id in extensionIds

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Diagnostics/SetAzureServiceDiagnosticsExtension.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ public void ExecuteCommand()
130130
PrivateConfiguration = PrivateConfiguration,
131131
Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
132132
};
133-
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
133+
134+
var secondSlotDeployment = GetDeployment(this.Slot == DeploymentSlotType.Production ? DeploymentSlotType.Staging : DeploymentSlotType.Production);
135+
Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration secondSlotExtensionConfiguration =
136+
secondSlotDeployment != null ? secondSlotDeployment.ExtensionConfiguration : null;
137+
138+
var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, secondSlotExtensionConfiguration);
134139
ChangeDeployment(extConfig);
135140
}
136141

0 commit comments

Comments
 (0)