Move devices check to on_domain_pre_deleted
This commit is contained in:
parent
b09a137b26
commit
f1ff6c26d8
@ -1201,14 +1201,6 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI):
|
||||
if not self.dest.is_halted():
|
||||
raise qubes.exc.QubesVMNotHaltedError(self.dest)
|
||||
|
||||
assignments = self.dest.get_provided_assignments()
|
||||
if assignments:
|
||||
desc = ', '.join(
|
||||
assignment.ident for assignment in assignments)
|
||||
raise qubes.exc.QubesVMInUseError(self.dest,
|
||||
'VM has devices attached persistently to other VMs: ' +
|
||||
desc)
|
||||
|
||||
if self.dest.installed_by_rpm:
|
||||
raise qubes.exc.QubesVMInUseError(self.dest,
|
||||
"VM installed by package manager: " + self.dest.name)
|
||||
|
@ -1462,6 +1462,15 @@ class Qubes(qubes.PropertyHolder):
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
assignments = vm.get_provided_assignments()
|
||||
if assignments:
|
||||
desc = ', '.join(
|
||||
assignment.ident for assignment in assignments)
|
||||
raise qubes.exc.QubesVMInUseError(
|
||||
vm,
|
||||
'VM has devices attached persistently to other VMs: ' +
|
||||
desc)
|
||||
|
||||
@qubes.events.handler('domain-delete')
|
||||
def on_domain_deleted(self, event, vm):
|
||||
# pylint: disable=unused-argument
|
||||
|
@ -673,6 +673,15 @@ class TC_90_Qubes(qubes.tests.QubesTestCase):
|
||||
with self.assertRaises(qubes.exc.QubesVMInUseError):
|
||||
del self.app.domains[appvm]
|
||||
|
||||
def test_206_remove_attached(self):
|
||||
# See also qubes.tests.api_admin.
|
||||
vm = self.app.add_new_vm(
|
||||
'AppVM', name='test-vm', template=self.template, label='red')
|
||||
assignment = mock.Mock(ident='1234')
|
||||
vm.get_provided_assignments = lambda: [assignment]
|
||||
with self.assertRaises(qubes.exc.QubesVMInUseError):
|
||||
del self.app.domains[vm]
|
||||
|
||||
@qubes.tests.skipUnlessGit
|
||||
def test_900_example_xml_in_doc(self):
|
||||
self.assertXMLIsValid(
|
||||
|
Loading…
Reference in New Issue
Block a user