Skip to content

Commit 958d91c

Browse files
committed
Merge remote-tracking branch 'origin/pr/626'
* origin/pr/626: UEFI test
2 parents 51aeab6 + 66e9015 commit 958d91c

File tree

2 files changed

+80
-26
lines changed

2 files changed

+80
-26
lines changed

qubes/tests/__init__.py

+47-20
Original file line numberDiff line numberDiff line change
@@ -1328,33 +1328,60 @@ def prepare_hvm_system_linux(self, vm, init_script, extra_files=None):
13281328

13291329
def create_bootable_iso(self):
13301330
"""Create simple bootable ISO image.
1331-
Type 'poweroff' to it to terminate that VM.
1331+
Type 'halt' to it to terminate that VM.
13321332
"""
1333-
isolinux_cfg = (
1334-
'prompt 1\n'
1335-
'label poweroff\n'
1336-
' kernel poweroff.c32\n'
1337-
)
13381333
output_fd, output_path = tempfile.mkstemp('.iso')
13391334
with tempfile.TemporaryDirectory() as tmp_dir:
1335+
f = os.open(tmp_dir, os.O_RDONLY|os.O_DIRECTORY)
13401336
try:
1341-
shutil.copy('/usr/share/syslinux/isolinux.bin', tmp_dir)
1342-
shutil.copy('/usr/share/syslinux/ldlinux.c32', tmp_dir)
1343-
shutil.copy('/usr/share/syslinux/poweroff.c32', tmp_dir)
1344-
with open(os.path.join(tmp_dir, 'isolinux.cfg'), 'w') as cfg:
1345-
cfg.write(isolinux_cfg)
1346-
subprocess.check_call(['genisoimage', '-o', output_path,
1347-
'-c', 'boot.cat',
1348-
'-b', 'isolinux.bin',
1337+
os.mkdir('os', mode=0o755, dir_fd=f)
1338+
os.mkdir('iso', mode=0o755, dir_fd=f)
1339+
os.mkdir('os/images', mode=0o755, dir_fd=f)
1340+
os.mkdir('os/EFI', mode=0o755, dir_fd=f)
1341+
os.mkdir('os/EFI/BOOT', mode=0o755, dir_fd=f)
1342+
with open(f'/proc/self/fd/{f}/os/images/boot_hybrid.img', 'wb') as v:
1343+
subprocess.check_call(['grub2-mkimage',
1344+
'-O', 'i386-pc-eltorito',
1345+
'-d', '/usr/lib/grub/i386-pc',
1346+
'-p', '/boot/grub2',
1347+
'iso9660', 'biosdisk', 'halt'], stdout=v)
1348+
with open(f'/proc/self/fd/{f}/os/EFI/BOOT/BOOTX64.EFI', 'wb') as v:
1349+
subprocess.check_call(['grub2-mkimage',
1350+
'-O', 'x86_64-efi',
1351+
'-d', '/usr/lib/grub/x86_64-efi',
1352+
'-p', '/boot/grub2',
1353+
'iso9660', 'disk', 'halt'], stdout=v)
1354+
graft_path = '.=' + os.path.join(tmp_dir, "os").replace("\\", "\\\\").replace("=", "\\=")
1355+
efiboot_img = os.path.join(tmp_dir, 'os/images/efiboot.img')
1356+
subprocess.check_call(['sudo', 'mkefiboot', '--label=ANACONDA',
1357+
os.path.join(tmp_dir, 'os/EFI/BOOT'),
1358+
efiboot_img])
1359+
subprocess.check_call(['sudo', 'chmod', '-R', 'go+rX', tmp_dir])
1360+
subprocess.check_call(['xorrisofs',
1361+
'-o', output_path,
1362+
'--grub2-mbr', 'os/images/boot_hybrid.img',
1363+
'--mbr-force-bootable',
1364+
'--gpt-iso-bootable',
1365+
'-partition_offset', '16',
1366+
'-append_partition', '2', '0xef', efiboot_img,
1367+
'-iso_mbr_part_type', 'EBD0A0A2-B9E5-4433-87C0-68B6B72699C7',
1368+
'-appended_part_as_gpt',
1369+
'-c', 'boot.cat', '--boot-catalog-hide',
1370+
'-eltorito-boot', 'images/boot_hybrid.img',
13491371
'-no-emul-boot',
13501372
'-boot-load-size', '4',
13511373
'-boot-info-table',
1352-
'-q',
1353-
tmp_dir])
1354-
except FileNotFoundError:
1355-
self.skipTest('syslinux or genisoimage not installed')
1356-
os.close(output_fd)
1357-
self.addCleanup(os.unlink, output_path)
1374+
'--grub2-boot-info',
1375+
'-eltorito-alt-boot',
1376+
'-e', '--interval:appended_partition_2:all::',
1377+
'-no-emul-boot',
1378+
'-graft-points', graft_path,
1379+
'boot/grub2/i386-pc=/usr/lib/grub/i386-pc',
1380+
'boot/grub2/x86_64-efi=/usr/lib/grub/x86_64-efi'],
1381+
cwd=tmp_dir)
1382+
self.addCleanup(os.unlink, output_path)
1383+
finally:
1384+
os.close(f)
13581385
return output_path
13591386

13601387
def create_local_file(self, filename, content, mode='w'):

qubes/tests/integ/basic.py

+33-6
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,44 @@ def test_120_start_standalone_with_cdrom_dom0(self):
103103
(stdout, _) = self.loop.run_until_complete(p.communicate())
104104
self.assertEqual(p.returncode, 0, stdout)
105105
# check if VM do not crash instantly
106-
self.loop.run_until_complete(asyncio.sleep(5))
106+
self.loop.run_until_complete(asyncio.sleep(50))
107107
self.assertTrue(self.vm.is_running())
108-
# Type 'poweroff'
108+
# Type 'halt'
109109
subprocess.check_call(['xdotool', 'search', '--name', self.vm.name,
110-
'type', '--window', '%1', 'poweroff\r'])
110+
'type', '--window', '%1', 'halt\r'])
111111
for _ in range(10):
112112
if not self.vm.is_running():
113113
break
114114
self.loop.run_until_complete(asyncio.sleep(1))
115115
self.assertFalse(self.vm.is_running())
116116

117+
def test_121_start_uefi(self):
118+
vmname = self.make_vm_name('appvm')
119+
self.vm = self.app.add_new_vm('StandaloneVM', label='red', name=vmname)
120+
self.loop.run_until_complete(self.vm.create_on_disk())
121+
self.vm.kernel = None
122+
self.vm.virt_mode = 'hvm'
123+
self.vm.features["uefi"] = "1"
124+
iso_path = self.create_bootable_iso()
125+
# start the VM using qvm-start tool, to test --cdrom option there
126+
p = self.loop.run_until_complete(asyncio.create_subprocess_exec(
127+
'qvm-start', '--cdrom=dom0:' + iso_path, self.vm.name,
128+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
129+
(stdout, _) = self.loop.run_until_complete(p.communicate())
130+
self.assertEqual(p.returncode, 0, stdout)
131+
# check if VM do not crash instantly
132+
self.loop.run_until_complete(asyncio.sleep(50))
133+
self.assertTrue(self.vm.is_running())
134+
# Type 'halt'
135+
subprocess.check_call(['xdotool', 'search', '--name', self.vm.name,
136+
'type', '--window', '%1', 'halt\r'])
137+
for _ in range(10):
138+
if not self.vm.is_running():
139+
break
140+
self.loop.run_until_complete(asyncio.sleep(1))
141+
self.assertFalse(self.vm.is_running())
142+
143+
117144
def test_130_autostart_disable_on_remove(self):
118145
vm = self.app.add_new_vm(qubes.vm.appvm.AppVM,
119146
name=self.make_vm_name('vm'),
@@ -716,11 +743,11 @@ def test_121_start_standalone_with_cdrom_vm(self):
716743
(stdout, _) = self.loop.run_until_complete(p.communicate())
717744
self.assertEqual(p.returncode, 0, stdout)
718745
# check if VM do not crash instantly
719-
self.loop.run_until_complete(asyncio.sleep(5))
746+
self.loop.run_until_complete(asyncio.sleep(50))
720747
self.assertTrue(self.vm.is_running())
721-
# Type 'poweroff'
748+
# Type 'halt'
722749
subprocess.check_call(['xdotool', 'search', '--name', self.vm.name,
723-
'type', '--window', '%1', 'poweroff\r'])
750+
'type', '--window', '%1', 'halt\r'])
724751
for _ in range(10):
725752
if not self.vm.is_running():
726753
break

0 commit comments

Comments
 (0)