@@ -723,296 +723,6 @@ function Test-EnableContainerContinuousDeploymentAndGetUrl
723
723
}
724
724
}
725
725
726
- <#
727
- . SYNOPSIS
728
- Tests issuing an EnterPsSession command to a Windows container web app.
729
- . DESCRIPTION
730
- SmokeTest
731
- #>
732
- function Test-WindowsContainerCanIssueWebAppPSSession
733
- {
734
- # Setup
735
- $rgname = Get-ResourceGroupName
736
- $wname = Get-WebsiteName
737
- $location = Get-WebLocation
738
- $whpName = Get-WebHostPlanName
739
- $tier = " PremiumContainer"
740
- $apiversion = " 2015-08-01"
741
- $resourceType = " Microsoft.Web/sites"
742
- $containerImageName = " dotnetsdktesting.azurecr.io/webapplication3:latest"
743
- $containerRegistryUrl = " https://dotnetsdktesting.azurecr.io"
744
- $containerRegistryUser = " DotNetSDKTesting"
745
- $pass = " NuO4xVus40R/wukMM9i1OdMIohADB=oR"
746
- $containerRegistryPassword = ConvertTo-SecureString - String $pass - AsPlainText - Force
747
- $dockerPrefix = " DOCKER|"
748
-
749
- try
750
- {
751
-
752
- Write-Debug " Creating app service plan..."
753
-
754
- # Setup
755
- New-AzResourceGroup - Name $rgname - Location $location
756
- $serverFarm = New-AzAppServicePlan - ResourceGroupName $rgname - Name $whpName - Location $location - Tier $tier - WorkerSize Large - HyperV
757
-
758
- Write-Debug " App service plan created"
759
-
760
- Write-Debug " Creating web app plan..."
761
-
762
- # Create new web app
763
- $job = New-AzWebApp - ResourceGroupName $rgname - Name $wname - Location $location - AppServicePlan $whpName - ContainerImageName $containerImageName - ContainerRegistryUrl $containerRegistryUrl - ContainerRegistryUser $containerRegistryUser - ContainerRegistryPassword $containerRegistryPassword - AsJob
764
- $job | Wait-Job
765
- $actual = $job | Receive-Job
766
-
767
- Write-Debug " Webapp created"
768
-
769
- # Assert
770
- Assert-AreEqual $wname $actual.Name
771
- Assert-AreEqual $serverFarm.Id $actual.ServerFarmId
772
- # Get new web app
773
- $result = Get-AzWebApp - ResourceGroupName $rgname - Name $wname
774
-
775
- Write-Debug " Webapp retrieved"
776
-
777
- Write-Debug " Validating web app properties..."
778
-
779
- # Assert
780
- Assert-AreEqual $wname $result.Name
781
- Assert-AreEqual $serverFarm.Id $result.ServerFarmId
782
- Assert-AreEqual $true $result.IsXenon
783
- Assert-AreEqual ($dockerPrefix + $containerImageName ) $result.SiteConfig.WindowsFxVersion
784
-
785
- $actualAppSettings = @ {}
786
-
787
- foreach ($kvp in $result.SiteConfig.AppSettings )
788
- {
789
- $actualAppSettings [$kvp.Name ] = $kvp.Value
790
- }
791
-
792
- # Validate Appsettings
793
-
794
- $expectedAppSettings = @ {}
795
- $expectedAppSettings [" DOCKER_REGISTRY_SERVER_URL" ] = $containerRegistryUrl ;
796
- $expectedAppSettings [" DOCKER_REGISTRY_SERVER_USERNAME" ] = $containerRegistryUser ;
797
- $expectedAppSettings [" DOCKER_REGISTRY_SERVER_PASSWORD" ] = $pass ;
798
-
799
- foreach ($key in $expectedAppSettings.Keys )
800
- {
801
- Assert-True {$actualAppSettings.Keys -contains $key }
802
- Assert-AreEqual $actualAppSettings [$key ] $expectedAppSettings [$key ]
803
- }
804
-
805
- Write-Debug " Enabling Win-RM..."
806
-
807
- # Adding Appsetting: enabling WinRM
808
- $actualAppSettings [" CONTAINER_WINRM_ENABLED" ] = " 1"
809
- $webApp = Set-AzWebApp - ResourceGroupName $rgname - Name $wName - AppSettings $actualAppSettings
810
-
811
- # Validating that the client can at least issue the EnterPsSession command.
812
- # This will validate that this cmdlet will run succesfully in Cloud Shell.
813
- # If the current Operating System is Windows and the current WSMAN settings will not allow the user
814
- # to connect (for example: invalid Trusted Hosts, Basic Auth not enabled) this command will issue a Warning instructing the user
815
- # to fix WSMAN settings. It will not attempt to run EnterPsSession.
816
- #
817
- # If the current is not Windows, this command will not attempt to validate WSMAN settings and
818
- # just try to run EnterPsSession if the current PsCore version is 6.1.0.0 or subsequent. EnterPsSession using WinRM is available in Cloud Shell
819
- #
820
- # We need a real Windows Container app running to fully validate the returned PsSession object, which is not
821
- # possible in 'Playback' mode.
822
- #
823
- # This assert at least verifies that the EnterPsSession command is attempted and that the behavior is the expected
824
- New-AzWebAppContainerPSSession - ResourceGroupName $rgname - Name $wname - WarningVariable wv - WarningAction SilentlyContinue - ErrorAction SilentlyContinue - Force
825
-
826
-
827
- if ((Get-WebsitesTestMode ) -ne ' Playback' )
828
- {
829
- # Message for Recording mode
830
- $message = " Connecting to remote server $wname .azurewebsites.net failed with the following error message : The connection to the specified remote host was refused."
831
- $resultError = $Error [0 ] -like " *$ ( $message ) *"
832
- Write-Debug " Expected Message: $message "
833
- }
834
- else
835
- {
836
- # Three possible error messages in Playback mode.
837
- $messageDNS = " Connecting to remote server $wname .azurewebsites.net failed with the following error message : The WinRM client cannot process the request because the server name cannot be resolved"
838
- $messageUnavailable = " Connecting to remote server $wname .azurewebsites.net failed with the following error message : The WinRM client sent a request to an HTTP server and got a response saying the requested HTTP URL was not available."
839
- $messagePsVersionNotSupported = " Remote Powershell sessions into Windows Containers on App Service from this version of PowerShell is not supported." ;
840
- $messageMIResulFailed = " Connecting to remote server $wname .azurewebsites.net failed with the following error message : MI_RESULT_FAILED" ;
841
- $messageWSManNotInstalled = " This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system" ;
842
-
843
- # One possible warning message in Playback mode.
844
- $messageWSMANNotConfigured = " Your current WSMAN Trusted Hosts settings will prevent you from connecting to your Container Web App" ;
845
-
846
- $resultError = ($Error [0 ] -like " *$ ( $messageDNS ) *" ) -or
847
- ($Error [0 ] -like " *$ ( $messageUnavailable ) *" ) -or
848
- ($Error [0 ] -like " *$ ( $messageWSMANNotConfigured ) *" ) -or
849
- ($Error [0 ] -like " *$ ( $messagePsVersionNotSupported ) *" ) -or
850
- ($Error [0 ] -like " *$ ( $messageMIResulFailed ) *" ) -or
851
- ($Error [0 ] -like " *$ ( $messageWSManNotInstalled ) *" )
852
-
853
- $resultWarning = ($wv [0 ] -like " *$ ( $messageWSMANNotConfigured ) *" )
854
-
855
- Write-Debug " Expected error message 1: $messageDNS "
856
- Write-Debug " Expected error message 2: $messageUnavailable "
857
- Write-Debug " Expected error message 3: $messagePsVersionNotSupported "
858
- Write-Debug " Expected error message 4: $messageMIResulFailed "
859
- Write-Debug " Expected error message 5: $messageWSManNotInstalled "
860
-
861
- Write-Debug " Expected Warning message 1: $messageWSMANNotConfigured "
862
-
863
-
864
- }
865
-
866
- Write-Debug " Error: $Error [0]"
867
- Write-Debug " Warnings: $wv "
868
-
869
- Write-Debug " Printing PsVersion"
870
- foreach ($key in $PsVersionTable.Keys )
871
- {
872
- Write-Debug " $key "
873
- foreach ($v in $PsVersionTable [$key ])
874
- {
875
- Write-Debug " $v "
876
- }
877
- }
878
-
879
-
880
- If (! $resultError -or ! $resultWarning )
881
- {
882
- Write-Output " expected error $ ( $message ) , actual error $ ( $Error [0 ]) "
883
- Write-Output " Warnings: $wv "
884
- }
885
- Assert-True {$resultError -or $resultWarning }
886
- }
887
- finally
888
- {
889
- # Cleanup
890
- Remove-AzWebApp - ResourceGroupName $rgname - Name $wname - Force
891
- Remove-AzAppServicePlan - ResourceGroupName $rgname - Name $whpName - Force
892
- Remove-AzResourceGroup - Name $rgname - Force
893
- }
894
- }
895
-
896
- <#
897
- . SYNOPSIS
898
- Tests that a PsSession can be established to a Windows Container App. It is expected to fail in Playback mode
899
- . DESCRIPTION
900
- SmokeTest
901
- #>
902
- function Test-WindowsContainerWebAppPSSessionOpened
903
- {
904
- # Setup
905
- $rgname = Get-ResourceGroupName
906
- $wname = Get-WebsiteName
907
- $location = Get-WebLocation
908
- $whpName = Get-WebHostPlanName
909
- $tier = " PremiumContainer"
910
- $apiversion = " 2015-08-01"
911
- $resourceType = " Microsoft.Web/sites"
912
- $containerImageName = " mcr.microsoft.com/azure-app-service/samples/aspnethelloworld:latest"
913
- $containerRegistryUrl = " https://mcr.microsoft.com"
914
- $containerRegistryUser = " testregistry"
915
- $pass = " 7Dxo9p79Ins2K3ZU"
916
- $containerRegistryPassword = ConvertTo-SecureString - String $pass - AsPlainText - Force
917
- $dockerPrefix = " DOCKER|"
918
-
919
- try
920
- {
921
-
922
- Write-Debug " Creating app service plan..."
923
-
924
- # Setup
925
- New-AzResourceGroup - Name $rgname - Location $location
926
- $serverFarm = New-AzAppServicePlan - ResourceGroupName $rgname - Name $whpName - Location $location - Tier $tier - WorkerSize Large - HyperV
927
-
928
- Write-Debug " App service plan created"
929
-
930
- Write-Debug " Creating web app plan..."
931
-
932
- # Create new web app
933
- $job = New-AzWebApp - ResourceGroupName $rgname - Name $wname - Location $location - AppServicePlan $whpName - ContainerImageName $containerImageName - ContainerRegistryUrl $containerRegistryUrl - ContainerRegistryUser $containerRegistryUser - ContainerRegistryPassword $containerRegistryPassword - AsJob
934
- $job | Wait-Job
935
- $actual = $job | Receive-Job
936
-
937
- Write-Debug " Webapp created"
938
-
939
- # Assert
940
- Assert-AreEqual $wname $actual.Name
941
- Assert-AreEqual $serverFarm.Id $actual.ServerFarmId
942
- # Get new web app
943
- $result = Get-AzWebApp - ResourceGroupName $rgname - Name $wname
944
-
945
- Write-Debug " Webapp retrieved"
946
-
947
- Write-Debug " Validating web app properties..."
948
-
949
- # Assert
950
- Assert-AreEqual $wname $result.Name
951
- Assert-AreEqual $serverFarm.Id $result.ServerFarmId
952
- Assert-AreEqual $true $result.IsXenon
953
- Assert-AreEqual ($dockerPrefix + $containerImageName ) $result.SiteConfig.WindowsFxVersion
954
-
955
- $actualAppSettings = @ {}
956
-
957
- foreach ($kvp in $result.SiteConfig.AppSettings )
958
- {
959
- $actualAppSettings [$kvp.Name ] = $kvp.Value
960
- }
961
-
962
- # Validate Appsettings
963
-
964
- $expectedAppSettings = @ {}
965
- $expectedAppSettings [" DOCKER_REGISTRY_SERVER_URL" ] = $containerRegistryUrl ;
966
- $expectedAppSettings [" DOCKER_REGISTRY_SERVER_USERNAME" ] = $containerRegistryUser ;
967
- $expectedAppSettings [" DOCKER_REGISTRY_SERVER_PASSWORD" ] = $pass ;
968
-
969
- foreach ($key in $expectedAppSettings.Keys )
970
- {
971
- Assert-True {$actualAppSettings.Keys -contains $key }
972
- Assert-AreEqual $actualAppSettings [$key ] $expectedAppSettings [$key ]
973
- }
974
-
975
- Write-Debug " Enabling Win-RM..."
976
-
977
- # Adding Appsetting: enabling WinRM
978
- $actualAppSettings [" CONTAINER_WINRM_ENABLED" ] = " 1"
979
- $webApp = Set-AzWebApp - ResourceGroupName $rgname - Name $wName - AppSettings $actualAppSettings
980
-
981
- $status = PingWebApp($webApp )
982
- Write-Debug " Just pinged the web app"
983
- Write-Debug " Status: $status "
984
-
985
- # Wait for the container app to return 200.
986
- # Windows Container apps return 503 when starting up. Usualy takes 8-9 minutes.
987
- # Timing out at 15 minutes
988
-
989
- $count = 0
990
- while (($status -like " ServiceUnavailable" ) -and $count -le 15 )
991
- {
992
- Wait-Seconds 60
993
- $status = PingWebApp($webApp )
994
- Write-Debug $count
995
- $count ++
996
- }
997
-
998
- # Asserting status of the last ping to the web app
999
- Assert-AreEqual $status " 200"
1000
-
1001
- $ps_session = New-AzWebAppContainerPSSession - ResourceGroupName $rgname - Name $wname - Force
1002
-
1003
- Write-Debug " After PSSession"
1004
-
1005
- Assert-AreEqual $ps_session.ComputerName $wname " .azurewebsites.net"
1006
- Assert-AreEqual $ps_session.State " Opened"
1007
- }
1008
- finally
1009
- {
1010
- # Cleanup
1011
- Remove-AzWebApp - ResourceGroupName $rgname - Name $wname - Force
1012
- Remove-AzAppServicePlan - ResourceGroupName $rgname - Name $whpName - Force
1013
- Remove-AzResourceGroup - Name $rgname - Force
1014
- }
1015
- }
1016
726
1017
727
<#
1018
728
. SYNOPSIS
0 commit comments