qvm_remove.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. import qubesadmin.tests
  21. import qubesadmin.tests.tools
  22. import qubesadmin.tools.qvm_remove
  23. import unittest.mock
  24. class TC_00_qvm_remove(qubesadmin.tests.QubesTestCase):
  25. def test_000_single(self):
  26. self.app.expected_calls[
  27. ('dom0', 'admin.vm.List', None, None)] = \
  28. b'0\x00some-vm class=AppVM state=Running\n'
  29. self.app.expected_calls[
  30. ('some-vm', 'admin.vm.Remove', None, None)] = \
  31. b'0\x00\n'
  32. qubesadmin.tools.qvm_remove.main(['-f', 'some-vm'], app=self.app)
  33. self.assertAllCalled()
  34. @unittest.mock.patch('qubesadmin.utils.vm_dependencies')
  35. def test_100_dependencies(self, mock_dependencies):
  36. self.app.expected_calls[
  37. ('dom0', 'admin.vm.List', None, None)] = \
  38. b'0\x00some-vm class=AppVM state=Running\n'
  39. self.app.expected_calls[
  40. ('some-vm', 'admin.vm.Remove', None, None)] = \
  41. b'2\x00QubesVMInUseError\x00\x00An error occurred\x00'
  42. mock_dependencies.return_value = \
  43. [(None, 'default_template'), (self.app.domains['some-vm'], 'netvm')]
  44. qubesadmin.tools.qvm_remove.main(['-f', 'some-vm'], app=self.app)
  45. self.assertTrue(mock_dependencies.called,
  46. "Dependencies check not called.")