qvm_features.py 2.7 KB

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