qvm_clone.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_clone
  23. class TC_00_qvm_clone(qubesadmin.tests.QubesTestCase):
  24. def test_000_simple(self):
  25. self.app.expected_calls[('test-vm', 'mgmt.vm.Clone', None,
  26. b'name=new-vm')] = b'0\x00'
  27. self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
  28. b'0\x00new-vm class=AppVM state=Halted\n' \
  29. b'test-vm class=AppVM state=Halted\n'
  30. qubesadmin.tools.qvm_clone.main(['test-vm', 'new-vm'], app=self.app)
  31. self.assertAllCalled()
  32. def test_001_missing_vm(self):
  33. with self.assertRaises(SystemExit):
  34. with qubesadmin.tests.tools.StderrBuffer() as stderr:
  35. qubesadmin.tools.qvm_clone.main(['test-vm'], app=self.app)
  36. self.assertIn('NAME', stderr.getvalue())
  37. self.assertAllCalled()
  38. def test_004_pool(self):
  39. self.app.expected_calls[('test-vm', 'mgmt.vm.CloneInPool',
  40. None, b'name=new-vm pool=some-pool')] = b'0\x00'
  41. self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
  42. b'0\x00new-vm class=AppVM state=Halted\n' \
  43. b'test-vm class=AppVM state=Halted\n'
  44. qubesadmin.tools.qvm_clone.main(['-P', 'some-pool', 'test-vm', 'new-vm'],
  45. app=self.app)
  46. self.assertAllCalled()
  47. def test_005_pools(self):
  48. self.app.expected_calls[('test-vm', 'mgmt.vm.CloneInPool',
  49. None, b'name=new-vm pool:private=some-pool '
  50. b'pool:volatile=other-pool')] = b'0\x00'
  51. self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
  52. b'0\x00new-vm class=AppVM state=Halted\n' \
  53. b'test-vm class=AppVM state=Halted\n'
  54. qubesadmin.tools.qvm_clone.main(['--pool', 'private=some-pool',
  55. '--pool', 'volatile=other-pool', 'test-vm', 'new-vm'],
  56. app=self.app)
  57. self.assertAllCalled()