dispvm.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. self.app.expected_calls[
  30. ('disp123', 'admin.vm.property.Get', 'qrexec_timeout', None)] = \
  31. b'0\0default=yes type=int 30'
  32. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  33. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  34. vm.cleanup()
  35. self.assertEqual(self.app.service_calls, [
  36. ('disp123', 'test.service', {'connect_timeout': 30}),
  37. ('disp123', 'test.service', b''),
  38. ])
  39. self.assertAllCalled()
  40. def test_001_local_create_specific(self):
  41. self.app.qubesd_connection_type = 'socket'
  42. self.app.expected_calls[
  43. ('test-vm', 'admin.vm.CreateDisposable', None, None)] = \
  44. b'0\0disp123'
  45. self.app.expected_calls[
  46. ('disp123', 'admin.vm.Kill', None, None)] = b'0\0'
  47. self.app.expected_calls[
  48. ('disp123', 'admin.vm.property.Get', 'qrexec_timeout', None)] = \
  49. b'0\0default=yes type=int 30'
  50. vm = qubesadmin.vm.DispVM.from_appvm(self.app, 'test-vm')
  51. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  52. vm.cleanup()
  53. self.assertEqual(self.app.service_calls, [
  54. ('disp123', 'test.service', {'connect_timeout': 30}),
  55. ('disp123', 'test.service', b''),
  56. ])
  57. self.assertAllCalled()
  58. def test_002_local_no_run_cleanup(self):
  59. self.app.qubesd_connection_type = 'socket'
  60. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  61. vm.cleanup()
  62. self.assertEqual(self.app.service_calls, [])
  63. self.assertAllCalled()
  64. def test_010_remote_create_default(self):
  65. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  66. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  67. vm.cleanup()
  68. self.assertEqual(self.app.service_calls, [
  69. ('$dispvm', 'test.service', {}),
  70. ('$dispvm', 'test.service', b''),
  71. ])
  72. self.assertAllCalled()
  73. def test_011_remote_create_specific(self):
  74. vm = qubesadmin.vm.DispVM.from_appvm(self.app, 'test-vm')
  75. (stdout, stderr) = vm.run_service_for_stdio('test.service')
  76. vm.cleanup()
  77. self.assertEqual(self.app.service_calls, [
  78. ('$dispvm:test-vm', 'test.service', {}),
  79. ('$dispvm:test-vm', 'test.service', b''),
  80. ])
  81. self.assertAllCalled()
  82. def test_012_remote_no_run_cleanup(self):
  83. vm = qubesadmin.vm.DispVM.from_appvm(self.app, None)
  84. vm.cleanup()
  85. self.assertEqual(self.app.service_calls, [])
  86. self.assertAllCalled()