Skip to content

Commit

Permalink
Fix #73: OpenBSD VM fails during "Initializing VM" with QEMU on macOS
Browse files Browse the repository at this point in the history
The `Xhyve` hypervisor class was selected instead of `QemuEfi`
  • Loading branch information
jacob-carlborg committed Jan 9, 2024
1 parent 7de0dae commit 23106fd
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 15 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,25 @@ jobs:
hypervisor: qemu
shutdown_vm: true
run: test -f foo.txt

openbsd-qemu-macos:
timeout-minutes: 5
name: Test OpenBSD with QEMU on macOS runner
runs-on: macos-latest

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

- name: Test
uses: ./
with:
operating_system: openbsd
architecture: x86-64
version: '7.4'
hypervisor: qemu
sync_files: false
shutdown_vm: false
run: true
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- OpenBSD VM fails during "Initializing VM" with QEMU on macOS ([#73](https://github.com/cross-platform-actions/action/issues/73))

### Changed
- Update qemu to 8.2.0 for CVTPS2PD fix ([#78](https://github.com/cross-platform-actions/action/issues/78))
Expand Down
21 changes: 14 additions & 7 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.

61 changes: 61 additions & 0 deletions spec/architecture.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,65 @@
import * as architecture from '../src/architecture'
import {Architecture} from '../src/architecture'
import {Host} from '../src/host'
import * as os from '../src/operating_systems/kind'
import {Qemu, QemuEfi, Xhyve} from '../src/hypervisor'

let context = describe

describe('Architecture', () => {
describe('efiHypervisor', () => {
context('x86_64', () => {
let kind = architecture.Kind.x86_64

context('macOS host', () => {
let host = Host.create('darwin')

context('QEMU hypervisor', () => {
let selectedHypervisor = new Qemu()

context('OpenBSD', () => {
let osKind = os.Kind.for('openbsd')
let arch = Architecture.for(kind, host, osKind, selectedHypervisor)

it('returns the QEMU EFI hypervisor', () => {
expect(arch.efiHypervisor).toBeInstanceOf(QemuEfi)
})
})
})

context('Xhyve hypervisor', () => {
let selectedHypervisor = new Xhyve()

context('OpenBSD', () => {
let osKind = os.Kind.for('openbsd')
let arch = Architecture.for(kind, host, osKind, selectedHypervisor)

it('returns the Xhyve hypervisor', () => {
expect(arch.efiHypervisor).toBeInstanceOf(Xhyve)
})
})
})
})

context('Linux host', () => {
let host = Host.create('linux')

context('QEMU hypervisor', () => {
let selectedHypervisor = new Qemu()

context('OpenBSD', () => {
let osKind = os.Kind.for('openbsd')
let arch = Architecture.for(kind, host, osKind, selectedHypervisor)

it('returns the QEMU EFI hypervisor', () => {
expect(arch.efiHypervisor).toBeInstanceOf(QemuEfi)
})
})
})
})
})
})
})

describe('toKind', () => {
describe('arm64', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/action/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Action {
try {
await implementation.run()
implementation.configSSH(vm.ipAddress)
await implementation.wait(120)
await implementation.wait(240)
await implementation.setupWorkDirectory(
this.homeDirectory,
this.workDirectory
Expand Down
2 changes: 1 addition & 1 deletion src/architecture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export abstract class Architecture {
}

override get efiHypervisor(): hypervisor.Hypervisor {
return this.host.efiHypervisor
return this.selectedHypervisor.efi
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/hypervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export abstract class Hypervisor {
abstract get sshPort(): number
abstract get firmwareFile(): string
abstract get vmModule(): typeof QemuVm | typeof XhyveVm
abstract get efi(): Hypervisor
abstract getResourceUrl(architecture: Architecture): string
abstract resolve<T>(implementation: Record<string, T>): T
}
Expand All @@ -44,6 +45,10 @@ export class Xhyve extends Hypervisor {
return XhyveVm
}

override get efi(): Hypervisor {
return this
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
override getResourceUrl(_architecture: Architecture): string {
return `${ResourceUrls.create().resourceBaseUrl}/xhyve-macos.tar`
Expand Down Expand Up @@ -73,6 +78,10 @@ export class Qemu extends Hypervisor {
return QemuVm
}

override get efi(): Hypervisor {
return new QemuEfi()
}

override getResourceUrl(architecture: Architecture): string {
return architecture.resourceUrl
}
Expand Down
3 changes: 1 addition & 2 deletions src/operating_systems/openbsd/openbsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as core from '@actions/core'
import * as architecture from '../../architecture'
import {operatingSystem} from '../factory'
import * as vmModule from '../../vm'
import {host} from '../../host'
import {QemuVm} from './qemu_vm'
import * as os from '../../operating_system'
import versions from '../../version'
Expand Down Expand Up @@ -66,7 +65,7 @@ export default class OpenBsd extends os.OperatingSystem {
uuid: this.uuid
}

const cls = host.hypervisor.resolve({qemu: QemuVm, xhyve: XhyveVm})
const cls = this.hypervisor.resolve({qemu: QemuVm, xhyve: XhyveVm})
return new cls(
hypervisorDirectory,
resourcesDirectory,
Expand Down
8 changes: 5 additions & 3 deletions src/qemu_vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export abstract class Vm extends vm.Vm {
this.hypervisorPath.toString(),
'-daemonize',
'-machine', `type=${this.configuration.machineType},accel=${accel}`,
'-cpu', this.configuration.cpu,
// "-pdpe1gb" == disable huge pages, otherwise OpenBSD will not boot: https://gitlab.com/qemu-project/qemu/-/issues/1091
'-cpu', `${this.configuration.cpu},-pdpe1gb`,
'-smp', this.configuration.cpuCount.toString(),
'-m', this.configuration.memory,

Expand All @@ -49,8 +50,9 @@ export abstract class Vm extends vm.Vm {

'-boot', 'strict=off',
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
'-bios', this.configuration.firmware!.toString()
].concat(this.hardDriverFlags)
'-bios', this.configuration.firmware!.toString(),
...this.hardDriverFlags
]
}

protected abstract get hardDriverFlags(): string[]
Expand Down

0 comments on commit 23106fd

Please sign in to comment.