From 3548ee1163c14b2f921ebc8b55ffb390167fbe4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 22 Sep 2017 21:26:49 +0200 Subject: [PATCH] ext/block: properly list devtype=cdrom option --- qubes/ext/block.py | 2 ++ qubes/tests/devices_block.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/qubes/ext/block.py b/qubes/ext/block.py index 209fb240..38d5ae28 100644 --- a/qubes/ext/block.py +++ b/qubes/ext/block.py @@ -205,6 +205,8 @@ class BlockDeviceExtension(qubes.ext.Extension): else: options['read-only'] = 'no' options['frontend-dev'] = frontend_dev + if disk.get('device') != 'disk': + options['devtype'] = disk.get('device') if dev_path.startswith('/dev/'): ident = dev_path[len('/dev/'):] diff --git a/qubes/tests/devices_block.py b/qubes/tests/devices_block.py index a2e385ae..8adbf806 100644 --- a/qubes/tests/devices_block.py +++ b/qubes/tests/devices_block.py @@ -328,6 +328,29 @@ class TC_00_Block(qubes.tests.QubesTestCase): self.assertEqual(options['frontend-dev'], 'xvdi') self.assertEqual(options['read-only'], 'no') + def test_033_list_attached_cdrom(self): + disk = ''' + + + + + + + + ''' + vm = TestVM({}, domain_xml=domain_xml_template.format(disk)) + vm.app.domains['test-vm'] = vm + vm.app.domains['sys-usb'] = TestVM({}, name='sys-usb') + devices = sorted(list(self.ext.on_device_list_attached(vm, ''))) + self.assertEqual(len(devices), 1) + dev = devices[0][0] + options = devices[0][1] + self.assertEqual(dev.backend_domain, vm.app.domains['sys-usb']) + self.assertEqual(dev.ident, 'sr0') + self.assertEqual(options['frontend-dev'], 'xvdi') + self.assertEqual(options['read-only'], 'yes') + self.assertEqual(options['devtype'], 'cdrom') + def test_040_attach(self): back_vm = TestVM(name='sys-usb', qdb={ '/qubes-block-devices/sda': b'',