Skip to content

Commit

Permalink
fixup! Fix #61, 62: very frequent freezing of VM during teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Nov 30, 2023
1 parent d5b757f commit 28581cb
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 21 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -255,6 +255,30 @@ jobs:
hypervisor: qemu
run: dmesg | grep -i avx2

test-no-vm-shutdown:
timeout-minutes: 5
name: Test not shutting down the VM
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Test
uses: ./
with:
operating_system: freebsd
architecture: x86-64
version: '13.2'
hypervisor: qemu
shutdown_vm: false
run: true

- name: Verify VM is still running
run: ps aux | grep -q qemu

test-sync-files:
timeout-minutes: 5
name: 'Test sync files: ${{ matrix.data.direction }}'
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -49,6 +49,11 @@ inputs:
machine and in which direction. Valid values are `true`, `false`,
`runner-to-vm` and `vm-to-runner`.
default: 'true'
shutdown_vm:
required: false
description: |
Specifies if the VM should be shutdown after the action has been run.
default: false

runs:
using: node20
Expand Down
62 changes: 47 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -128,6 +128,7 @@ This section lists the available inputs for the action.
| `hypervisor` || `xhyve` or `qemu` | string | The hypervisor to use for running the virtual machine. For Linux runners the only valid value is `qemu`. For macOS runners the default for OpenBSD and FreeBSD is `xhyve` for all other platforms the default is `qemu`. |
| `image_url` ||| string | URL a custom VM image that should be used in place of the default ones. |
| `sync_files` || `true` | string | Specifies if the local files should be synchronized to the virtual machine and in which direction. Valid values are `true`, `false`, `runner-to-vm` and `vm-to-runner`. `true` synchronizes files in both directions. `false` disables file synchronization. |
| `shutdown_vm` || `false` | boolean | Specifies if the VM should be shutdown after the action has been run. |

All inputs are expected to be of the specified type. It's especially important
that you specify `version` as a string, using single or
Expand Down
6 changes: 6 additions & 0 deletions spec/operating_systems/freebsd/freebsd.spec.ts
Expand Up @@ -9,6 +9,7 @@ import HostQemu from '../../../src/host_qemu'
import * as hypervisor from '../../../src/hypervisor'
import * as qemu from '../../../src/qemu_vm'
import * as xhyve from '../../../src/xhyve_vm'
import {Input} from '../../../src/action/input'

describe('FreeBSD OperatingSystem', () => {
class MockHost extends hostModule.Host {
Expand Down Expand Up @@ -47,6 +48,7 @@ describe('FreeBSD OperatingSystem', () => {
let hypervisorDirectory = 'hypervisor/directory'
let resourcesDirectory = 'resources/directory'
let firmwareDirectory = 'firmware/directory'
let input = new Input()

let config = {
memory: '4G',
Expand All @@ -70,13 +72,15 @@ describe('FreeBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

expect(vmModule).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
input,
{
...config,
ssHostPort: 2847,
Expand All @@ -102,6 +106,7 @@ describe('FreeBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

Expand All @@ -123,6 +128,7 @@ describe('FreeBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

Expand Down
4 changes: 3 additions & 1 deletion spec/operating_systems/freebsd/qemu_vm.spec.ts
Expand Up @@ -4,6 +4,7 @@ import {host} from '../../../src/host'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import '../../../src/operating_systems/freebsd/freebsd'
import {Input} from '../../../src/action/input'

describe('FreeBSD QemuVm', () => {
let memory = '5G'
Expand All @@ -17,6 +18,7 @@ describe('FreeBSD QemuVm', () => {
osKind,
host.hypervisor
)
let input = new Input()
let config = {
memory: memory,
cpuCount: cpuCount,
Expand All @@ -30,7 +32,7 @@ describe('FreeBSD QemuVm', () => {
userboot: '',
firmware: ''
}
let vm = new QemuVm('', '', architecture, config)
let vm = new QemuVm('', '', architecture, input, config)

let getFlagValue = (flag: string) => vm.command[vm.command.indexOf(flag) + 1]
let actualMemory = () => getFlagValue('-m')
Expand Down
6 changes: 6 additions & 0 deletions spec/operating_systems/netbsd/netbsd.spec.ts
Expand Up @@ -8,6 +8,7 @@ import * as hypervisor from '../../../src/hypervisor'
import * as qemu from '../../../src/qemu_vm'
import * as xhyve from '../../../src/xhyve_vm'
import * as netbsdQemuVm from '../../../src/operating_systems/netbsd/qemu_vm'
import {Input} from '../../../src/action/input'

describe('NetBSD OperatingSystem', () => {
class Host extends hostModule.Host {
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('NetBSD OperatingSystem', () => {
let hypervisorDirectory = 'hypervisor/directory'
let resourcesDirectory = 'resources/directory'
let firmwareDirectory = 'firmware/directory'
let input = new Input()

let config = {
memory: '4G',
Expand All @@ -67,13 +69,15 @@ describe('NetBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

expect(qemuVmSpy).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
input,
{
...config,
ssHostPort: 2847,
Expand Down Expand Up @@ -133,13 +137,15 @@ describe('NetBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

expect(qemuVmSpy).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
input,
{
...config,
ssHostPort: 2847,
Expand Down
4 changes: 3 additions & 1 deletion spec/operating_systems/netbsd/qemu_vm.spec.ts
Expand Up @@ -4,6 +4,7 @@ import {host} from '../../../src/host'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import '../../../src/operating_systems/netbsd/netbsd'
import {Input} from '../../../src/action/input'

describe('NetBSD QemuVm', () => {
let memory = '5G'
Expand All @@ -17,6 +18,7 @@ describe('NetBSD QemuVm', () => {
osKind,
host.hypervisor
)
let input = new Input()
let config = {
memory: memory,
cpuCount: cpuCount,
Expand All @@ -30,7 +32,7 @@ describe('NetBSD QemuVm', () => {
userboot: '',
firmware: ''
}
let vm = new Vm('', '', architecture, config)
let vm = new Vm('', '', architecture, input, config)

let getFlagValue = (flag: string) => vm.command[vm.command.indexOf(flag) + 1]
let actualMemory = () => getFlagValue('-m')
Expand Down
13 changes: 12 additions & 1 deletion src/action/action.ts
Expand Up @@ -119,9 +119,19 @@ export class Action {
} finally {
core.startGroup('Tearing down VM')
await this.syncBack(vm.ipAddress)

if (this.input.shutdownVm) {
await vm.stop()
}
}
} finally {
core.endGroup()
try {
if (this.input.shutdownVm) {
await vm.terminate()
}
} finally {
core.endGroup()
}
}
}

Expand Down Expand Up @@ -162,6 +172,7 @@ export class Action {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
this.input,
{
...config,
diskImage: path.join(resourcesDirectory, this.targetDiskName),
Expand Down

0 comments on commit 28581cb

Please sign in to comment.