diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs index dc94d83f5b06..c70998bd8e6d 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs @@ -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)) { diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/PaasCmdletInfo/SetAzureServiceDiagnosticsExtensionCmdletInfo.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/PaasCmdletInfo/SetAzureServiceDiagnosticsExtensionCmdletInfo.cs index 0a478fab976e..8f97e7a887c6 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/PaasCmdletInfo/SetAzureServiceDiagnosticsExtensionCmdletInfo.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/PaasCmdletInfo/SetAzureServiceDiagnosticsExtensionCmdletInfo.cs @@ -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)); @@ -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)) diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs index 98f0fbe5bf4e..bf35d219ead2 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ScenarioTest.cs @@ -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 { @@ -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 @@ -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 @@ -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) diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs index c342cdbd4471..e74663989efc 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs @@ -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(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, config, roles, slot)); + return RunPSCmdletAndReturnFirst(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(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, cert, config, roles, slot)); + return RunPSCmdletAndReturnFirst(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(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, thumbprint, algorithm, config, roles, slot)); + return RunPSCmdletAndReturnFirst(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storageContext, thumbprint, algorithm, config, roles, slot)); } // Get-AzureServiceDiagnosticsExtension diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs index da956f65e765..a36308e3ac6b 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementTest.cs @@ -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"); } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/Utilities.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/Utilities.cs index 0dfe5b9a8f33..14f95114aa7e 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/Utilities.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/Utilities.cs @@ -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)); } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cscfg b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cscfg index d20303b264fb..1ef08edc2459 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cscfg +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cscfg @@ -8,8 +8,9 @@ ********************************************************************************************** --> - + + \ No newline at end of file diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cspkg b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cspkg new file mode 100644 index 000000000000..b4dc1981ab00 Binary files /dev/null and b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/HelloNoDiag.cspkg differ diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/da.xml b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/da.xml index 6a7ac70b669b..8b0eb6c957b8 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/da.xml +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/Resources/da.xml @@ -1,10 +1,20 @@ - + - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs index c6dc159c042f..2a4d98eff417 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionManager.cs @@ -21,12 +21,14 @@ using Microsoft.WindowsAzure.Commands.Utilities.Common; using Microsoft.WindowsAzure.Management.Compute; using Microsoft.WindowsAzure.Management.Compute.Models; +using DeploymentSlotType = Microsoft.WindowsAzure.Commands.ServiceManagement.Model.DeploymentSlotType; +using System.Diagnostics; namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions { public class ExtensionManager { - public const int ExtensionIdLiveCycleCount = 2; + public const int ExtensionIdLiveCycleCount = 3; private const string ExtensionIdTemplate = "{0}-{1}-{2}-Ext-{3}"; private const string DefaultAllRolesNameStr = "Default"; private const string ExtensionCertificateSubject = "DC=Microsoft Azure Service Management for Extensions"; @@ -143,16 +145,24 @@ private void GetThumbprintAndAlgorithm(IList new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1)) }; - var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration); + + var secondSlotDeployment = GetDeployment(this.Slot == DeploymentSlotType.Production ? DeploymentSlotType.Staging : DeploymentSlotType.Production); + Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration secondSlotExtensionConfiguration = + secondSlotDeployment != null ? secondSlotDeployment.ExtensionConfiguration : null; + + var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, secondSlotExtensionConfiguration); ChangeDeployment(extConfig); }