qvm_check.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. # The Qubes OS Project, https://www.qubes-os.org/
  3. #
  4. # Copyright (C) 2016 Marek Marczykowski-Górecki
  5. # <marmarek@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. import qubes
  22. import qubes.tools.qvm_check
  23. import qubes.tests
  24. import qubes.vm.appvm
  25. class TC_00_qvm_check(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  26. def setUp(self):
  27. super(TC_00_qvm_check, self).setUp()
  28. self.init_default_template()
  29. self.sharedopts = ['--qubesxml', qubes.tests.XMLPATH]
  30. self.vm1 = self.app.add_new_vm(qubes.vm.appvm.AppVM,
  31. name=self.make_vm_name('vm1'),
  32. template=self.app.default_template,
  33. label='red')
  34. self.vm1.create_on_disk()
  35. self.app.save()
  36. def test_000_exists(self):
  37. self.assertEqual(0, qubes.tools.qvm_check.main(
  38. self.sharedopts + [self.vm1.name]))
  39. with self.assertRaises(SystemExit):
  40. qubes.tools.qvm_check.main(
  41. self.sharedopts + ['test-no-such-vm'])
  42. def test_001_running(self):
  43. self.assertEqual(1, qubes.tools.qvm_check.main(
  44. self.sharedopts + ['--running', self.vm1.name]))
  45. self.vm1.start()
  46. self.assertEqual(0, qubes.tools.qvm_check.main(
  47. self.sharedopts + ['--running', self.vm1.name]))
  48. def test_002_paused(self):
  49. self.assertEqual(1, qubes.tools.qvm_check.main(
  50. self.sharedopts + ['--paused', self.vm1.name]))
  51. self.vm1.start()
  52. self.assertEqual(1, qubes.tools.qvm_check.main(
  53. self.sharedopts + ['--paused', self.vm1.name]))
  54. self.vm1.pause()
  55. self.assertEqual(0, qubes.tools.qvm_check.main(
  56. self.sharedopts + ['--paused', self.vm1.name]))
  57. def test_003_template(self):
  58. self.assertEqual(1, qubes.tools.qvm_check.main(
  59. self.sharedopts + ['--template', self.vm1.name]))
  60. self.assertEqual(0, qubes.tools.qvm_check.main(
  61. self.sharedopts + ['--template', self.app.default_template.name]))