-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add Ubuntu SSH remoting tests CI #12033
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
TravisEz13
merged 33 commits into
PowerShell:master
from
PaulHigin:add-sshremoting-tests-ci
Mar 11, 2020
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c7511cb
Add SSH remoting CI
PaulHigin 4000771
Fix typo
PaulHigin 0db93ed
Add install git to Ubuntu CI
PaulHigin f628155
Update .vsts-ci/sshremoting-tests.yml
PaulHigin f27502e
Fix install git 1
PaulHigin 2b75fd0
Add missing tools module import
PaulHigin b2b1854
Change ubuntu service restart
PaulHigin 50f5e0c
Update ssh install
PaulHigin dbe66ed
fix module path
PaulHigin b1784ee
fix module path
PaulHigin 466d732
change module import
PaulHigin ec235fc
Add tracing
PaulHigin 2b80d1e
Add service start retry
PaulHigin c568afc
Fix service restart
PaulHigin 83b00c5
Fix options restore
PaulHigin 1d2e802
Fix Restore-PSOptions path
PaulHigin d5a5549
Fix Pester test output
PaulHigin 04be24d
fix typo
PaulHigin 5e2d471
Fix test output path
PaulHigin 8318697
Debug 1
PaulHigin 672fa26
Debug 2
PaulHigin b352329
Debug 3
PaulHigin 7f8b2e7
Change results path
PaulHigin 99cb598
Fix result publish to use build artifacts directory
PaulHigin b6faa0e
Add more New-PSSession tests
PaulHigin a9e6e1c
Remove User test
PaulHigin 070b6ba
Remove env:USER
PaulHigin 56d5fab
Add API tests
PaulHigin 671c2ba
Fix type for Subsytem API test
PaulHigin 7082e8c
Update .vsts-ci/sshremoting-tests.yml
PaulHigin c4a7bf4
Update .vsts-ci/sshremoting-tests.yml
PaulHigin 704e849
Update .vsts-ci/sshremoting-tests.yml
PaulHigin 4a3ebe3
Apply suggestions from code review
TravisEz13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| name: PR-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr) | ||
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
PaulHigin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| trigger: | ||
| # Batch merge builds together while a merge build is running | ||
| batch: true | ||
| branches: | ||
| include: | ||
| - master | ||
| - release* | ||
| - feature* | ||
| paths: | ||
| include: | ||
| - '/src/System.Management.Automation/engine/*' | ||
| - '/test/SSHRemoting/*' | ||
| pr: | ||
| branches: | ||
| include: | ||
| - master | ||
| - release* | ||
| - feature* | ||
| paths: | ||
| include: | ||
| - '/src/System.Management.Automation/engine/*' | ||
| - '/test/SSHRemoting/*' | ||
|
|
||
| variables: | ||
| DOTNET_CLI_TELEMETRY_OPTOUT: 1 | ||
| POWERSHELL_TELEMETRY_OPTOUT: 1 | ||
| # Avoid expensive initialization of dotnet cli, see: https://donovanbrown.com/post/Stop-wasting-time-during-NET-Core-builds | ||
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | ||
| __SuppressAnsiEscapeSequences: 1 | ||
|
|
||
| resources: | ||
| - repo: self | ||
| clean: true | ||
| jobs: | ||
| - job: SSHRemotingTests | ||
| container: mcr.microsoft.com/powershell/test-deps:ubuntu-18.04 | ||
| displayName: SSH Remoting Tests | ||
|
|
||
| steps: | ||
| - pwsh: | | ||
| Get-ChildItem -Path env: | ||
| displayName: Capture Environment | ||
| condition: succeededOrFailed() | ||
|
|
||
| - pwsh: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))" | ||
| displayName: Set Build Name for Non-PR | ||
| condition: ne(variables['Build.Reason'], 'PullRequest') | ||
|
|
||
| - template: /tools/releaseBuild/azureDevOps/templates/insert-nuget-config-azfeed.yml | ||
|
|
||
| - pwsh: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y git | ||
| displayName: Install Github | ||
| condition: succeeded() | ||
|
|
||
| - pwsh: | | ||
| Import-Module .\tools\ci.psm1 | ||
| Invoke-CIInstall -SkipUser | ||
| displayName: Bootstrap | ||
| condition: succeededOrFailed() | ||
|
|
||
| - pwsh: | | ||
| Import-Module .\tools\ci.psm1 | ||
| Invoke-CIBuild | ||
| displayName: Build | ||
| condition: succeeded() | ||
|
|
||
| - pwsh: | | ||
| Import-Module .\tools\ci.psm1 | ||
| Restore-PSOptions | ||
| $options = (Get-PSOptions) | ||
| Import-Module .\test\tools\Modules\HelpersRemoting | ||
| Install-SSHRemoting -PowerShellFilePath $options.Output | ||
| displayName: Install SSH Remoting | ||
| condition: succeeded() | ||
|
|
||
| - pwsh: | | ||
| Import-Module .\tools\ci.psm1 | ||
| Restore-PSOptions | ||
| $options = (Get-PSOptions) | ||
| Import-Module .\build.psm1 | ||
| Start-PSPester -Path test/SSHRemoting -powershell $options.Output -OutputFile "$PWD/sshTestResults.xml" | ||
| displayName: Test | ||
| condition: succeeded() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Describe "SSHRemoting Basic Tests" -tags CI { | ||
|
|
||
| # SSH remoting is set up to automatically authenticate current user via SSH keys | ||
| # All tests connect back to localhost machine | ||
|
|
||
| function VerifySession { | ||
| param ( | ||
| [System.Management.Automation.Runspaces.PSSession] $session | ||
| ) | ||
|
|
||
| $session.State | Should -BeExactly 'Opened' | ||
| $session.ComputerName | Should -BeExactly 'localhost' | ||
| $session.Transport | Should -BeExactly 'SSH' | ||
| Invoke-Command -Session $session -ScriptBlock { whoami } | Should -BeExactly $(whoami) | ||
| $psRemoteVersion = Invoke-Command -Session $session -ScriptBlock { $PSSenderInfo.ApplicationArguments.PSVersionTable.PSVersion } | ||
| $psRemoteVersion.Major | Should -BeExactly $PSVersionTable.PSVersion.Major | ||
| $psRemoteVersion.Minor | Should -BeExactly $PSVersionTable.PSVersion.Minor | ||
| } | ||
|
|
||
| Context "New-PSSession Tests" { | ||
|
|
||
| AfterEach { | ||
| if ($script:session -ne $null) { Remove-PSSession -session $script:session } | ||
| if ($script:sessions -ne $null) { Remove-PSSession -session $script:sessions } | ||
| } | ||
|
|
||
| It "Verifies new connection with implicit current User" { | ||
| $script:session = New-PSSession -HostName localhost -ErrorVariable err | ||
| $err | Should -HaveCount 0 | ||
| VerifySession $script:session | ||
| } | ||
|
|
||
| It "Verifies new connection with explicit User parameter" { | ||
| $script:session = New-PSSession -HostName localhost -UserName (whoami) -ErrorVariable err | ||
| $err | Should -HaveCount 0 | ||
| VerifySession $script:session | ||
| } | ||
|
|
||
| It "Verifies explicit Name parameter" { | ||
| $sessionName = 'TestSessionNameA' | ||
| $script:session = New-PSSession -HostName localhost -Name $sessionName -ErrorVariable err | ||
| $err | Should -HaveCount 0 | ||
| VerifySession $script:session | ||
| $script:session.Name | Should -BeExactly $sessionName | ||
| } | ||
|
|
||
| It "Verifies explicit Port parameter" { | ||
| $portNum = 22 | ||
| $script:session = New-PSSession -HostName localhost -Port $portNum -ErrorVariable err | ||
| $err | Should -HaveCount 0 | ||
| VerifySession $script:session | ||
| } | ||
|
|
||
| It "Verifies explicit Subsystem parameter" { | ||
| $portNum = 22 | ||
| $subSystem = 'powershell' | ||
| $script:session = New-PSSession -HostName localhost -Port $portNum -SubSystem $subSystem -ErrorVariable err | ||
| $err | Should -HaveCount 0 | ||
| VerifySession $script:session | ||
| } | ||
|
|
||
| It "Verifies explicit KeyFilePath parameter" { | ||
| $keyFilePath = "$HOME/.ssh/id_rsa" | ||
| $portNum = 22 | ||
| $subSystem = 'powershell' | ||
| $script:session = New-PSSession -HostName localhost -Port $portNum -SubSystem $subSystem -KeyFilePath $keyFilePath -ErrorVariable err | ||
| $err | Should -HaveCount 0 | ||
| VerifySession $script:session | ||
| } | ||
|
|
||
| It "Verifies SSHConnection hash table parameters" { | ||
| $sshConnection = @( | ||
| @{ | ||
| HostName = 'localhost' | ||
| UserName = whoami | ||
| Port = 22 | ||
| KeyFilePath = "$HOME/.ssh/id_rsa" | ||
| Subsystem = 'powershell' | ||
| }, | ||
| @{ | ||
| HostName = 'localhost' | ||
| KeyFilePath = "$HOME/.ssh/id_rsa" | ||
| Subsystem = 'powershell' | ||
| }) | ||
| $script:sessions = New-PSSession -SSHConnection $sshConnection -Name 'Connection1','Connection2' -ErrorVariable err | ||
| $err | Should -HaveCount 0 | ||
| $script:sessions | Should -HaveCount 2 | ||
| $script:sessions[0].Name | Should -BeLike 'Connection*' | ||
| $script:sessions[1].Name | Should -BeLike 'Connection*' | ||
| VerifySession $script:sessions[0] | ||
| VerifySession $script:sessions[1] | ||
| } | ||
| } | ||
|
|
||
| function VerifyRunspace { | ||
| param ( | ||
| [runspace] $rs | ||
| ) | ||
|
|
||
| $rs.RunspaceStateInfo.State | Should -BeExactly 'Opened' | ||
| $rs.RunspaceAvailability | Should -BeExactly 'Available' | ||
| $rs.RunspaceIsRemote | Should -BeTrue | ||
| $ps = [powershell]::Create() | ||
| try | ||
| { | ||
| $ps.Runspace = $rs | ||
| $psRemoteVersion = $ps.AddScript('$PSSenderInfo.ApplicationArguments.PSVersionTable.PSVersion').Invoke() | ||
| $psRemoteVersion.Major | Should -BeExactly $PSVersionTable.PSVersion.Major | ||
| $psRemoteVersion.Minor | Should -BeExactly $PSVersionTable.PSVersion.Minor | ||
|
|
||
| $ps.Commands.Clear() | ||
| $ps.AddScript('whoami').Invoke() | Should -BeExactly $(whoami) | ||
| } | ||
| finally | ||
| { | ||
| $ps.Dispose() | ||
| } | ||
| } | ||
|
|
||
| Context "SSH Remoting API Tests" { | ||
|
|
||
| AfterEach { | ||
| if ($script:rs -ne $null) { $script:rs.Dispose() } | ||
| } | ||
|
|
||
| $testCases = @( | ||
| @{ | ||
| testName = 'Verifies connection with implicit user' | ||
| UserName = $null | ||
| ComputerName = 'localhost' | ||
| KeyFilePath = $null | ||
| Port = 0 | ||
| Subsystem = $null | ||
| }, | ||
| @{ | ||
| testName = 'Verifies connection with UserName' | ||
| UserName = whoami | ||
| ComputerName = 'localhost' | ||
| KeyFilePath = $null | ||
| Port = 0 | ||
| Subsystem = $null | ||
| }, | ||
| @{ | ||
| testName = 'Verifies connection with KeyFilePath' | ||
| UserName = whoami | ||
| ComputerName = 'localhost' | ||
| KeyFilePath = "$HOME/.ssh/id_rsa" | ||
| Port = 0 | ||
| Subsystem = $null | ||
| }, | ||
| @{ | ||
| testName = 'Verifies connection with Port specified' | ||
| UserName = whoami | ||
| ComputerName = 'localhost' | ||
| KeyFilePath = "$HOME/.ssh/id_rsa" | ||
| Port = 22 | ||
| Subsystem = $null | ||
| }, | ||
| @{ | ||
| testName = 'Verifies connection with Subsystem specified' | ||
| UserName = whoami | ||
| ComputerName = 'localhost' | ||
| KeyFilePath = "$HOME/.ssh/id_rsa" | ||
| Port = 22 | ||
| Subsystem = 'powershell' | ||
| } | ||
| ) | ||
|
|
||
| It "<testName>" -TestCases $testCases { | ||
| param ( | ||
| $UserName, | ||
| $ComputerName, | ||
| $KeyFilePath, | ||
| $Port, | ||
| $SubSystem | ||
| ) | ||
|
|
||
| $ci = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new($UserName, $ComputerName, $KeyFilePath, $Port, $Subsystem) | ||
| $script:rs = [runspacefactory]::CreateRunspace($host, $ci) | ||
| $script:rs.Open() | ||
| VerifyRunspace $script:rs | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.