Skip to content

Commit

Permalink
Fix ordering of AdminVM and QubesVM
Browse files Browse the repository at this point in the history
AdminVM instances must always compare less than any QubesVM instance.

Fixes: QubesOS/qubes-issues#6998
(cherry picked from commit 5078bd9)
  • Loading branch information
DemiMarie authored and marmarek committed May 13, 2023
1 parent 5674dff commit f8a78a5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions qubes/tests/vm/adminvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,6 @@ def test_710_run_service_for_stdio(self, mock_run_service):
self.assertEqual(exc.exception.returncode, 1)
self.assertEqual(exc.exception.output, b'stdout')
self.assertEqual(exc.exception.stderr, b'stderr')

def test_711_adminvm_ordering(self):
assert(self.vm < qubes.vm.qubesvm.QubesVM(self.app, None, qid=1, name="dom0"))
3 changes: 3 additions & 0 deletions qubes/tests/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2280,3 +2280,6 @@ def property_change(vm, property_name, new_value):

property_change(test_vm, "template_for_dispvms", False)
property_change(test_vm, "template_for_dispvms", True)

def test_801_ordering(self):
assert qubes.vm.qubesvm.QubesVM(self.app, None, qid=1, name="bogus") > qubes.vm.adminvm.AdminVM(self.app, None)
14 changes: 10 additions & 4 deletions qubes/vm/adminvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
import qubes.exc
import qubes.vm
from qubes.vm.qubesvm import _setter_kbd_layout
from qubes.vm import BaseVM


class AdminVM(qubes.vm.BaseVM):
class AdminVM(BaseVM):
'''Dom0'''

dir_path = None
Expand Down Expand Up @@ -82,16 +83,21 @@ def __init__(self, *args, **kwargs):
def __str__(self):
return self.name

def __lt__(self, other):
def __lt__(self, other: object):
if not isinstance(other, BaseVM):
return NotImplemented
# order dom0 before anything
return self.name != other.name
if not isinstance(other, AdminVM):
return True
assert self is other, "multiple instances of AdminVM?"
return False

@property
def attached_volumes(self):
return []

@property
def xid(self):
def xid(self) -> int:
'''Always ``0``.
.. seealso:
Expand Down
5 changes: 5 additions & 0 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import qubes.storage
import qubes.utils
import qubes.vm
import qubes.vm.adminvm
import qubes.vm.mix.net

qmemman_present = False
Expand Down Expand Up @@ -959,6 +960,10 @@ def __hash__(self):
return self.qid

def __lt__(self, other):
if not isinstance(other, qubes.vm.BaseVM):
return NotImplemented
if isinstance(other, qubes.vm.adminvm.AdminVM):
return False
return self.name < other.name

def __xml__(self):
Expand Down

0 comments on commit f8a78a5

Please sign in to comment.