Skip to content

Commit

Permalink
q-dev: update tests and make pylint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 30, 2024
1 parent 08b899c commit 727133f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qubes/ext/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def on_tag_add(self, vm, event, tag, **kwargs):
def on_device_attach(
self, vm, event, dest, arg, device, mode, options, **kwargs
):
# pylint: disable=unused-argument
# pylint: disable=unused-argument,too-many-positional-arguments
# ignore auto-attachment
if mode != 'manual':
return

Check warning on line 177 in qubes/ext/admin.py

View check run for this annotation

Codecov / codecov/patch

qubes/ext/admin.py#L176-L177

Added lines #L176 - L177 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion qubes/ext/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ async def on_domain_shutdown(self, vm, event, **_kwargs):
if front_vm is None:
continue
dev = BlockDevice(vm, dev_id)
vm.fire_event(f"device-removed:block", port=dev.port)
vm.fire_event("device-removed:block", port=dev.port)
await self.detach_and_notify(front_vm, dev.port)

Check warning on line 646 in qubes/ext/block.py

View check run for this annotation

Codecov / codecov/patch

qubes/ext/block.py#L645-L646

Added lines #L645 - L646 were not covered by tests
continue
for dev_id, front_vm in self.devices_cache[domain.name].items():
Expand Down
6 changes: 3 additions & 3 deletions qubes/tests/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class TestVMM(object):
def __init__(self, offline_mode=False):
self.offline_mode = offline_mode
self.xs = unittest.mock.Mock()
self.libvirt_mock = unittest.mock.Mock()

@property
def libvirt_conn(self):
if self.offline_mode:
import libvirt
raise libvirt.libvirtError('phony error')
else:
libvirt_mock = unittest.mock.Mock()
vm_mock = libvirt_mock.lookupByUUID.return_value
vm_mock = self.libvirt_mock.lookupByUUID.return_value
vm_mock.isActive.return_value = False
return libvirt_mock
return self.libvirt_mock

class TestHost(object):
# pylint: disable=too-few-public-methods
Expand Down
48 changes: 46 additions & 2 deletions qubes/tests/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def __init__(self, data=None):
def write(self, path, value):
self.data[path] = value

def read(self, path):
return self.data[path]

def rm(self, path):
if path.endswith('/'):
for key in [x for x in self.data if x.startswith(path)]:
Expand Down Expand Up @@ -1303,6 +1306,26 @@ def test_600_libvirt_xml_hvm_pcidev(self):
my_uuid = '7db78950-c467-4863-94d1-af59806384ea'
# required for PCI devices listing
self.app.vmm.offline_mode = False
hostdev_details = unittest.mock.Mock(**{
'XMLDesc.return_value': """
<device>
<name>pci_0000_00_00_0</name>
<path>/sys/devices/pci0000:00/0000:00:00.0</path>
<parent>computer</parent>
<capability type='pci'>
<class>0x060000</class>
<domain>0</domain>
<bus>0</bus>
<slot>0</slot>
<function>0</function>
<product id='0x0000'>Unknown</product>
<vendor id='0x8086'>Intel Corporation</vendor>
</capability>
</device>""",
})
self.app.vmm.libvirt_mock = unittest.mock.Mock(**{
'nodeDeviceLookupByName.return_value': hostdev_details
})
dom0 = self.get_vm(name='dom0', qid=0)
vm = self.get_vm(uuid=my_uuid)
vm.netvm = None
Expand All @@ -1321,8 +1344,7 @@ def test_600_libvirt_xml_hvm_pcidev(self):
),
mode='required',
)
vm.devices['pci']._set.add(
assignment)
vm.devices['pci']._set.add(assignment)
libvirt_xml = vm.create_config_file()
self.assertXMLEqual(lxml.etree.XML(libvirt_xml),
lxml.etree.XML(expected))
Expand Down Expand Up @@ -1391,6 +1413,26 @@ def test_600_libvirt_xml_hvm_pcidev_s0ix(self):
my_uuid = '7db78950-c467-4863-94d1-af59806384ea'
# required for PCI devices listing
self.app.vmm.offline_mode = False
hostdev_details = unittest.mock.Mock(**{
'XMLDesc.return_value': """
<device>
<name>pci_0000_00_00_0</name>
<path>/sys/devices/pci0000:00/0000:00:00.0</path>
<parent>computer</parent>
<capability type='pci'>
<class>0x060000</class>
<domain>0</domain>
<bus>0</bus>
<slot>0</slot>
<function>0</function>
<product id='0x0000'>Unknown</product>
<vendor id='0x8086'>Intel Corporation</vendor>
</capability>
</device>""",
})
self.app.vmm.libvirt_mock = unittest.mock.Mock(**{
'nodeDeviceLookupByName.return_value': hostdev_details
})
dom0 = self.get_vm(name='dom0', qid=0)
dom0.features['suspend-s0ix'] = True
vm = self.get_vm(uuid=my_uuid)
Expand Down Expand Up @@ -1478,6 +1520,7 @@ def test_600_libvirt_xml_hvm_cdrom_boot(self):
'/qubes-block-devices/sda/desc': b'Test device',
'/qubes-block-devices/sda/size': b'1024000',
'/qubes-block-devices/sda/mode': b'r',
'/qubes-block-devices/sda/parent': b'',
}
test_qdb = TestQubesDB(qdb)
dom0 = qubes.vm.adminvm.AdminVM(self.app, None)
Expand Down Expand Up @@ -1573,6 +1616,7 @@ def test_600_libvirt_xml_hvm_cdrom_dom0_kernel_boot(self):
'/qubes-block-devices/sda/desc': b'Test device',
'/qubes-block-devices/sda/size': b'1024000',
'/qubes-block-devices/sda/mode': b'r',
'/qubes-block-devices/sda/parent': b'',
}
test_qdb = TestQubesDB(qdb)
dom0 = qubes.vm.adminvm.AdminVM(self.app, None)
Expand Down

0 comments on commit 727133f

Please sign in to comment.