Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewige committed Dec 17, 2024
1 parent 7948896 commit 91f3a84
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ jobs:
post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true
name: driver_native_only_ws2022
build_artifact: Build-x64-native-only
environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]'
environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]'
# driver test copies dumps to testlog folder.
gather_dumps: false
# driver tests manually gather code coverage
Expand All @@ -284,7 +284,7 @@ jobs:
post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true
name: regression_driver_ws2022
build_artifact: Build-x64
environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]'
environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]'
# driver test copies dumps to testlog folder.
gather_dumps: false
# driver tests manually gather code coverage
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ jobs:
if: contains(inputs.environment, 'self-hosted')
run: |
powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1"
# powershell.exe "Get-NetAdapter"
# powershell.exe "Get-VMSwitch"
# powershell.exe "Get-NetAdapter"
# powershell.exe "Get-VMSwitch"
# powershell.exe "Get-VM"
- name: Print CPU information
run:
Expand Down
68 changes: 45 additions & 23 deletions 1es/Setup_orig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ param(
[Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\',
[Parameter(Mandatory=$False)][string]$WorkingPath='.\working',
[Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds',
[Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch',

[Parameter(Mandatory=$False)][string]$VMCpuCount=4,
[Parameter(Mandatory=$False)][string]$VMMemory=4096MB
Expand All @@ -28,13 +27,29 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) {
throw "VHD directory not found at $BaseVhdDirPath"
}

# Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal'
Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal'
Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External'
# Stored credentials doesn't seem to be working...
# Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword
# Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword
Create-DirectoryIfNotExists -Path $WorkingPath

# Unzip any VHDs
$zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip
foreach ($zipFile in $zipFiles) {
$outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName
if (-not (Test-Path -Path $outDir)) {
Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir

# Move the VHDs to the base directory
$vhdFiles = Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore
$vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore
foreach ($vhdFile in $vhdFiles) {
Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath
}
}
}

# Read the input VHDs
$vhds = @((Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd))
$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx
Expand All @@ -43,27 +58,34 @@ if ($vhds.Count -eq 0) {
}

for ($i = 0; $i -lt $vhds.Count; $i++) {
$vhd = $vhds[$i]
Log-Message -Message "Processing VHD: $($vhd.FullName)"
$vmName = "runner_vm"
if ($i -gt 0) {
$vmName += "_$i"
}
$outVMPath = Join-Path -Path $WorkingPath -ChildPath $VMName
try {
$vhd = $vhds[$i]
Log-Message -Message "Processing VHD: $($vhd.FullName)"
$vmName = "runner_vm"
if ($i -gt 0) {
$vmName += "_$i"
}
$outVMPath = Join-Path -Path $WorkingPath -ChildPath $VMName

Create-VM `
-VmName $vmName `
-VhdPath $vhd.FullName `
-VmStoragePath $outVMPath `
-VMMemory $VMMemory `
-UnattendPath $BaseUnattendPath `
-VmUsername $VmUsername `
-VmPassword $VmPassword

Create-VM `
-VmName $vmName `
-VhdPath $vhd.FullName `
-VmStoragePath $outVMPath `
-ExternalVMSwitchName $ExternalSwitchName `
-VMMemory $VMMemory `
-UnattendPath $BaseUnattendPath `
-VmUsername $VmUsername `
-VmPassword $VmPassword
Configure-VM `
-VmName $vmName `
-VmUsername $VmUsername `
-VmPassword $VmPassword `
-CpuCount $CpuCount

Configure-VM `
-VmName $vmName `
-CpuCount $VMCpuCount `
-VmUsername $VmUsername `
-VmPassword $VmPassword
Log-Message "VM $vmName created successfully"
} catch {
Log-Message "Failed to create VM $vmName: $_"
}
}

Log-Message "Setup.ps1 complete!"
4 changes: 2 additions & 2 deletions 1es/configure_vm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ foreach ($adapter in $adapters) {
}
}

Get-NetAdapterBinding -AllBindings
Get-NetAdapterBinding -AllBindings | Out-String

ipconfig /all

Get-NetIPInterface
Get-NetIPInterface | Out-String

# Reboot the machine to apply the changes.
Restart-Computer -Force
19 changes: 10 additions & 9 deletions 1es/prepare_vm_helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ function Create-VM {
[Parameter(Mandatory=$True)][string]$VmPassword,
[Parameter(Mandatory=$True)][string]$VhdPath,
[Parameter(Mandatory=$True)][string]$VmStoragePath,
[Parameter(Mandatory=$True)][string]$ExternalVMSwitchName,
[Parameter(Mandatory=$True)][Int64]$VMMemory,
[Parameter(Mandatory=$True)][string]$UnattendPath
)
Expand Down Expand Up @@ -191,7 +190,7 @@ function Create-VM {
# Create the VM
Log-Message "Creating the VM"
New-VM -Name $VmName -VhdPath $VmVhdPath
$vmSwitches = Get-VMSwitch
$vmSwitches = Get-VMSwitch -ErrorAction Ignore
foreach ($switch in $vmSwitches) {
Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)"
Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name
Expand Down Expand Up @@ -238,10 +237,10 @@ function Configure-VM {
Log-Message "Sleeping for 1 minute to let the VM get into a steady state"
Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state.

# Fetch all updates on the VM
Log-Message "Fetching Updates on the VM"
# Update-VM -VMName $VmName -VmCredential $VmCredential
Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green
# # Fetch all updates on the VM
# Log-Message "Fetching Updates on the VM"
# # Update-VM -VMName $VmName -VmCredential $VmCredential
# Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green

# Copy setup script to the VM and execute it.
Log-Message "Executing VM configuration script ($VMSetupScript) on VM: $VmName"
Expand All @@ -266,6 +265,8 @@ function Configure-VM {
continue
}
}

Log-Message "Successfully configured VM: $VmName" -ForegroundColor Green
} catch {
throw "Failed to configure VM: $VmName. Error: $_"
}
Expand Down Expand Up @@ -297,7 +298,7 @@ function Create-VMSwitchIfNeeded {
try {
if ($SwitchType -eq 'External') {
# Check to see if an external switch already exists
$ExternalSwitches = (Get-VMSwitch -SwitchType External)
$ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore)
if ($ExternalSwitches -ne $null) {
Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)"
return
Expand All @@ -311,7 +312,7 @@ function Create-VMSwitchIfNeeded {
if ([string]::IsNullOrEmpty($NetAdapterName)) {
continue
}
$switchName = $ExternalSwitchName + '-' + $index
$switchName = $SwitchName + '-' + $index
Log-Message "Attempting to creating external switch: $switchName with NetAdapter: $NetAdapterName"
New-VMSwitch -Name $switchName -NetAdapterName $NetAdapterName -AllowManagementOS $true
# break
Expand All @@ -321,7 +322,7 @@ function Create-VMSwitchIfNeeded {
}
} elseif ($SwitchType -eq 'Internal') {
# Check to see if an internal switch already exists
$InternalSwitches = (Get-VMSwitch -SwitchType Internal)
$InternalSwitches = (Get-VMSwitch -SwitchType Internal -ErrorAction Ignore)
if ($InternalSwitches -ne $null) {
Log-Message -Message "Internal switch already exists: $($InternalSwitches[0].Name)"
return
Expand Down

0 comments on commit 91f3a84

Please sign in to comment.