Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test improvements #622

Merged
merged 6 commits into from
Oct 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion linux/systemd/qubes-core.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Unit]
Description=Qubes Dom0 startup setup
After=qubes-db-dom0.service libvirtd.service xenconsoled.service qubesd.service qubes-qmemman.service
After=qubes-db-dom0.service libvirtd.service virtxend.socket xenconsoled.service qubesd.service qubes-qmemman.service
# Cover legacy init.d script

[Service]
Expand Down
18 changes: 8 additions & 10 deletions qubes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
self._vm = self._connection._conn.lookupByUUID(self._vm.UUID())
return is_dead

def close(self):
self._vm = None
self._connection = None

Check warning on line 97 in qubes/app.py

View check run for this annotation

Codecov / codecov/patch

qubes/app.py#L96-L97

Added lines #L96 - L97 were not covered by tests

def __getattr__(self, attrname):
attr = getattr(self._vm, attrname)
if not isinstance(attr, collections.abc.Callable):
Expand All @@ -100,12 +104,14 @@
@functools.wraps(attr)
def wrapper(*args, **kwargs):
try:
return attr(*args, **kwargs)
return getattr(self._vm, attrname)(*args, **kwargs)

Check warning on line 107 in qubes/app.py

View check run for this annotation

Codecov / codecov/patch

qubes/app.py#L107

Added line #L107 was not covered by tests
except libvirt.libvirtError:
if self._reconnect_if_dead():
return getattr(self._vm, attrname)(*args, **kwargs)
raise

del wrapper.__wrapped__
del attr

Check warning on line 114 in qubes/app.py

View check run for this annotation

Codecov / codecov/patch

qubes/app.py#L113-L114

Added lines #L113 - L114 were not covered by tests
return wrapper


Expand Down Expand Up @@ -531,15 +537,7 @@
if not vm.is_halted():
raise qubes.exc.QubesVMNotHaltedError(vm)
self.app.fire_event('domain-pre-delete', pre_event=True, vm=vm)
try:
if vm.libvirt_domain:
vm.libvirt_domain.undefine()
# pylint: disable=protected-access
vm._libvirt_domain = None
except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
# already undefined
pass
vm.libvirt_undefine()
del self._dict[vm.qid]
self.app.fire_event('domain-delete', vm=vm)
if getattr(vm, 'dispid', None):
Expand Down
3 changes: 3 additions & 0 deletions qubes/tests/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ def is_halted(self):
def get_power_state(self):
return "Halted"

def libvirt_undefine(self):
pass


class TestApp(qubes.tests.TestEmitter):
pass
Expand Down
4 changes: 2 additions & 2 deletions qubes/tests/integ/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_140_libvirt_events_reconnect(self):
self.loop.run_until_complete(self.vm.create_on_disk())
self.loop.run_until_complete(self.vm.start())
p = self.loop.run_until_complete(asyncio.create_subprocess_exec(
'systemctl', 'restart', 'libvirtd'))
'systemctl', 'restart', 'virtxend'))
self.loop.run_until_complete(p.communicate())
# check if events still works
self.domain_paused_received = False
Expand All @@ -302,7 +302,7 @@ def test_141_libvirt_objects_reconnect(self):
# make sure libvirt object is cached
self.app.domains[0].libvirt_domain.isActive()
p = self.loop.run_until_complete(asyncio.create_subprocess_exec(
'systemctl', 'restart', 'libvirtd'))
'systemctl', 'restart', 'virtxend'))
self.loop.run_until_complete(p.communicate())
# trigger reconnect
with self.assertNotRaises(libvirt.libvirtError):
Expand Down
2 changes: 2 additions & 0 deletions qubes/tests/integ/vm_qrexec_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ async def _test_300_bug_1028_gui_memory_pinning(self):

# exclude from memory balancing
self.testvm1.features['service.meminfo-writer'] = False
# prevent Whonix startup notifications from interfering
self.testvm1.features['service.whonix-tor-disable'] = True
await self.testvm1.start()
await self.wait_for_session(self.testvm1)

Expand Down
13 changes: 13 additions & 0 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,19 @@
# fire hooks
await self.fire_event_async('domain-clone-files', src=src)

def libvirt_undefine(self):
"""Undefine domain object in libvirt"""
try:
if self.libvirt_domain:
self.libvirt_domain.undefine()
except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:

Check warning on line 1939 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1937-L1939

Added lines #L1937 - L1939 were not covered by tests
# already undefined
pass

Check warning on line 1941 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1941

Added line #L1941 was not covered by tests
if self._libvirt_domain is not None:
self._libvirt_domain.close()
self._libvirt_domain = None

Check warning on line 1944 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1943-L1944

Added lines #L1943 - L1944 were not covered by tests

#
# methods for querying domain state
#
Expand Down