Skip to content

Commit 1deb723

Browse files
committed
fixed Scenario Test for Set-AzureServiceDiagnosticsExtension cmdlet
1 parent f9f2d9a commit 1deb723

File tree

9 files changed

+67
-62
lines changed

9 files changed

+67
-62
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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
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));
2829
if (roles != null)
2930
{
3031
this.cmdletParams.Add(new CmdletParam("Role", roles));
@@ -35,14 +36,14 @@ public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string stor
3536
}
3637
}
3738

38-
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, string storage, X509Certificate2 cert, string config, string[] roles, string slot)
39-
: this(service, storage, config, roles, slot)
39+
public SetAzureServiceDiagnosticsExtensionCmdletInfo(string service, AzureStorageContext storageContext, X509Certificate2 cert, string config, string[] roles, string slot)
40+
: this(service, storageContext, config, roles, slot)
4041
{
4142
this.cmdletParams.Add(new CmdletParam("X509Certificate", cert));
4243
}
4344

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

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

Lines changed: 26 additions & 25 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
{
@@ -1026,41 +1029,39 @@ public void AzureServiceDiagnosticsExtensionTest()
10261029
DeploymentInfoContext result;
10271030

10281031
string storage = defaultAzureSubscription.CurrentStorageAccountName;
1029-
string daConfig = @".\da.xml";
1032+
string daConfig = @"da.xml";
10301033

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

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

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

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");
1042+
result = vmPowershellCmdlets.GetAzureDeployment(serviceName, DeploymentSlotType.Production);
1043+
pass = Utilities.PrintAndCompareDeployment(result, serviceName, deploymentName, deploymentLabel, DeploymentSlotType.Production, null, 2);
1044+
Console.WriteLine("successfully deployed the package");
10441045

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

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

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

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

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

1055-
vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
1058+
vmPowershellCmdlets.RemoveAzureServiceDiagnosticsExtension(serviceName, true);
10561059

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-
}
1060+
Assert.AreEqual(vmPowershellCmdlets.GetAzureServiceDiagnosticsExtension(serviceName).Count, 0);
1061+
1062+
vmPowershellCmdlets.RemoveAzureDeployment(serviceName, DeploymentSlotType.Production, true);
1063+
1064+
pass &= Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDeployment, serviceName, DeploymentSlotType.Production);
10641065
}
10651066

10661067
#endregion
@@ -1701,9 +1702,9 @@ private void VerifyDiagExtContext(DiagnosticExtensionContext resultContext, stri
17011702
//Assert.AreEqual(storage, resultContext.StorageAccountName, "storage account name is not same");
17021703

17031704
XmlDocument doc = new XmlDocument();
1704-
doc.Load("@./da.xml");
1705+
doc.Load("da.xml");
17051706
string inner = Utilities.GetInnerXml(resultContext.WadCfg, "WadCfg");
1706-
Assert.IsTrue(Utilities.CompareWadCfg(inner, doc), "xml is not same");
1707+
Utilities.CompareWadCfg(inner, doc);
17071708
}
17081709

17091710
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
@@ -1120,19 +1120,19 @@ public ExtensionConfigurationInput NewAzureServiceDiagnosticsExtensionConfig
11201120

11211121
// Set-AzureServiceDiagnosticsExtension
11221122
public ManagementOperationContext SetAzureServiceDiagnosticsExtension
1123-
(string service, string storage, string config = null, string[] roles = null, string slot = null)
1123+
(string service, AzureStorageContext storageContext, string config = null, string[] roles = null, string slot = null)
11241124
{
1125-
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storage, config, roles, slot));
1125+
return RunPSCmdletAndReturnFirst<ManagementOperationContext>(new SetAzureServiceDiagnosticsExtensionCmdletInfo(service, storageContext, config, roles, slot));
11261126
}
11271127

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

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

11381138
// 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
@@ -786,24 +786,16 @@ public static string GetInnerXml(string xmlString, string tag)
786786
return xml.GetElementsByTagName(tag)[0].InnerXml;
787787
}
788788

789-
public static bool CompareWadCfg(string wadcfg, XmlDocument daconfig)
789+
public static void CompareWadCfg(string wadcfg, XmlDocument daconfig)
790790
{
791-
try
791+
if (string.IsNullOrWhiteSpace(wadcfg))
792792
{
793-
if (string.IsNullOrWhiteSpace(wadcfg))
794-
{
795-
Assert.IsNull(wadcfg);
796-
}
797-
else
798-
{
799-
string innerXml = daconfig.InnerXml;
800-
Assert.AreEqual(Utilities.FindSubstring(wadcfg, '<', 2), Utilities.FindSubstring(innerXml, '<', 2));
801-
}
802-
return true;
793+
Assert.IsNull(wadcfg);
803794
}
804-
catch
795+
else
805796
{
806-
return false;
797+
string innerXml = daconfig.InnerXml;
798+
StringAssert.Contains(Utilities.FindSubstring(innerXml, '<', 2), Utilities.FindSubstring(wadcfg, '<', 2));
807799
}
808800
}
809801

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>
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
3-
<WadCfg>
4-
<DiagnosticMonitorConfiguration overallQuotaInMB="10000">
5-
<PerformanceCounters scheduledTransferPeriod="PT1M">
6-
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT30S" unit="percent" />
7-
</PerformanceCounters>
8-
</DiagnosticMonitorConfiguration>
9-
</WadCfg>
3+
<WadCfg>
4+
<DiagnosticMonitorConfiguration overallQuotaInMB="25000">
5+
<PerformanceCounters scheduledTransferPeriod="PT1M">
6+
<PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT1M" unit="percent" />
7+
<PerformanceCounterConfiguration counterSpecifier="\Memory\Committed Bytes" sampleRate="PT1M" unit="bytes"/>
8+
</PerformanceCounters>
9+
<EtwProviders>
10+
<EtwEventSourceProviderConfiguration provider="SampleEventSourceWriter" scheduledTransferPeriod="PT5M">
11+
<Event id="1" eventDestination="EnumsTable"/>
12+
<Event id="2" eventDestination="MessageTable"/>
13+
<Event id="3" eventDestination="SetOtherTable"/>
14+
<Event id="4" eventDestination="HighFreqTable"/>
15+
<DefaultEvents eventDestination="DefaultTable" />
16+
</EtwEventSourceProviderConfiguration>
17+
</EtwProviders>
18+
</DiagnosticMonitorConfiguration>
19+
</WadCfg>
1020
</PublicConfig>

0 commit comments

Comments
 (0)