backup.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/python
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2014-2015
  7. # Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  8. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. #
  24. import os
  25. import unittest
  26. import sys
  27. import qubes.tests
  28. class TC_00_Backup(qubes.tests.BackupTestsMixin, qubes.tests.QubesTestCase):
  29. def test_000_basic_backup(self):
  30. vms = self.create_backup_vms()
  31. self.make_backup(vms)
  32. self.remove_vms(vms)
  33. self.restore_backup()
  34. self.remove_vms(vms)
  35. def test_001_compressed_backup(self):
  36. vms = self.create_backup_vms()
  37. self.make_backup(vms, do_kwargs={'compressed': True})
  38. self.remove_vms(vms)
  39. self.restore_backup()
  40. self.remove_vms(vms)
  41. def test_002_encrypted_backup(self):
  42. vms = self.create_backup_vms()
  43. self.make_backup(vms, do_kwargs={'encrypted': True})
  44. self.remove_vms(vms)
  45. self.restore_backup()
  46. self.remove_vms(vms)
  47. def test_003_compressed_encrypted_backup(self):
  48. vms = self.create_backup_vms()
  49. self.make_backup(vms,
  50. do_kwargs={
  51. 'compressed': True,
  52. 'encrypted': True})
  53. self.remove_vms(vms)
  54. self.restore_backup()
  55. self.remove_vms(vms)
  56. def test_004_sparse_multipart(self):
  57. vms = []
  58. vmname = self.make_vm_name('testhvm2')
  59. if self.verbose:
  60. print >>sys.stderr, "-> Creating %s" % vmname
  61. hvmtemplate = self.qc.add_new_vm("QubesTemplateHVm", name=vmname)
  62. hvmtemplate.create_on_disk(verbose=self.verbose)
  63. self.fill_image(os.path.join(hvmtemplate.dir_path, '00file'),
  64. 195*1024*1024-4096*3)
  65. self.fill_image(hvmtemplate.private_img, 195*1024*1024-4096*3)
  66. self.fill_image(hvmtemplate.root_img, 1024*1024*1024, sparse=True)
  67. vms.append(hvmtemplate)
  68. self.qc.save()
  69. self.make_backup(vms)
  70. self.remove_vms(vms)
  71. self.restore_backup()
  72. self.remove_vms(vms)
  73. # TODO: iterate over templates
  74. def test_100_send_to_vm(self):
  75. vms = self.create_backup_vms()
  76. self.backupvm.start()
  77. self.make_backup(vms,
  78. do_kwargs={
  79. 'appvm': self.backupvm,
  80. 'compressed': True,
  81. 'encrypted': True},
  82. target='dd of=/var/tmp/backup-test')
  83. self.remove_vms(vms)
  84. self.restore_backup(source='dd if=/var/tmp/backup-test',
  85. appvm=self.backupvm)
  86. self.remove_vms(vms)