Skip to content

Fix for #193 ConflictError: The extension ID xxx-PaasDiagnostics-Production-Ext-0 is already in use for this deployment #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ private bool VerifyExtensionConfigDiag(ExtensionConfigurationInput resultConfig,

Assert.AreEqual("PaaSDiagnostics", resultConfig.Type, "Type is not equal!");
Assert.AreEqual(storage, resultStorageAccount);
Assert.IsTrue(Utilities.CompareWadCfg(resultWadCfg, wadconfig));
Utilities.CompareWadCfg(resultWadCfg, wadconfig);

if (string.IsNullOrWhiteSpace(thumbprint))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@

using System.Security.Cryptography.X509Certificates;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.PowershellCore;
using Microsoft.WindowsAzure.Commands.Common.Storage;

namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.PaasCmdletInfo
{
public class SetAzureServiceDiagnosticsExtensionCmdletInfo : CmdletsInfo
{

public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string storage, string config, string[] roles, string slot)
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorageContext storageContext, string config, string[] roles, string slot)
{
this.cmdletName = Utilities.SetAzureServiceDiagnosticsExtensionCmdletName;
this.cmdletParams.Add(new CmdletParam("ServiceName", service));
this.cmdletParams.Add(new CmdletParam("StorageAccountName", storage));
this.cmdletParams.Add(new CmdletParam("StorageContext", storageContext));
this.cmdletParams.Add(new CmdletParam("Slot", slot));
if (roles != null)
{
this.cmdletParams.Add(new CmdletParam("Role", roles));
Expand All @@ -35,14 +37,14 @@ public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string stor
}
}

public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string storage, X509Certificate2 cert, string config, string[] roles, string slot)
: this(service, storage, config, roles, slot)
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorageContext storageContext, X509Certificate2 cert, string config, string[] roles, string slot)
: this(service, storageContext, config, roles, slot)
{
this.cmdletParams.Add(new CmdletParam("X509Certificate", cert));
}

public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string storage, string thumbprint, string algorithm, string config, string[] roles, string slot)
: this(service, storage, config, roles, slot)
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorageContext storageContext, string thumbprint, string algorithm, string config, string[] roles, string slot)
: this(service, storageContext, config, roles, slot)
{
this.cmdletParams.Add(new CmdletParam("CertificateThumbprint", thumbprint));
if (!string.IsNullOrEmpty(algorithm))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
using Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.ConfigDataInfo;
using Microsoft.WindowsAzure.Commands.Common.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage;

namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests
{
Expand Down Expand Up @@ -1009,7 +1012,6 @@ public void AzureServiceDiagnosticsExtensionConfigScenarioTest()
[Ignore]
public void AzureServiceDiagnosticsExtensionTest()
{

StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

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

string storage = defaultAzureSubscription.CurrentStorageAccountName;
string daConfig = @".\da.xml";
string daConfig = @"da.xml";

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

try
{
serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
Console.WriteLine("service, {0}, is created.", serviceName);
serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
Console.WriteLine("service, {0}, is created.", serviceName);

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

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

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

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

VerifyDiagExtContext(resultContext, "AllRoles", defaultExtensionId, storage, daConfig);
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, null);

vmPowershellCmdlets.RemoveAzureServiceDiagnosticsExtension(serviceName, true);
DiagnosticExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName)[0];

Assert.AreEqual(vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName).Count, 0);
VerifyDiagExtContext(resultContext, "AllRoles", defaultExtensionId, storage, daConfig);

vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
vmPowershellCmdlets.RemoveAzureServiceDiagnosticsExtension(serviceName, true);

pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
}
catch (Exception e)
{
pass = false;
Assert.Fail("Exception occurred: {0}", e.ToString());
}
Assert.AreEqual(vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName).Count, 0);

vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);

pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
}

[TestMethod(), TestCategory(Category.Scenario), TestProperty("Feature", "PAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet ((Get,Set,Remove)-AzureServiceRemoteDesktopExtension)")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Resources\\nodiagpackage.csv", "nodiagpackage#csv", DataAccessMethod.Sequential)]
[Ignore]
public void VipSwapWithDiagnosticsExtensionTest()
{
StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

// Choose the package and config files from local machine
string packageName = Convert.ToString(TestContext.DataRow["packageName"]);
string configName = Convert.ToString(TestContext.DataRow["configName"]);
var packagePath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + packageName);
var configPath = new FileInfo(Directory.GetCurrentDirectory() + "\\" + configName);

Assert.IsTrue(File.Exists(packagePath.FullName), "Package file not exist={0}", packagePath);
Assert.IsTrue(File.Exists(configPath.FullName), "Config file not exist={0}", configPath);

string deploymentName = "deployment1";
string deploymentLabel = "label1";
DeploymentInfoContext result;

string storage = defaultAzureSubscription.CurrentStorageAccountName;
string daConfig = @"da.xml";

string storageKey = vmPowershellCmdlets.GetAzureStorageAccountKey(storage).Primary;
StorageCredentials creds = new StorageCredentials(storage, storageKey);
CloudStorageAccount csa = new WindowsAzure.Storage.CloudStorageAccount(creds, true);
var storageContext = new AzureStorageContext(csa);

serviceName = Utilities.GetUniqueShortName(serviceNamePrefix);
vmPowershellCmdlets.NewAzureService(serviceName, serviceName, locationName);
Console.WriteLine("service, {0}, is created.", serviceName);

// deploy staging
vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath.FullName, configPath.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false);
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Staging, null, 2);
Console.WriteLine("successfully deployed the package");

vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, slot: DeploymentSlotType.Staging);
DiagnosticExtensionContext resultContext = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName, slot: DeploymentSlotType.Staging)[0];
VerifyDiagExtContext(resultContext, "AllRoles", "Default-PaaSDiagnostics-Staging-Ext-0", storage, daConfig);

// swap staging -> production
// production will be retain diagnosting config from staging, named Default-PaaSDiagnostics-Staging-Ext-0
vmPowershellCmdlets.MoveAzureDeployment(serviceName);

// deploy a new staging
deploymentName = "deployment2";
deploymentLabel = "label2";

vmPowershellCmdlets.NewAzureDeployment(serviceName, packagePath.FullName, configPath.FullName, DeploymentSlotType.Staging, deploymentLabel, deploymentName, false, false);
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Staging);
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Staging, null, 2);
Console.WriteLine("successfully deployed the package");

// should detect that Default-PaaSDiagnostics-Staging-Ext-0 is in use
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, slot: DeploymentSlotType.Staging);
DiagnosticExtensionContext resultContext2 = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName, slot: DeploymentSlotType.Staging)[0];
VerifyDiagExtContext(resultContext2, "AllRoles", "Default-PaaSDiagnostics-Staging-Ext-1", storage, daConfig);

// execute again to make sure max number of extensions will handled correctly (1 for production and 1 for staging, 1 unused)
// should not fail due to ExtensionIdLiveCycleCount limit
vmPowershellCmdlets.SetAzureServiceDiagnosticsExtension(serviceName, storageContext, daConfig, null, slot: DeploymentSlotType.Staging);
DiagnosticExtensionContext resultContext3 = vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName, slot: DeploymentSlotType.Staging)[0];

// azure splits config from All Roles to specific role in that case, so role name should not be validated
VerifyDiagExtContext(resultContext3, null, "Default-PaaSDiagnostics-Staging-Ext-2", storage, daConfig);

vmPowershellCmdlets.RemoveAzureService(serviceName, true);
}

#endregion
Expand Down Expand Up @@ -1695,15 +1766,19 @@ private void VerifyDiagExtContext(DiagnosticExtensionContext resultContext, stri
{
Utilities.PrintContext(resultContext);

Assert.AreEqual(role, resultContext.Role.RoleType.ToString(), "role is not same");
if (role != null)
{
Assert.AreEqual(role, resultContext.Role.RoleType.ToString(), "role is not same");
}

Assert.AreEqual(Utilities.PaaSDiagnosticsExtensionName, resultContext.Extension, "extension is not Diagnostics");

Assert.AreEqual(extID, resultContext.Id, "extension id is not same");
//Assert.AreEqual(storage, resultContext.StorageAccountName, "storage account name is not same");

XmlDocument doc = new XmlDocument();
doc.Load("@./da.xml");
doc.Load("da.xml");
string inner = Utilities.GetInnerXml(resultContext.WadCfg, "WadCfg");
Assert.IsTrue(Utilities.CompareWadCfg(inner, doc), "xml is not same");
Utilities.CompareWadCfg(inner, doc);
}

private void VerifyRDPExtContext(RemoteDesktopExtensionContext resultContext, string role, string extID, string userName, DateTime exp, string version = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,19 +1120,19 @@ public ExtensionConfigurationInput NewAzureServiceDiagnosticsExtensionConfig

// Set-AzureServiceDiagnosticsExtension
public ManagementOperationContext SetAzureServiceDiagnosticsExtension
(string service, string storage, string config = null, string[] roles = null, string slot = null)
(string service, AzureStorageContext storageContext, string config = null, string[] roles = null, string slot = null)
{
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, config, roles, slot));
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storageContext, config, roles, slot));
}

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

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

// Get-AzureServiceDiagnosticsExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void SetDefaultStorage()
}
else
{
Console.WriteLine("Unable to get the default storege account");
Console.WriteLine("Unable to get the default storage account");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,24 +786,16 @@ public static string GetInnerXml(string xmlString, string tag)
return xml.GetElementsByTagName(tag)[0].InnerXml;
}

public static bool CompareWadCfg(string wadcfg, XmlDocument daconfig)
public static void CompareWadCfg(string wadcfg, XmlDocument daconfig)
{
try
if (string.IsNullOrWhiteSpace(wadcfg))
{
if (string.IsNullOrWhiteSpace(wadcfg))
{
Assert.IsNull(wadcfg);
}
else
{
string innerXml = daconfig.InnerXml;
Assert.AreEqual(Utilities.FindSubstring(wadcfg, '<', 2), Utilities.FindSubstring(innerXml, '<', 2));
}
return true;
Assert.IsNull(wadcfg);
}
catch
else
{
return false;
string innerXml = daconfig.InnerXml;
StringAssert.Contains(Utilities.FindSubstring(innerXml, '<', 2), Utilities.FindSubstring(wadcfg, '<', 2));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

**********************************************************************************************
-->
<ServiceConfiguration serviceName="HelloNoDiag" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*" schemaVersion="2012-10.1.8">
<ServiceConfiguration serviceName="HelloNoDiag" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2014-06.2.4">
<Role name="WebRole1">
<Instances count="2" />
<ConfigurationSettings />
</Role>
</ServiceConfiguration>
Binary file not shown.
Loading