Skip to content

Commit 3d88c8c

Browse files
committed
Merge pull request #361 from LogicSoftware/dev
Fix for #193 ConflictError: The extension ID xxx-PaasDiagnostics-Production-Ext-0 is already in use for this deployment
2 parents f90bbd5 + 3f00913 commit 3d88c8c

File tree

11 files changed

+164
-69
lines changed

11 files changed

+164
-69
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ private bool VerifyExtensionConfigDiag(ExtensionConfigurationInput resultConfig,
10361036

10371037
Assert.AreEqual("PaaSDiagnostics", resultConfig.Type, "Type is not equal!");
10381038
Assert.AreEqual(storage, resultStorageAccount);
1039-
Assert.IsTrue(Utilities.CompareWadCfg(resultWadCfg, wadconfig));
1039+
Utilities.CompareWadCfg(resultWadCfg, wadconfig);
10401040

10411041
if (string.IsNullOrWhiteSpace(thumbprint))
10421042
{

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414

1515
using System.Security.Cryptography.X509Certificates;
1616
using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.PowershellCore;
17+
using Microsoft.WindowsAzure.Commands.Common.Storage;
1718

1819
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.PaasCmdletInfo
1920
{
2021
public class SetAzureServiceDiagnosticsExtensionCmdletInfo : CmdletsInfo
2122
{
2223

23-
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string storage, string config, string[] roles, string slot)
24+
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorageContext storageContext, string config, string[] roles, string slot)
2425
{
2526
this.cmdletName = Utilities.SetAzureServiceDiagnosticsExtensionCmdletName;
2627
this.cmdletParams.Add(new CmdletParam("ServiceName", service));
27-
this.cmdletParams.Add(new CmdletParam("StorageAccountName", storage));
28+
this.cmdletParams.Add(new CmdletParam("StorageContext", storageContext));
29+
this.cmdletParams.Add(new CmdletParam("Slot", slot));
2830
if (roles != null)
2931
{
3032
this.cmdletParams.Add(new CmdletParam("Role", roles));
@@ -35,14 +37,14 @@ public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string stor
3537
}
3638
}
3739

38-
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string storage, X509Certificate2 cert, string config, string[] roles, string slot)
39-
: this(service, storage, config, roles, slot)
40+
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorageContext storageContext, X509Certificate2 cert, string config, string[] roles, string slot)
41+
: this(service, storageContext, config, roles, slot)
4042
{
4143
this.cmdletParams.Add(new CmdletParam("X509Certificate", cert));
4244
}
4345

44-
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string storage, string thumbprint, string algorithm, string config, string[] roles, string slot)
45-
: this(service, storage, config, roles, slot)
46+
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorageContext storageContext, string thumbprint, string algorithm, string config, string[] roles, string slot)
47+
: this(service, storageContext, config, roles, slot)
4648
{
4749
this.cmdletParams.Add(new CmdletParam("CertificateThumbprint", thumbprint));
4850
if (!string.IsNullOrEmpty(algorithm))

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

Lines changed: 103 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
using Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions;
3333
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
3434
using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.ConfigDataInfo;
35+
using Microsoft.WindowsAzure.Commands.Common.Storage;
36+
using Microsoft.WindowsAzure.Storage.Auth;
37+
using Microsoft.WindowsAzure.Storage;
3538

3639
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests
3740
{
@@ -1009,7 +1012,6 @@ public void AzureServiceDiagnosticsExtensionConfigScenarioTest()
10091012
[Ignore]
10101013
public void AzureServiceDiagnosticsExtensionTest()
10111014
{
1012-
10131015
StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
10141016

10151017
// Choose the package and config files from local machine
@@ -1026,41 +1028,110 @@ public void AzureServiceDiagnosticsExtensionTest()
10261028
DeploymentInfoContext result;
10271029

10281030
string storage = defaultAzureSubscription.CurrentStorageAccountName;
1029-
string daConfig = @".\da.xml";
1031+
string daConfig = @"da.xml";
10301032

10311033
string defaultExtensionId = string.Format("Default-{0}-Production-Ext-0", Utilities.PaaSDiagnosticsExtensionName);
10321034

1033-
try
1034-
{
1035-
serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
1036-
vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
1037-
Console.WriteLine("service, {0}, is created.", serviceName);
1035+
serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
1036+
vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
1037+
Console.WriteLine("service, {0}, is created.", serviceName);
10381038

1039-
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false);
1039+
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath1.FullName, configPath1.FullName, DeploymentSlotType.Production, deploymentLabel, deploymentName, false, false);
10401040

1041-
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
1042-
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
1043-
Console.WriteLine("successfully deployed the package");
1041+
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
1042+
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
1043+
Console.WriteLine("successfully deployed the package");
10441044

1045-
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storage, daConfig, null, null);
1045+
string storageKey = vmPowershellCmdlets.GetAzureStorageAccountKey(storage).Primary;
10461046

1047-
DiagnosticExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName)[0];
1047+
StorageCredentials creds = new StorageCredentials(storage, storageKey);
1048+
CloudStorageAccount csa = new WindowsAzure.Storage.CloudStorageAccount(creds, true);
1049+
var storageContext = new AzureStorageContext(csa);
10481050

1049-
VerifyDiagExtContext(resultContext, "AllRoles", defaultExtensionId, storage, daConfig);
1051+
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, null);
10501052

1051-
vmPowershellCmdlets.RemoveAzureServiceDiagnosticsExtension(serviceName, true);
1053+
DiagnosticExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName)[0];
10521054

1053-
Assert.AreEqual(vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName).Count, 0);
1055+
VerifyDiagExtContext(resultContext, "AllRoles", defaultExtensionId, storage, daConfig);
10541056

1055-
vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
1057+
vmPowershellCmdlets.RemoveAzureServiceDiagnosticsExtension(serviceName, true);
10561058

1057-
pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
1058-
}
1059-
catch (Exception e)
1060-
{
1061-
pass = false;
1062-
Assert.Fail("Exception occurred: {0}", e.ToString());
1063-
}
1059+
Assert.AreEqual(vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName).Count, 0);
1060+
1061+
vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
1062+
1063+
pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
1064+
}
1065+
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);
10641135
}
10651136

10661137
#endregion
@@ -1695,15 +1766,19 @@ private void VerifyDiagExtContext(DiagnosticExtensionContext resultContext, stri
16951766
{
16961767
Utilities.PrintContext(resultContext);
16971768

1698-
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+
16991774
Assert.AreEqual(Utilities.PaaSDiagnosticsExtensionName, resultContext.Extension, "extension is not Diagnostics");
1775+
17001776
Assert.AreEqual(extID, resultContext.Id, "extension id is not same");
1701-
//Assert.AreEqual(storage, resultContext.StorageAccountName, "storage account name is not same");
17021777

17031778
XmlDocument doc = new XmlDocument();
1704-
doc.Load("@./da.xml");
1779+
doc.Load("da.xml");
17051780
string inner = Utilities.GetInnerXml(resultContext.WadCfg, "WadCfg");
1706-
Assert.IsTrue(Utilities.CompareWadCfg(inner, doc), "xml is not same");
1781+
Utilities.CompareWadCfg(inner, doc);
17071782
}
17081783

17091784
private void VerifyRDPExtContext(RemoteDesktopExtensionContext resultContext, string role, string extID, string userName, DateTime exp, string version = null)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,19 +1127,19 @@ public ExtensionConfigurationInput NewAzureServiceDiagnosticsExtensionConfig
11271127

11281128
// Set-AzureServiceDiagnosticsExtension
11291129
public ManagementOperationContext SetAzureServiceDiagnosticsExtension
1130-
(string service, string storage, string config = null, string[] roles = null, string slot = null)
1130+
(string service, AzureStorageContext storageContext, string config = null, string[] roles = null, string slot = null)
11311131
{
1132-
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, config, roles, slot));
1132+
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storageContext, config, roles, slot));
11331133
}
11341134

1135-
public ManagementOperationContext SetAzureServiceDiagnosticsExtension(string service, string storage, X509Certificate2 cert, string config = null, string[] roles = null, string slot = null)
1135+
public ManagementOperationContext SetAzureServiceDiagnosticsExtension(string service, AzureStorageContext storageContext, X509Certificate2 cert, string config = null, string[] roles = null, string slot = null)
11361136
{
1137-
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, cert, config, roles, slot));
1137+
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storageContext, cert, config, roles, slot));
11381138
}
11391139

1140-
public ManagementOperationContext SetAzureServiceDiagnosticsExtension(string service, string storage, string thumbprint, string algorithm = null, string config = null, string[] roles = null, string slot = null)
1140+
public ManagementOperationContext SetAzureServiceDiagnosticsExtension(string service, AzureStorageContext storageContext, string thumbprint, string algorithm = null, string config = null, string[] roles = null, string slot = null)
11411141
{
1142-
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, thumbprint, algorithm, config, roles, slot));
1142+
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storageContext, thumbprint, algorithm, config, roles, slot));
11431143
}
11441144

11451145
// Get-AzureServiceDiagnosticsExtension

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static void SetDefaultStorage()
112112
}
113113
else
114114
{
115-
Console.WriteLine("Unable to get the default storege account");
115+
Console.WriteLine("Unable to get the default storage account");
116116
}
117117
}
118118

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -812,24 +812,16 @@ public static string GetInnerXml(string xmlString, string tag)
812812
return xml.GetElementsByTagName(tag)[0].InnerXml;
813813
}
814814

815-
public static bool CompareWadCfg(string wadcfg, XmlDocument daconfig)
815+
public static void CompareWadCfg(string wadcfg, XmlDocument daconfig)
816816
{
817-
try
817+
if (string.IsNullOrWhiteSpace(wadcfg))
818818
{
819-
if (string.IsNullOrWhiteSpace(wadcfg))
820-
{
821-
Assert.IsNull(wadcfg);
822-
}
823-
else
824-
{
825-
string innerXml = daconfig.InnerXml;
826-
Assert.AreEqual(Utilities.FindSubstring(wadcfg, '<', 2), Utilities.FindSubstring(innerXml, '<', 2));
827-
}
828-
return true;
819+
Assert.IsNull(wadcfg);
829820
}
830-
catch
821+
else
831822
{
832-
return false;
823+
string innerXml = daconfig.InnerXml;
824+
StringAssert.Contains(Utilities.FindSubstring(innerXml, '<', 2), Utilities.FindSubstring(wadcfg, '<', 2));
833825
}
834826
}
835827

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cscfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
99
**********************************************************************************************
1010
-->
11-
<ServiceConfiguration serviceName="HelloNoDiag" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*" schemaVersion="2012-10.1.8">
11+
<ServiceConfiguration serviceName="HelloNoDiag" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-06.2.4">
1212
<Role name="WebRole1">
1313
<Instances count="2" />
14+
<ConfigurationSettings />
1415
</Role>
1516
</ServiceConfiguration>

0 commit comments

Comments
 (0)