dispvm.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*- encoding: utf-8 -*-
  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.vm
  22. class TC_00_Dispvm(qubesadmin.tests.QubesTestCase):
  23. def test_000_local_create_default(self):
  24. self.app.qubesd_connection_type = 'socket'
  25. self.app.expected_calls[
  26. ('dom0', 'admin.vm.CreateDisposable', None, None)] = b'0\0disp123'
  27. self.app.expected_calls[
  28. ('disp123', 'admin.vm.Kill', None, None)] = b'0\0'
  29. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  30. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  31. vm.cleanup()
  32. self.assertEqual(self.app.service_calls, [
  33. ('disp123', 'test.service', {}),
  34. ('disp123', 'test.service', b''),
  35. ])
  36. self.assertAllCalled()
  37. def test_001_local_create_specific(self):
  38. self.app.qubesd_connection_type = 'socket'
  39. self.app.expected_calls[
  40. ('test-vm', 'admin.vm.CreateDisposable', None, None)] = \
  41. b'0\0disp123'
  42. self.app.expected_calls[
  43. ('disp123', 'admin.vm.Kill', None, None)] = b'0\0'
  44. vm = qubesadmin.vm.DispVM.from_appvm(self.app, 'test-vm')
  45. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  46. vm.cleanup()
  47. self.assertEqual(self.app.service_calls, [
  48. ('disp123', 'test.service', {}),
  49. ('disp123', 'test.service', b''),
  50. ])
  51. self.assertAllCalled()
  52. def test_002_local_no_run_cleanup(self):
  53. self.app.qubesd_connection_type = 'socket'
  54. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  55. vm.cleanup()
  56. self.assertEqual(self.app.service_calls, [])
  57. self.assertAllCalled()
  58. def test_010_remote_create_default(self):
  59. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  60. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  61. vm.cleanup()
  62. self.assertEqual(self.app.service_calls, [
  63. ('$dispvm', 'test.service', {}),
  64. ('$dispvm', 'test.service', b''),
  65. ])
  66. self.assertAllCalled()
  67. def test_011_remote_create_specific(self):
  68. vm = qubesadmin.vm.DispVM.from_appvm(self.app, 'test-vm')
  69. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  70. vm.cleanup()
  71. self.assertEqual(self.app.service_calls, [
  72. ('$dispvm:test-vm', 'test.service', {}),
  73. ('$dispvm:test-vm', 'test.service', b''),
  74. ])
  75. self.assertAllCalled()
  76. def test_012_remote_no_run_cleanup(self):
  77. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  78. vm.cleanup()
  79. self.assertEqual(self.app.service_calls, [])
  80. self.assertAllCalled()