mirror of https://github.com/cirruslabs/tart.git
Reject macOS balloon targets below the restore-image minimum
For macOS guests, "tart run --balloon-target-memory" now also enforces the VM's own minimum supported memory size (dictated by the restore image), similarly to how "tart set --memory" restricts the configured memory size. Addresses a PR review comment. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
3678f45d82
commit
8de3a2e929
|
|
@ -429,7 +429,13 @@ struct Run: AsyncParsableCommand {
|
||||||
+ " configured memory size of \(vmConfig.memorySize / 1024 / 1024) MB")
|
+ " configured memory size of \(vmConfig.memorySize / 1024 / 1024) MB")
|
||||||
}
|
}
|
||||||
|
|
||||||
let minimumAllowedMemorySize = VZVirtualMachineConfiguration.minimumAllowedMemorySize
|
var minimumAllowedMemorySize = VZVirtualMachineConfiguration.minimumAllowedMemorySize
|
||||||
|
if vmConfig.os == .darwin {
|
||||||
|
// macOS guests additionally have a minimum supported memory size
|
||||||
|
// dictated by the restore image they were created from, similarly
|
||||||
|
// to how "tart set --memory" restricts the configured memory size
|
||||||
|
minimumAllowedMemorySize = max(minimumAllowedMemorySize, vmConfig.memorySizeMin)
|
||||||
|
}
|
||||||
if targetMemoryBytes < minimumAllowedMemorySize {
|
if targetMemoryBytes < minimumAllowedMemorySize {
|
||||||
throw ValidationError("--balloon-target-memory (\(targetMemoryMB) MB) is too small,"
|
throw ValidationError("--balloon-target-memory (\(targetMemoryMB) MB) is too small,"
|
||||||
+ " it should be at least \(minimumAllowedMemorySize / 1024 / 1024) MB")
|
+ " it should be at least \(minimumAllowedMemorySize / 1024 / 1024) MB")
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,25 @@ final class MemoryBalloonTests: XCTestCase {
|
||||||
XCTAssertNoThrow(try Run.validateBalloonTargetMemory(4096, vmConfig: vmConfig))
|
XCTAssertNoThrow(try Run.validateBalloonTargetMemory(4096, vmConfig: vmConfig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testBalloonTargetMemoryValidationRespectsDarwinMinimum() throws {
|
||||||
|
// A macOS guest whose restore image requires 4096 MB of memory at minimum
|
||||||
|
var vmConfig = VMConfig(platform: Linux(), cpuCountMin: 1, memorySizeMin: 4096 * 1024 * 1024)
|
||||||
|
vmConfig.os = .darwin
|
||||||
|
vmConfig.memoryBalloon = true
|
||||||
|
try vmConfig.setMemory(memorySize: 8192 * 1024 * 1024)
|
||||||
|
|
||||||
|
// Target below the restore image's minimum supported memory size
|
||||||
|
XCTAssertThrowsError(try Run.validateBalloonTargetMemory(2048, vmConfig: vmConfig))
|
||||||
|
|
||||||
|
// Target at the restore image's minimum supported memory size
|
||||||
|
XCTAssertNoThrow(try Run.validateBalloonTargetMemory(4096, vmConfig: vmConfig))
|
||||||
|
|
||||||
|
// The same minimum doesn't apply to Linux guests, similarly
|
||||||
|
// to how "tart set --memory" doesn't restrict them
|
||||||
|
vmConfig.os = .linux
|
||||||
|
XCTAssertNoThrow(try Run.validateBalloonTargetMemory(2048, vmConfig: vmConfig))
|
||||||
|
}
|
||||||
|
|
||||||
func testBalloonDeviceOnlyConfiguredWhenEnabled() throws {
|
func testBalloonDeviceOnlyConfiguredWhenEnabled() throws {
|
||||||
// Disabled by default
|
// Disabled by default
|
||||||
XCTAssertEqual(try craftConfiguration().memoryBalloonDevices.count, 0)
|
XCTAssertEqual(try craftConfiguration().memoryBalloonDevices.count, 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue