3232using Microsoft . WindowsAzure . Commands . ServiceManagement . Extensions ;
3333using Microsoft . WindowsAzure . Commands . ServiceManagement . Model ;
3434using 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
3639namespace 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 )
0 commit comments