Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ jobs:
if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch')
uses: ./.github/workflows/reusable-test.yml
strategy:
fail-fast: false
matrix:
image:
- 'server2022'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ jobs:

- name: Cache nuget packages
if: steps.skip_check.outputs.should_skip != 'true'
continue-on-error: true
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809
env:
cache-name: cache-nuget-modules
Expand Down
28 changes: 17 additions & 11 deletions docs/remote-vm-setup.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
# Running Scripts on a Remote VM
# Running CI/CD Scripts on a Remote VM

This guide explains how to set up and run eBPF for Windows CI/CD scripts on a remote VM.
This guide explains how to set up and run eBPF for Windows CI/CD scripts on a remote VM using [WinRM](https://learn.microsoft.com/en-us/windows/win32/winrm/portal).

---

## 1. Prepare the Remote VM
## Prepare the Remote VM

Set the execution policy and run the setup script as Administrator:

```powershell
Set-ExecutionPolicy Unrestricted -Force
.\setup_remote_vm.ps1
```
Post reboot run `winrm quickconfig` and take a snapshot of the VM.

---

## 2. Ensure Remote VM is Reachable
## Start WinRM service on the local host
```cmd
sc.exe start winrm
```

## Ensure Remote VM is Reachable

On your host machine, verify that the remote VM is reachable and that WinRM is running by executing:

```powershell
Test-WSMan <remote-vm-ip>
```

If this command fails, ensure the VM is powered on, network connectivity is working, and WinRM is enabled. Running `winrm quickconfig` on the remote VM can help identify and fix common WinRM setup issues.
If this command fails, ensure the VM is powered on, network connectivity is working, and WinRM is enabled.

---

## 2.1. Add Remote VM to Trusted Hosts
## Add Remote VM to Trusted Hosts

On your host machine, allow connections to the remote VM by adding its IP address to the list of trusted hosts:

Expand All @@ -36,7 +42,7 @@ Set-Item WSMan:\localhost\Client\TrustedHosts -Value "<remote-vm-ip>"
```
---

## 3. Store VM Credentials on the Host
## Store VM Credentials on the Host

On your host machine, save the VM administrator and standard user credentials using the `CredentialManager` module:

Expand All @@ -52,7 +58,7 @@ New-StoredCredential -Target TEST_VM_STANDARD -Username <VM Standard User Name>

---

## 4. Prepare the Build Artifacts
## Prepare the Build Artifacts

1. **Navigate to the Build Directory**

Expand All @@ -62,7 +68,7 @@ New-StoredCredential -Target TEST_VM_STANDARD -Username <VM Standard User Name>
cd .\x64\Release
```

2. **Edit `test_execution.json`**
1. **Edit `test_execution.json`**

Update the `VMMap` section to specify your test VM.
Example:
Expand All @@ -86,15 +92,15 @@ New-StoredCredential -Target TEST_VM_STANDARD -Username <VM Standard User Name>

---

## 5. Run the CI/CD Setup Script
## Run the CI/CD Setup Script

1. **Run the Setup Script**

```powershell
.\setup_ebpf_cicd_tests.ps1 -VMIsRemote
```

3. **Run the Test Execution Script**
1. **Run the Test Execution Script**

```powershell
.\execute_ebpf_cicd_tests.ps1 -VMIsRemote
Expand Down
128 changes: 78 additions & 50 deletions scripts/common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ function Wait-TestJobToComplete
$TestVMName = $VMList[0].Name

try {
Write-Host "Running kernel tests on $TestVMName has timed out after one hour" -ForegroundColor Yellow
Write-Host "Running kernel test job on $TestVMName has timed out after $($TestJobTimeout / 60) minutes." -ForegroundColor Yellow
Write-Log "Generating kernel dump due to test timeout on $TestVMName"

Import-Module "$PSScriptRoot\vm_run_tests.psm1" -ArgumentList @(
$false, # ExecuteOnHost
$true, # ExecuteOnVM
$VMIsRemote, # VMIsRemote
$TestVMName, # VMName
$false, # ExecuteOnHost
$true, # ExecuteOnVM
$VMIsRemote, # VMIsRemote
$TestVMName, # VMName
$AdminTestVMCredential.UserName, # Admin
$AdminTestVMCredential.Password, # AdminPassword
$StandardUserTestVMCredential.UserName, # StandardUser
Expand Down Expand Up @@ -742,51 +742,6 @@ function Get-ZipFileFromUrl {
}
}

function Get-LegacyRegressionTestArtifacts
{
$ArifactVersionList = @("0.11.0")
$RegressionTestArtifactsPath = "$pwd\regression"
if (Test-Path -Path $RegressionTestArtifactsPath) {
Remove-Item -Path $RegressionTestArtifactsPath -Recurse -Force
}
mkdir $RegressionTestArtifactsPath

# verify Artifacts' folder presense
if (-not (Test-Path -Path $RegressionTestArtifactsPath)) {
$ErrorMessage = "*** ERROR *** Regression test artifacts folder not found: $RegressionTestArtifactsPath)"
Write-Log $ErrorMessage
throw $ErrorMessage
}

# Download regression test artifacts for each version.
foreach ($ArtifactVersion in $ArifactVersionList)
{
Write-Log "Downloading legacy regression test artifacts for version $ArtifactVersion"
$DownloadPath = "$RegressionTestArtifactsPath\$ArtifactVersion"
mkdir $DownloadPath
$ArtifactName = "v$ArtifactVersion/Build-x64-native-only-Release.$ArtifactVersion.zip"
$ArtifactUrl = "https://github.com/microsoft/ebpf-for-windows/releases/download/" + $ArtifactName

for ($i = 0; $i -lt 5; $i++) {
try {
# Download and extract the artifact.
Get-ZipFileFromUrl -Url $ArtifactUrl -DownloadFilePath "$DownloadPath\artifact.zip" -OutputDir $DownloadPath

# Extract the inner zip file.
Expand-Archive -Path "$DownloadPath\build-NativeOnlyRelease.zip" -DestinationPath $DownloadPath -Force
break
} catch {
Write-Log -TraceMessage "Iteration $i failed to download $ArtifactUrl. Removing $DownloadPath" -ForegroundColor Red
Remove-Item -Path $DownloadPath -Force -ErrorAction Ignore
Start-Sleep -Seconds 5
}
}

Move-Item -Path "$DownloadPath\NativeOnlyRelease\cgroup_sock_addr2.sys" -Destination "$RegressionTestArtifactsPath\cgroup_sock_addr2_$ArtifactVersion.sys" -Force
Remove-Item -Path $DownloadPath -Force -Recurse
}
}

function Get-RegressionTestArtifacts
{
param([Parameter(Mandatory=$True)][string] $Configuration,
Expand Down Expand Up @@ -875,3 +830,76 @@ function Get-PSExec {
Remove-Item -Path $DownloadPath -Force -Recurse -ErrorAction Ignore
return $psExecPath
}

<#
.SYNOPSIS
Invokes a command on a remote or local VM.

.PARAMETER VMName
The name of the VM.

.PARAMETER VMIsRemote
Indicates if the VM is remote.

.PARAMETER Credential
The credential to use for the VM.

.DESCRIPTION
This function invokes a command on a remote or local VM using the specified credentials.

.PARAMETER ScriptBlock
The script block to execute on the VM.

.PARAMETER ArgumentList
The arguments to pass to the script block.

.EXAMPLE
Invoke-CommandOnVM -VMName "MyVM" -VMIsRemote $true -Credential $credential -ScriptBlock { Get-Process }
#>
function Invoke-CommandOnVM {
param(
[Parameter(Mandatory = $true)][string] $VMName,
[Parameter(Mandatory = $false)][bool] $VMIsRemote = $false,
[Parameter(Mandatory = $true)][PSCredential] $Credential,
[Parameter(Mandatory = $true)][ScriptBlock] $ScriptBlock,
[Parameter(Mandatory = $false)][object[]] $ArgumentList = @()
)
Write-Log "Invoking command on VM: $VMName (IsRemote: $VMIsRemote)"
if ($VMIsRemote) {
Invoke-Command -ComputerName $VMName -Credential $Credential -ScriptBlock $ScriptBlock -ArgumentList $ArgumentList -ErrorAction Stop
} else {
Invoke-Command -VMName $VMName -Credential $Credential -ScriptBlock $ScriptBlock -ArgumentList $ArgumentList -ErrorAction Stop
}
}

<#
.SYNOPSIS
Creates a new PowerShell session on a remote or local VM.
.PARAMETER VMName
The name of the VM.
.PARAMETER VMIsRemote
Indicates if the VM is remote.
.PARAMETER Credential
The credential to use for the VM.
.RETURNS
A new PowerShell session object.
.DESCRIPTION
This function creates a new PowerShell session on a remote or local VM using the specified credentials
.EXAMPLE
$session = New-SessionOnVM -VMName "MyVM" -VMIsRemote $true -Credential $credential
#>
function New-SessionOnVM {
param(
[Parameter(Mandatory = $true)][string] $VMName,
[Parameter(Mandatory = $false)][bool] $VMIsRemote = $false,
[Parameter(Mandatory = $true)][PSCredential] $Credential
)
$session = $null
Write-Log "Creating new session on VM: $VMName (IsRemote: $VMIsRemote)"
if ($VMIsRemote) {
$session = New-PSSession -ComputerName $VMName -Credential $Credential -ErrorAction Stop
} else {
$session = New-PSSession -VMName $VMName -Credential $Credential -ErrorAction Stop
}
return $session
}
Loading
Loading