Skip to content

Commit

Permalink
Refactor all deployments to use the MSI package. (microsoft#3284)
Browse files Browse the repository at this point in the history
* draft

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* test

* wip

* wip

* test

* test

* wip

* test

* wip

* wip

* wip

* test

* wip

* wip

* fix debug installation

* update VM install doc

* wip

* wip

* wip

* wip

* wip

* improve msi log readability

* wip

* debug

* nits

* feedback

* nl

* updates

* add extra stop-check

* wip

* wip

* nit

* fix

* doc

* exclude doc

* sync
  • Loading branch information
gtrevi authored Mar 21, 2024
1 parent 22b7adc commit 1eaa568
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 203 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT

# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request,
Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT

repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.3
Expand Down
5 changes: 2 additions & 3 deletions scripts/check_msi_installation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ function Install-MsiPackage {

$res = $true

$arguments = "/i $MsiPath /qn /norestart /log msi-install.log $MsiAdditionalArguments"
$arguments = "/i $MsiPath /qn /norestart /l*v msi-install.log $MsiAdditionalArguments"
Write-Host "Installing MSI package with arguments: '$arguments'..."
$process = Start-Process -FilePath msiexec.exe -ArgumentList $arguments -Wait -PassThru

if ($process.ExitCode -eq 0) {
Write-Host "Installation successful!"
} else {
Expand All @@ -105,7 +104,7 @@ function Uninstall-MsiPackage {

Write-Host "Uninstalling MSI package..."
$res = $true
$process = Start-Process -FilePath msiexec.exe -ArgumentList "/x $MsiPath /qn /norestart /log msi-uninstall.log" -Wait -PassThru
$process = Start-Process -FilePath msiexec.exe -ArgumentList "/x $MsiPath /qn /norestart /l*v msi-uninstall.log" -Wait -PassThru
if ($process.ExitCode -eq 0) {
Write-Host "Uninstallation successful!"
} else {
Expand Down
8 changes: 8 additions & 0 deletions scripts/cleanup_ebpf_cicd_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop
# Load other utility modules.
Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue
Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue
Import-Module .\install_ebpf.psm1 -ArgumentList ($WorkingDirectory, $LogFileName) -Force -WarningAction SilentlyContinue

# Read the test execution json.
$TestExecutionConfig = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json
$VMList = $TestExecutionConfig.VMMap.$SelfHostedRunnerName

# Uninstall eBPF Components on the test VM.
foreach($VM in $VMList) {
$VMName = $VM.Name
Write-Host "Uninstalling eBPF components on VM $VMName..."
Uninstall-eBPFComponentsOnVM -VMName $VMname -ErrorAction Stop
}

# Import logs from VMs.
Import-ResultsFromVM -VMList $VMList -KmTracing $KmTracing

Expand Down
86 changes: 61 additions & 25 deletions scripts/config_test_vm.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function Export-BuildArtifactsToVMs
&tar @("cfz", "$tempFileName", "*")
Write-Log "Created $tempFileName containing files in $pwd"

# Copy artifacts to the given VM list.
foreach($VM in $VMList) {
$VMName = $VM.Name
$TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword
Expand Down Expand Up @@ -210,6 +211,52 @@ function Export-BuildArtifactsToVMs
Remove-Item -Force $tempFileName
}

#
# Install eBPF components on VM.
#

function Install-eBPFComponentsOnVM
{
param([parameter(Mandatory=$true)][string] $VMName,
[parameter(Mandatory=$true)][bool] $KmTracing,
[parameter(Mandatory=$true)][string] $KmTraceType)

Write-Log "Installing eBPF components on $VMName"
$TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword

Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock {
param([Parameter(Mandatory=$True)] [string] $WorkingDirectory,
[Parameter(Mandatory=$True)] [string] $LogFileName,
[Parameter(Mandatory=$true)] [bool] $KmTracing,
[Parameter(Mandatory=$true)] [string] $KmTraceType)
$WorkingDirectory = "$env:SystemDrive\$WorkingDirectory"
Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue
Import-Module $WorkingDirectory\install_ebpf.psm1 -ArgumentList ($WorkingDirectory, $LogFileName) -Force -WarningAction SilentlyContinue

Install-eBPFComponents -KmTracing $KmTracing -KmTraceType $KmTraceType -KMDFVerifier $true -ErrorAction Stop
} -ArgumentList ("eBPF", $LogFileName, $KmTracing, $KmTraceType) -ErrorAction Stop
Write-Log "eBPF components installed on $VMName" -ForegroundColor Green
}

function Uninstall-eBPFComponentsOnVM
{
param([parameter(Mandatory=$true)][string] $VMName)

Write-Log "Unnstalling eBPF components on $VMName"
$TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword

Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock {
param([Parameter(Mandatory=$True)] [string] $WorkingDirectory,
[Parameter(Mandatory=$True)] [string] $LogFileName)
$WorkingDirectory = "$env:SystemDrive\$WorkingDirectory"
Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue
Import-Module $WorkingDirectory\install_ebpf.psm1 -ArgumentList ($WorkingDirectory, $LogFileName) -Force -WarningAction SilentlyContinue

Uninstall-eBPFComponents
} -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop
Write-Log "eBPF components uninstalled on $VMName" -ForegroundColor Green
}

function ArchiveKernelModeDumpOnVM
{
param (
Expand Down Expand Up @@ -331,7 +378,6 @@ function Import-ResultsFromVM
if (!(Test-Path ".\TestLogs\$VMName\Logs")) {
New-Item -ItemType Directory -Path ".\TestLogs\$VMName\Logs"
}

$VMTemp = Invoke-Command -Session $VMSession -ScriptBlock {return $Env:TEMP}
Write-Log ("Copy $LogFileName from $VMTemp on $VMName to $pwd\TestLogs")
Copy-Item `
Expand Down Expand Up @@ -436,30 +482,9 @@ function Import-ResultsFromVM
Move-Item "$env:TEMP\$LogFileName" -Destination ".\TestLogs" -Force -ErrorAction Ignore 2>&1 | Write-Log
}

function Install-eBPFComponentsOnVM
{
param([parameter(Mandatory=$true)][string] $VMName,
[parameter(Mandatory=$true)][bool] $KmTracing,
[parameter(Mandatory=$true)][string] $KmTraceType)

Write-Log "Installing eBPF components on $VMName"
$TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword

Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock {
param([Parameter(Mandatory=$True)] [string] $WorkingDirectory,
[Parameter(Mandatory=$True)] [string] $LogFileName,
[Parameter(Mandatory=$true)] [bool] $KmTracing,
[Parameter(Mandatory=$true)] [string] $KmTraceType)
$WorkingDirectory = "$env:SystemDrive\$WorkingDirectory"
Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue
Import-Module $WorkingDirectory\install_ebpf.psm1 -ArgumentList ($WorkingDirectory, $LogFileName) -Force -WarningAction SilentlyContinue

Install-eBPFComponents -KmTracing $KmTracing -KmTraceType $KmTraceType -KMDFVerifier $true
Enable-KMDFVerifier
} -ArgumentList ("eBPF", $LogFileName, $KmTracing, $KmTraceType) -ErrorAction Stop
Write-Log "eBPF components installed on $VMName" -ForegroundColor Green
}

#
# Configure network adapters on VMs.
#
function Initialize-NetworkInterfacesOnVMs
{
param([parameter(Mandatory=$true)] $VMMap)
Expand Down Expand Up @@ -535,3 +560,14 @@ function Get-Duonic {
Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\notmyfault64.exe" -Destination $pwd -Force
Remove-Item -Path $DownloadPath -Force -Recurse
}

# Download the Visual C++ Redistributable.
function Get-VCRedistributable {
$url = "https://aka.ms/vs/16/release/vc_redist.x64.exe"
$DownloadPath = "$pwd\vc-redist"
mkdir $DownloadPath
Write-Host "Downloading Visual C++ Redistributable from $url to $DownloadPath"
Invoke-WebRequest -Uri $url -OutFile "$DownloadPath\vc_redist.x64.exe"
Move-Item -Path "$DownloadPath\vc_redist.x64.exe" -Destination $pwd -Force
Remove-Item -Path $DownloadPath -Force -Recurse
}
4 changes: 2 additions & 2 deletions scripts/execute_ebpf_cicd_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction
$StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop

# Load other utility modules.
Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue
Import-Module .\vm_run_tests.psm1 `
Import-Module $PSScriptRoot\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue
Import-Module $PSScriptRoot\vm_run_tests.psm1 `
-Force `
-ArgumentList (
$AdminTestVMCredential.UserName,
Expand Down
Loading

0 comments on commit 1eaa568

Please sign in to comment.