Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion connector/test_vm_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
sys.modules["vm_helper"] = _module
_spec.loader.exec_module(_module)

from vm_helper import HelperError, handle
from vm_helper import HelperError, domain_xml, handle


class Status(unittest.TestCase):
Expand Down Expand Up @@ -114,6 +114,7 @@ def fetch_ok(url):
with open(os.path.join(d, "vms", "abcd1234", "domain.xml"), encoding="utf-8") as xml_file:
xml = xml_file.read()
self.assertIn("<backend type='passt'/>", xml)
self.assertNotIn("qemu-xhci", xml)
self.assertIn("vnc.sock", xml)
self.assertNotIn("port=", xml.split("<graphics")[1].split("/>")[0])
self.assertIn("org.qemu.guest_agent.0", xml)
Expand Down Expand Up @@ -546,5 +547,31 @@ def test_migrate_probe_allows_a_paused_copy(self):
self.assertIs(report["ok"], True)


def _domain_spec(arch, **extra):
spec = {
"id": "abcd1234", "name": "Box", "memoryMb": 512, "sockets": 1, "cores": 1,
"cpuType": "host", "mac": "52:54:00:11:22:33", "firmware": "efi", "arch": arch,
"machineType": "virt" if arch == "arm64" else "q35", "nic": "virtio", "video": "virtio",
"kvm": False, "tablet": True, "acpi": True, "agent": False, "bootMenu": False,
"notes": "", "linkDown": False, "boot": ["disk0"],
"disks": [{"id": "disk0", "device": "disk", "bus": "virtio", "format": "qcow2"}],
}
spec.update(extra)
return spec


class ArmUsbController(unittest.TestCase):
def test_an_arm_tablet_gets_a_usb_controller_and_an_x86_machine_does_not(self):
arm = domain_xml(_domain_spec("arm64"), "/tmp/guest", False, "", {})
self.assertIn("<controller type='usb' model='qemu-xhci'/>", arm)
self.assertLess(arm.index("qemu-xhci"), arm.index("<input type='tablet'"))
passed = domain_xml(_domain_spec("arm64", tablet=False, usbDevices=[{"vendorId": "1234", "productId": "5678"}]), "/tmp/guest", False, "", {})
self.assertIn("qemu-xhci", passed)
self.assertNotIn("<input type='tablet'", passed)
x86 = domain_xml(_domain_spec("amd64", usbDevices=[{"vendorId": "1234", "productId": "5678"}]), "/tmp/guest", False, "", {})
self.assertNotIn("qemu-xhci", x86)
self.assertIn("<input type='tablet'", x86)


if __name__ == "__main__":
unittest.main()
6 changes: 6 additions & 0 deletions connector/vm-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,13 @@ def order(disk_id):
notes = spec.get("notes") or ""
description = "\n <description>%s</description>" % xml_escape(notes) if notes else ""
uuid_el = "\n <uuid>%s</uuid>" % uuid if uuid else ""
# virt has no USB controller of its own. The tablet and a passed-through device need one,
# or libvirt refuses with "USB is disabled for this domain". q35 already has one.
usb_controller = ""
if arm and (spec["tablet"] is not False or spec.get("usbDevices")):
usb_controller = "\n <controller type='usb' model='qemu-xhci'/>"
tablet = "" if spec["tablet"] is False else "\n <input type='tablet' bus='usb'/>"
tablet = usb_controller + tablet
agent = (
"\n <channel type='unix'><target type='virtio' name='org.qemu.guest_agent.0'/></channel>"
if spec["agent"]
Expand Down
3 changes: 2 additions & 1 deletion omarchyd/machines.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,8 @@ function domainXml(m, kvm, uuid = '') {
name: windowsAuto ? 'Windows' : basename(real).replace(/\.iso$/i, ''),
version: windowsAuto ? basename(real) : label || 'ISO',
sizeMb: Math.round(size / 1e6),
arch: 'amd64',
// Home is this computer's files, so the ISO is offered for this computer's architecture.
arch,
platform: windows ? 'windows' : 'linux',
requiresCredentials: windowsAuto,
manualSetup: !windowsAuto,
Expand Down
9 changes: 7 additions & 2 deletions test/machines.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,11 +1605,13 @@ test('a Windows Server ISO you install by hand gets the SATA disk and e1000e net
}
return ''
}
const machines = createMachines({dataDir, run, kvmDevice, files: {resolve: async (p) => ({real: p.replace('/Home', join(root, 'home')), top: 'Home'})}})
const machines = createMachines({dataDir, run, kvmDevice, arch: 'amd64', files: {resolve: async (p) => ({real: p.replace('/Home', join(root, 'home')), top: 'Home'})}})
await machines.ready
const isos = await machines.procedures['machines.localIsos'].run()
const server = isos.find((i) => /Win_Server/.test(i.id))
const arch = isos.find((i) => /archlinux/.test(i.id))
assert.equal(server.arch, 'amd64')
assert.equal(arch.arch, 'amd64')
assert.deepEqual([server.platform, server.requiresCredentials, server.manualSetup], ['windows', false, true])
const spec = {cores: 1, memoryGb: 1, diskSizeGb: 10}
const {id} = await machines.procedures['machines.create'].run({...spec, name: 'Server', osId: server.id})
Expand Down Expand Up @@ -1676,8 +1678,11 @@ test('on an ARM server (Omarchy on Apple Silicon) a machine is an aarch64 "virt"
}
return ''
}
const machines = createMachines({dataDir, run, kvmDevice, arch: 'arm64', catalogUrl: 'https://example.invalid/catalog.json', fetchImpl: async () => new Response('', {status: 503})})
await mkdir(join(root, 'home'), {recursive: true})
await writeFile(join(root, 'home', 'alpine.iso'), 'iso')
const machines = createMachines({dataDir, run, kvmDevice, arch: 'arm64', files: {resolve: async (p) => ({real: p.replace('/Home', join(root, 'home')), top: 'Home'})}, catalogUrl: 'https://example.invalid/catalog.json', fetchImpl: async () => new Response('', {status: 503})})
await machines.ready
assert.equal((await machines.procedures['machines.localIsos'].run()).find((i) => /alpine/.test(i.id)).arch, 'arm64')
await machines.procedures['machines.start'].run({id})
const xml = defined[0]
assert.match(xml, /<os firmware='efi'><type arch='aarch64' machine='virt'>hvm<\/type>/)
Expand Down
Loading