tools/qvm-start: fix starting a VM with cdrom image
1. Output of `losetup` command contains `\n` - strip it. 2. Provide read-only option - if device info hasn't propagated to qubesd yet, it will not be set automatically. Fixes QubesOS/qubes-issues#3146
This commit is contained in:
parent
8476afc306
commit
559cc9b0d6
@ -81,7 +81,7 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
|
||||
('some-vm', 'admin.vm.Start', None, None)] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Attach', 'dom0+sr0',
|
||||
b'devtype=cdrom persistent=True')] = b'0\x00'
|
||||
b'devtype=cdrom persistent=True read-only=True')] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Set.persistent', 'dom0+sr0',
|
||||
b'False')] = b'0\x00'
|
||||
@ -101,7 +101,7 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
|
||||
('some-vm', 'admin.vm.Start', None, None)] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Attach', 'dom0+sdb1',
|
||||
b'devtype=disk persistent=True')] = b'0\x00'
|
||||
b'devtype=disk persistent=True read-only=False')] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Set.persistent', 'dom0+sdb1',
|
||||
b'False')] = b'0\x00'
|
||||
@ -121,7 +121,7 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
|
||||
('some-vm', 'admin.vm.Start', None, None)] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Attach', 'dom0+sdb1',
|
||||
b'devtype=disk persistent=True')] = b'0\x00'
|
||||
b'devtype=disk persistent=True read-only=False')] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Set.persistent', 'dom0+sdb1',
|
||||
b'False')] = b'0\x00'
|
||||
@ -142,7 +142,7 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
|
||||
('some-vm', 'admin.vm.Start', None, None)] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Attach', 'dom0+loop12',
|
||||
b'devtype=cdrom persistent=True')] = b'0\x00'
|
||||
b'devtype=cdrom persistent=True read-only=True')] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Set.persistent', 'dom0+loop12',
|
||||
b'False')] = b'0\x00'
|
||||
@ -168,7 +168,7 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
|
||||
('some-vm', 'admin.vm.Start', None, None)] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Attach', 'other-vm+loop7',
|
||||
b'devtype=cdrom persistent=True')] = b'0\x00'
|
||||
b'devtype=cdrom persistent=True read-only=True')] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Set.persistent',
|
||||
'other-vm+loop7',
|
||||
@ -193,7 +193,7 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
|
||||
b'some-vm class=AppVM state=Running\n'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Attach', 'other-vm+loop7',
|
||||
b'devtype=cdrom persistent=True')] = b'0\x00'
|
||||
b'devtype=cdrom persistent=True read-only=True')] = b'0\x00'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.Start', None, None)] = \
|
||||
b'2\x00QubesException\x00\x00An error occurred\x00'
|
||||
@ -214,7 +214,7 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
|
||||
b'some-vm class=AppVM state=Running\n'
|
||||
self.app.expected_calls[
|
||||
('some-vm', 'admin.vm.device.block.Attach', 'other-vm+loop7',
|
||||
b'devtype=cdrom persistent=True')] = \
|
||||
b'devtype=cdrom persistent=True read-only=True')] = \
|
||||
b'2\x00QubesException\x00\x00An error occurred\x00'
|
||||
retcode = qubesadmin.tools.qvm_start.main([
|
||||
'--cdrom=other-vm:loop7',
|
||||
|
@ -118,13 +118,15 @@ def get_drive_assignment(app, drive_str):
|
||||
except subprocess.CalledProcessError:
|
||||
raise qubesadmin.exc.QubesException(
|
||||
'Failed to setup loop device for %s', ident)
|
||||
loop_name = loop_name.strip()
|
||||
assert loop_name.startswith(b'/dev/loop')
|
||||
ident = loop_name.decode().split('/')[2]
|
||||
# FIXME: synchronize with udev + exposing device in qubesdb
|
||||
|
||||
options = {}
|
||||
if devtype:
|
||||
options['devtype'] = devtype
|
||||
options = {
|
||||
'devtype': devtype,
|
||||
'read-only': devtype == 'cdrom'
|
||||
}
|
||||
assignment = qubesadmin.devices.DeviceAssignment(
|
||||
backend_domain,
|
||||
ident,
|
||||
|
Loading…
Reference in New Issue
Block a user