Skip to content

reset-parent-or-child-lab-machine #41

reset-parent-or-child-lab-machine

reset-parent-or-child-lab-machine #41

name: reset-parent-or-child-lab-machine
on:
schedule:
- cron: "0 */3 * * *" # Runs once every 3 hours
workflow_dispatch:
inputs:
parent-or-child:
description: "Lab jobs to observe"
required: false
type: string
vm-name:
description: "The name of the VM to reset"
default: "netperf-windows-2022-client"
required: false
type: string
reset-all-active:
description: "Resets all active lab machines"
default: false
required: false
type: boolean
jobs:
# This job ensures there is currently no actively running netperf jobs using the Github API. If there is, fail this step.
sanity-check:
name: Sanity check
runs-on: windows-latest
steps:
- name: Check for active jobs
run: |
$headers = @{
"Accept" = "application/vnd.github+json"
"Authorization" = "Bearer ${{ secrets.GITHUB_TOKEN }}"
"X-GitHub-Api-Version" = "2022-11-28"
}
$url = "https://api.github.com/repos/microsoft/netperf/actions/runs?status=in_progress"
Write-Debug "GET $url"
$activeRuns = ((Invoke-WebRequest -Uri $url -Method GET -Headers $headers).Content | ConvertFrom-Json).workflow_runs
foreach ($run in $activeRuns) {
if ($run.name -ne "reset-parent-or-child-lab-machine") {
Write-Host "Found active netperf job: $($run.name)"
exit 1
}
}
shell: pwsh
do-reset-all-active:
name: Reset all active lab machines
if: ${{ inputs.reset-all-active == true || github.event_name == 'schedule' }}
needs: sanity-check
strategy:
fail-fast: false
matrix:
vec: [
{ parent-or-child: "parent=rr1-netperf-26\\localadminuser", vm-name: "netperf-windows-2022-client" },
{ parent-or-child: "child=rr1-netperf-25\\localadminuser", vm-name: "netperf-windows-2022-server" },
{ parent-or-child: "child=rr1-netperf-05\\localadminuser", vm-name: "netperf" },
{ parent-or-child: "parent=rr1-netperf-10\\localadminuser", vm-name: "netperf" },
]
runs-on:
- self-hosted
- ${{ matrix.vec.parent-or-child }}
steps:
- name: RESET STATE (parent or child)
run: |
# TODO: Eventually, for WS 2025, we want to instead CRUD the VMs, instead of simply reseting their checkpoints here.
$vmName = "${{ matrix.vec.vm-name }}"
$checkPointName = "LATEST"
Restore-VMSnapshot -VMName $vmName -Name $checkPointName -Confirm:$false
- name: Start VM, wait for online status, alert observer.
run: |
$vmName = "${{ matrix.vec.vm-name }}"
Start-VM -Name $vmName
while (-not (Get-VMNetworkAdapter -VMName $vmName).IPAddresses) {
Write-Host "Waiting for VM to be online..."
Start-Sleep -Seconds 5
}
Start-Sleep 10
do-reset-manual:
name: Reset parent or child Machine
if: ${{ inputs.reset-all-active == false && github.event_name != 'schedule' }}
needs: sanity-check
runs-on:
- self-hosted
- ${{ inputs.parent-or-child }}
steps:
- name: RESET STATE (parent or child)
run: |
# TODO: Eventually, for WS 2025, we want to instead CRUD the VMs, instead of simply reseting their checkpoints here.
$vmName = "${{ inputs.vm-name }}"
$checkPointName = "LATEST"
Restore-VMSnapshot -VMName $vmName -Name $checkPointName -Confirm:$false
- name: Start VM, wait for online status, alert observer.
run: |
$vmName = "${{ inputs.vm-name }}"
Start-VM -Name $vmName
while (-not (Get-VMNetworkAdapter -VMName $vmName).IPAddresses) {
Write-Host "Waiting for VM to be online..."
Start-Sleep -Seconds 5
}
Start-Sleep 10