diff --git a/connector/test_vm_helper.py b/connector/test_vm_helper.py index 24118549..365da61d 100644 --- a/connector/test_vm_helper.py +++ b/connector/test_vm_helper.py @@ -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): @@ -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("", xml) + self.assertNotIn("qemu-xhci", xml) self.assertIn("vnc.sock", xml) self.assertNotIn("port=", xml.split("")[0]) self.assertIn("org.qemu.guest_agent.0", xml) @@ -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("", arm) + self.assertLess(arm.index("qemu-xhci"), arm.index("" + tablet = usb_controller + tablet agent = ( "\n " if spec["agent"] diff --git a/omarchyd/machines.mjs b/omarchyd/machines.mjs index a31dcbaf..35a8af1b 100644 --- a/omarchyd/machines.mjs +++ b/omarchyd/machines.mjs @@ -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, diff --git a/test/machines.test.mjs b/test/machines.test.mjs index 891c2e08..2f0be4dc 100644 --- a/test/machines.test.mjs +++ b/test/machines.test.mjs @@ -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}) @@ -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, /hvm<\/type>/)