Skip to content

Commit 39133f4

Browse files
committed
Merge remote-tracking branch 'origin/pr/299'
* origin/pr/299: add tests fix QubesOS/qubes-issues/issues/9354
2 parents 55ebbbe + 3e5edbf commit 39133f4

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

qubesadmin/tests/tools/qvm_device.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,40 @@ def test_001_list_assigned_required(self):
8686
# This shouldn't be listed
8787
self.expected_device_call(
8888
'test-vm2', 'Available',
89-
b"0\0dev2 ident='dev1' devclass='testclass' backend_domain='test-vm2'\n")
90-
self.expected_device_call('test-vm3', 'Available')
89+
b"0\0dev2 ident='dev2' devclass='testclass' backend_domain='test-vm2'\n")
90+
self.expected_device_call(
91+
'test-vm3', 'Available',
92+
b"0\0dev3 ident='dev3' devclass='testclass' backend_domain='test-vm3' vendor='evil inc.' product='test-device-3'\n"
93+
)
9194
self.expected_device_call('test-vm1', 'Attached')
9295
self.expected_device_call('test-vm2', 'Attached')
9396
self.expected_device_call('test-vm3', 'Attached')
9497
self.expected_device_call('test-vm1', 'Assigned')
95-
self.expected_device_call('test-vm2', 'Assigned')
9698
self.expected_device_call(
97-
'test-vm3', 'Assigned',
99+
'test-vm2', 'Assigned',
98100
b"0\0test-vm1+dev1 ident='dev1' devclass='testclass' "
99101
b"backend_domain='test-vm1' attach_automatically='yes' "
102+
b"required='yes' _option='other option' _extra_opt='yes'\n"
103+
b"test-vm3+dev3 ident='dev3' devclass='testclass' "
104+
b"backend_domain='test-vm3' attach_automatically='yes' "
100105
b"required='yes'\n"
101106
)
107+
self.expected_device_call(
108+
'test-vm3', 'Assigned',
109+
b"0\0test-vm1+dev1 ident='dev1' devclass='testclass' "
110+
b"backend_domain='test-vm1' attach_automatically='yes' "
111+
b"required='yes' _option='test option'\n"
112+
)
102113

103114
with qubesadmin.tests.tools.StdoutBuffer() as buf:
104115
qubesadmin.tools.qvm_device.main(
105116
['testclass', 'list', 'test-vm3'], app=self.app)
106117
self.assertEqual(
107118
buf.getvalue(),
108-
'test-vm1:dev1 ?******: itl test-device test-vm3\n'
119+
'test-vm1:dev1 ?******: itl test-device '
120+
'test-vm2 (option=other option, extra_opt=yes), '
121+
'test-vm3 (option=test option)\n'
122+
'test-vm3:dev3 ?******: evil inc. test-device-3 test-vm2\n'
109123
)
110124

111125
def test_002_list_attach(self):

qubesadmin/tools/qvm_device.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def list_devices(args):
9191
for dev in result:
9292
for vm in app.domains:
9393
frontends = _load_frontends_info(vm, dev, args.devclass)
94-
if frontends is not None:
95-
result[dev].frontends.append(frontends)
94+
result[dev].frontends.extend(frontends)
9695

9796
qubesadmin.tools.print_table(prepare_table(result.values()))
9897

@@ -132,19 +131,20 @@ def _load_frontends_info(vm, dev, devclass):
132131
Returns string of vms to which a device is connected or `None`.
133132
"""
134133
if vm == dev.backend_domain:
135-
return None
134+
return
136135

137136
try:
138137
for assignment in vm.devices[devclass].get_dedicated_devices():
139138
if dev != assignment:
140-
return None
139+
continue
141140
if assignment.options:
142-
return '{!s} ({})'.format(
141+
yield '{!s} ({})'.format(
143142
vm, ', '.join('{}={}'.format(key, value)
144143
for key, value in assignment.options.items()))
145-
return str(vm)
144+
else:
145+
yield str(vm)
146146
except qubesadmin.exc.QubesVMNotFoundError:
147-
return None
147+
pass
148148

149149

150150
def attach_device(args):

0 commit comments

Comments
 (0)