Skip to content

Commit 9a89893

Browse files
committed
tests: move TC_06_AppVMMixin from basic to misc
'basic' is ran on every storage pool and as such is a bit time sensitive. Since tests in TC_06_AppVMMixin are getting longer (and not really relevant for storage testing), move it to another file.
1 parent 4464186 commit 9a89893

File tree

3 files changed

+134
-93
lines changed

3 files changed

+134
-93
lines changed

qubes/tests/integ/basic.py

-93
Original file line numberDiff line numberDiff line change
@@ -867,106 +867,13 @@ def test_101_resize_root_img_online(self):
867867
self.assertGreater(int(new_size.strip()), 19 * 1024**2)
868868

869869

870-
class TC_06_AppVMMixin(object):
871-
template = None
872-
873-
def setUp(self):
874-
super(TC_06_AppVMMixin, self).setUp()
875-
self.init_default_template(self.template)
876-
877-
def test_010_os_metadata(self):
878-
tpl = self.app.default_template
879-
if self.template.startswith("fedora-"):
880-
self.assertEqual(tpl.features.get("os-distribution"), "fedora")
881-
version = self.template.split("-")[1]
882-
self.assertEqual(tpl.features.get("os-version"), version)
883-
self.assertIsNotNone(tpl.features.get("os-eol"))
884-
elif self.template.startswith("debian-"):
885-
self.assertEqual(tpl.features.get("os-distribution"), "debian")
886-
version = self.template.split("-")[1]
887-
self.assertEqual(tpl.features.get("os-version"), version)
888-
self.assertIsNotNone(tpl.features.get("os-eol"))
889-
elif self.template.startswith("whonix-"):
890-
self.assertEqual(tpl.features.get("os-distribution"), "whonix")
891-
self.assertEqual(tpl.features.get("os-distribution-like"), "debian")
892-
version = self.template.split("-")[2]
893-
self.assertEqual(tpl.features.get("os-version"), version)
894-
elif self.template.startswith("kali-core"):
895-
self.assertEqual(tpl.features.get("os-distribution"), "kali")
896-
self.assertEqual(tpl.features.get("os-distribution-like"), "debian")
897-
898-
@unittest.skipUnless(
899-
spawn.find_executable("xdotool"), "xdotool not installed"
900-
)
901-
def test_121_start_standalone_with_cdrom_vm(self):
902-
cdrom_vmname = self.make_vm_name("cdrom")
903-
self.cdrom_vm = self.app.add_new_vm(
904-
"AppVM", label="red", name=cdrom_vmname
905-
)
906-
self.loop.run_until_complete(self.cdrom_vm.create_on_disk())
907-
self.loop.run_until_complete(self.cdrom_vm.start())
908-
iso_path = self.create_bootable_iso()
909-
with open(iso_path, "rb") as iso_f:
910-
self.loop.run_until_complete(
911-
self.cdrom_vm.run_for_stdio(
912-
"cat > /home/user/boot.iso", stdin=iso_f
913-
)
914-
)
915-
916-
vmname = self.make_vm_name("appvm")
917-
self.vm = self.app.add_new_vm("StandaloneVM", label="red", name=vmname)
918-
self.loop.run_until_complete(self.vm.create_on_disk())
919-
self.vm.kernel = None
920-
self.vm.virt_mode = "hvm"
921-
922-
# start the VM using qvm-start tool, to test --cdrom option there
923-
p = self.loop.run_until_complete(
924-
asyncio.create_subprocess_exec(
925-
"qvm-start",
926-
"--cdrom=" + cdrom_vmname + ":/home/user/boot.iso",
927-
self.vm.name,
928-
stdout=subprocess.PIPE,
929-
stderr=subprocess.STDOUT,
930-
)
931-
)
932-
(stdout, _) = self.loop.run_until_complete(p.communicate())
933-
self.assertEqual(p.returncode, 0, stdout)
934-
# check if VM do not crash instantly
935-
self.loop.run_until_complete(asyncio.sleep(50))
936-
self.assertTrue(self.vm.is_running())
937-
# Type 'halt'
938-
subprocess.check_call(
939-
[
940-
"xdotool",
941-
"search",
942-
"--name",
943-
self.vm.name,
944-
"type",
945-
"--window",
946-
"%1",
947-
"halt\r",
948-
]
949-
)
950-
for _ in range(10):
951-
if not self.vm.is_running():
952-
break
953-
self.loop.run_until_complete(asyncio.sleep(1))
954-
self.assertFalse(self.vm.is_running())
955-
956-
957870
def create_testcases_for_templates():
958871
yield from qubes.tests.create_testcases_for_templates(
959872
"TC_05_StandaloneVM",
960873
TC_05_StandaloneVMMixin,
961874
qubes.tests.SystemTestCase,
962875
module=sys.modules[__name__],
963876
)
964-
yield from qubes.tests.create_testcases_for_templates(
965-
"TC_06_AppVM",
966-
TC_06_AppVMMixin,
967-
qubes.tests.SystemTestCase,
968-
module=sys.modules[__name__],
969-
)
970877

971878

972879
def load_tests(loader, tests, pattern):

qubes/tests/integ/misc.py

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#
2+
# The Qubes OS Project, https://www.qubes-os.org/
3+
#
4+
# Copyright (C) 2025 Marek Marczykowski-Górecki
5+
6+
#
7+
# This library is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation; either
10+
# version 2.1 of the License, or (at your option) any later version.
11+
#
12+
# This library is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public
18+
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
19+
import asyncio
20+
import contextlib
21+
import subprocess
22+
import sys
23+
import unittest
24+
from distutils import spawn
25+
26+
import qubes
27+
28+
29+
class TC_06_AppVMMixin(object):
30+
template = None
31+
32+
def setUp(self):
33+
super(TC_06_AppVMMixin, self).setUp()
34+
self.init_default_template(self.template)
35+
36+
def test_010_os_metadata(self):
37+
tpl = self.app.default_template
38+
if self.template.startswith("fedora-"):
39+
self.assertEqual(tpl.features.get("os-distribution"), "fedora")
40+
version = self.template.split("-")[1]
41+
self.assertEqual(tpl.features.get("os-version"), version)
42+
self.assertIsNotNone(tpl.features.get("os-eol"))
43+
elif self.template.startswith("debian-"):
44+
self.assertEqual(tpl.features.get("os-distribution"), "debian")
45+
version = self.template.split("-")[1]
46+
self.assertEqual(tpl.features.get("os-version"), version)
47+
self.assertIsNotNone(tpl.features.get("os-eol"))
48+
elif self.template.startswith("whonix-"):
49+
self.assertEqual(tpl.features.get("os-distribution"), "whonix")
50+
self.assertEqual(tpl.features.get("os-distribution-like"), "debian")
51+
version = self.template.split("-")[2]
52+
self.assertEqual(tpl.features.get("os-version"), version)
53+
elif self.template.startswith("kali-core"):
54+
self.assertEqual(tpl.features.get("os-distribution"), "kali")
55+
self.assertEqual(tpl.features.get("os-distribution-like"), "debian")
56+
57+
@unittest.skipUnless(
58+
spawn.find_executable("xdotool"), "xdotool not installed"
59+
)
60+
def test_121_start_standalone_with_cdrom_vm(self):
61+
cdrom_vmname = self.make_vm_name("cdrom")
62+
self.cdrom_vm = self.app.add_new_vm(
63+
"AppVM", label="red", name=cdrom_vmname
64+
)
65+
self.loop.run_until_complete(self.cdrom_vm.create_on_disk())
66+
self.loop.run_until_complete(self.cdrom_vm.start())
67+
iso_path = self.create_bootable_iso()
68+
with open(iso_path, "rb") as iso_f:
69+
self.loop.run_until_complete(
70+
self.cdrom_vm.run_for_stdio(
71+
"cat > /home/user/boot.iso", stdin=iso_f
72+
)
73+
)
74+
75+
vmname = self.make_vm_name("appvm")
76+
self.vm = self.app.add_new_vm("StandaloneVM", label="red", name=vmname)
77+
self.loop.run_until_complete(self.vm.create_on_disk())
78+
self.vm.kernel = None
79+
self.vm.virt_mode = "hvm"
80+
81+
# start the VM using qvm-start tool, to test --cdrom option there
82+
p = self.loop.run_until_complete(
83+
asyncio.create_subprocess_exec(
84+
"qvm-start",
85+
"--cdrom=" + cdrom_vmname + ":/home/user/boot.iso",
86+
self.vm.name,
87+
stdout=subprocess.PIPE,
88+
stderr=subprocess.STDOUT,
89+
)
90+
)
91+
(stdout, _) = self.loop.run_until_complete(p.communicate())
92+
self.assertEqual(p.returncode, 0, stdout)
93+
# check if VM do not crash instantly
94+
self.loop.run_until_complete(asyncio.sleep(50))
95+
self.assertTrue(self.vm.is_running())
96+
# Type 'halt'
97+
subprocess.check_call(
98+
[
99+
"xdotool",
100+
"search",
101+
"--name",
102+
self.vm.name,
103+
"type",
104+
"--window",
105+
"%1",
106+
"halt\r",
107+
]
108+
)
109+
for _ in range(10):
110+
if not self.vm.is_running():
111+
break
112+
self.loop.run_until_complete(asyncio.sleep(1))
113+
self.assertFalse(self.vm.is_running())
114+
115+
116+
def create_testcases_for_templates():
117+
yield from qubes.tests.create_testcases_for_templates(
118+
"TC_06_AppVM",
119+
TC_06_AppVMMixin,
120+
qubes.tests.SystemTestCase,
121+
module=sys.modules[__name__],
122+
)
123+
124+
125+
def load_tests(loader, tests, pattern):
126+
tests.addTests(loader.loadTestsFromNames(create_testcases_for_templates()))
127+
128+
return tests
129+
130+
131+
qubes.tests.maybe_create_testcases_on_import(create_testcases_for_templates)
132+
133+
# vim: ts=4 sw=4 et

rpm_spec/core-dom0.spec.in

+1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ done
521521
%{python3_sitelib}/qubes/tests/integ/dom0_update.py
522522
%{python3_sitelib}/qubes/tests/integ/vm_update.py
523523
%{python3_sitelib}/qubes/tests/integ/mime.py
524+
%{python3_sitelib}/qubes/tests/integ/misc.py
524525
%{python3_sitelib}/qubes/tests/integ/network.py
525526
%{python3_sitelib}/qubes/tests/integ/network_ipv6.py
526527
%{python3_sitelib}/qubes/tests/integ/grub.py

0 commit comments

Comments
 (0)