Skip to content

Commit

Permalink
q-dev: update and fix tests for qvm-start
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed May 26, 2024
1 parent 1ec3549 commit dd7882b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
81 changes: 46 additions & 35 deletions qubesadmin/tests/tools/qvm_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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'],
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions qubesadmin/tools/qvm_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dd7882b

Please sign in to comment.