diff --git a/qubesadmin/tests/tools/qvm_start.py b/qubesadmin/tests/tools/qvm_start.py index e91651f8..338cdb42 100644 --- a/qubesadmin/tests/tools/qvm_start.py +++ b/qubesadmin/tests/tools/qvm_start.py @@ -78,17 +78,17 @@ def test_010_drive_cdrom(self): self.app.expected_calls[ ('some-vm', 'admin.vm.CurrentState', None, None)] = \ b'0\x00power_state=Halted' - self.app.expected_calls[ - ('dom0', 'admin.vm.device.block.Available', None, None)] = \ - b'0\x00sr0\n' self.app.expected_calls[ ('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 required=True read-only=True')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Assign', 'dom0+sr0', + b"required='yes' attach_automatically='yes' ident='sr0' " + b"devclass='block' backend_domain='dom0' " + b"frontend_domain='some-vm' _devtype='cdrom' " + b"_read-only='True'")] = b'0\x00' self.app.expected_calls[ - ('some-vm', 'admin.vm.device.block.Set.assignment', 'dom0+sr0', - b'False')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Unassign', 'dom0+sr0', None)] = \ + b'0\x00' qubesadmin.tools.qvm_start.main(['--cdrom=dom0:sr0', 'some-vm'], app=self.app) self.assertAllCalled() @@ -101,17 +101,17 @@ def test_011_drive_disk(self): self.app.expected_calls[ ('some-vm', 'admin.vm.CurrentState', None, None)] = \ b'0\x00power_state=Halted' - self.app.expected_calls[ - ('dom0', 'admin.vm.device.block.Available', None, None)] = \ - b'0\x00sdb1\n' self.app.expected_calls[ ('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 required=True read-only=False')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Assign', 'dom0+sdb1', + b"required='yes' attach_automatically='yes' ident='sdb1' " + b"devclass='block' backend_domain='dom0' " + b"frontend_domain='some-vm' _devtype='disk' " + b"_read-only='False'")] = b'0\x00' self.app.expected_calls[ - ('some-vm', 'admin.vm.device.block.Set.assignment', 'dom0+sdb1', - b'False')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Unassign', 'dom0+sdb1', + None)] = b'0\x00' qubesadmin.tools.qvm_start.main(['--hd=dom0:sdb1', 'some-vm'], app=self.app) self.assertAllCalled() @@ -124,17 +124,17 @@ def test_012_drive_disk(self): self.app.expected_calls[ ('some-vm', 'admin.vm.CurrentState', None, None)] = \ b'0\x00power_state=Halted' - self.app.expected_calls[ - ('dom0', 'admin.vm.device.block.Available', None, None)] = \ - b'0\x00sdb1\n' self.app.expected_calls[ ('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 required=True read-only=False')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Assign', 'dom0+sdb1', + b"required='yes' attach_automatically='yes' ident='sdb1' " + b"devclass='block' backend_domain='dom0' " + b"frontend_domain='some-vm' _devtype='disk' " + b"_read-only='False'")] = b'0\x00' self.app.expected_calls[ - ('some-vm', 'admin.vm.device.block.Set.assignment', 'dom0+sdb1', - b'False')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Unassign', 'dom0+sdb1', + None)] = b'0\x00' qubesadmin.tools.qvm_start.main(['--drive=hd:dom0:sdb1', 'some-vm'], app=self.app) self.assertAllCalled() @@ -154,12 +154,15 @@ def test_013_drive_loop_local(self, mock_subprocess): self.app.expected_calls[ ('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 required=True read-only=True')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Assign', 'dom0+loop12', + b"required='yes' attach_automatically='yes' ident='loop12' " + b"devclass='block' backend_domain='dom0' " + b"frontend_domain='some-vm' _devtype='cdrom' " + b"_read-only='True'")] = b'0\x00' self.app.expected_calls[ - ('some-vm', 'admin.vm.device.block.Set.assignment', 'dom0+loop12', - b'False')] = b'0\x00' - mock_subprocess.return_value = b'/dev/loop12' + ('some-vm', 'admin.vm.device.block.Unassign', 'dom0+loop12', None + )] = b'0\x00loop12\n' + mock_subprocess.return_value = b"/dev/loop12" qubesadmin.tools.qvm_start.main([ '--cdrom=dom0:/home/some/image.iso', 'some-vm'], @@ -183,12 +186,14 @@ def test_014_drive_loop_remote(self): self.app.expected_calls[ ('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 required=True read-only=True')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Assign', 'other-vm+loop7', + b"required='yes' attach_automatically='yes' ident='loop7' " + b"devclass='block' backend_domain='other-vm' " + b"frontend_domain='some-vm' _devtype='cdrom' " + b"_read-only='True'")] = b'0\x00' self.app.expected_calls[ - ('some-vm', 'admin.vm.device.block.Set.assignment', - 'other-vm+loop7', - b'False')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Unassign', 'other-vm+loop7', + None)] = b'0\x00' self.app.expected_calls[ ('other-vm', 'admin.vm.feature.CheckWithTemplate', 'vmexec', None)] = b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'vmexec\' not set\x00' @@ -215,8 +220,11 @@ def test_015_drive_failed_start(self): ('some-vm', 'admin.vm.CurrentState', None, None)] = \ b'0\x00power_state=Halted' self.app.expected_calls[ - ('some-vm', 'admin.vm.device.block.Attach', 'other-vm+loop7', - b'devtype=cdrom required=True read-only=True')] = b'0\x00' + ('some-vm', 'admin.vm.device.block.Assign', 'other-vm+loop7', + b"required='yes' attach_automatically='yes' ident='loop7' " + b"devclass='block' backend_domain='other-vm' " + b"frontend_domain='some-vm' _devtype='cdrom' " + b"_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' @@ -239,8 +247,11 @@ def test_016_drive_failed_attach(self): ('some-vm', 'admin.vm.CurrentState', None, None)] = \ b'0\x00power_state=Halted' self.app.expected_calls[ - ('some-vm', 'admin.vm.device.block.Attach', 'other-vm+loop7', - b'devtype=cdrom required=True read-only=True')] = \ + ('some-vm', 'admin.vm.device.block.Assign', 'other-vm+loop7', + b"required='yes' attach_automatically='yes' ident='loop7' " + b"devclass='block' backend_domain='other-vm' " + b"frontend_domain='some-vm' _devtype='cdrom' " + b"_read-only='True'")] = \ b'2\x00QubesException\x00\x00An error occurred\x00' retcode = qubesadmin.tools.qvm_start.main([ '--cdrom=other-vm:loop7', diff --git a/qubesadmin/tools/qvm_start.py b/qubesadmin/tools/qvm_start.py index 27de91ff..39fca0cd 100644 --- a/qubesadmin/tools/qvm_start.py +++ b/qubesadmin/tools/qvm_start.py @@ -157,8 +157,9 @@ def get_drive_assignment(app, drive_str): 'read-only': devtype == 'cdrom' } assignment = qubesadmin.device_protocol.DeviceAssignment( - backend_domain, - ident, + backend_domain=backend_domain, + ident=ident, + devclass='block', options=options, attach_automatically=True, required=True)