Skip to content

Commit ca657f5

Browse files
authored
Always provide a serial console (#346)
1 parent dc4284a commit ca657f5

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Sources/Containerization/VZVirtualMachineInstance.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,12 @@ extension VZVirtualMachineInstance.Configuration {
265265
config.memorySize = self.memoryInBytes
266266
config.entropyDevices = [VZVirtioEntropyDeviceConfiguration()]
267267
config.socketDevices = [VZVirtioSocketDeviceConfiguration()]
268+
268269
if let bootlog = self.bootlog {
269270
config.serialPorts = try serialPort(path: bootlog)
271+
} else {
272+
// We always supply a serial console. If no explicit path was provided just send em to the void.
273+
config.serialPorts = try serialPort(path: URL(filePath: "/dev/null"))
270274
}
271275

272276
config.networkDevices = try self.interfaces.map {

Sources/Integration/ContainerTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,25 @@ extension IntegrationSuite {
999999
}
10001000
}
10011001

1002+
func testNoSerialConsole() async throws {
1003+
let id = "test-no-serial-console"
1004+
1005+
let bs = try await bootstrap(id)
1006+
let container = try LinuxContainer(id, rootfs: bs.rootfs, vmm: bs.vmm) { config in
1007+
config.process.arguments = ["/bin/true"]
1008+
}
1009+
1010+
try await container.create()
1011+
try await container.start()
1012+
1013+
let status = try await container.wait()
1014+
try await container.stop()
1015+
1016+
guard status.exitCode == 0 else {
1017+
throw IntegrationError.assert(msg: "process status \(status) != 0")
1018+
}
1019+
}
1020+
10021021
private func createMountDirectory() throws -> URL {
10031022
let dir = FileManager.default.uniqueTemporaryDirectory(create: true)
10041023
try "hello".write(to: dir.appendingPathComponent("hi.txt"), atomically: true, encoding: .utf8)

Sources/Integration/Suite.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ struct IntegrationSuite: AsyncParsableCommand {
291291
Test("container /dev/console", testContainerDevConsole),
292292
Test("container statistics", testContainerStatistics),
293293
Test("container cgroup limits", testCgroupLimits),
294+
Test("container no serial console", testNoSerialConsole),
294295

295296
// Pods
296297
Test("pod single container", testPodSingleContainer),

0 commit comments

Comments
 (0)