backupcompatibility.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. #
  2. # The Qubes OS Project, http://www.qubes-os.org
  3. #
  4. # Copyright (C) 2014 Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. #
  20. from multiprocessing import Queue
  21. import os
  22. import shutil
  23. import subprocess
  24. import unittest
  25. import sys
  26. import re
  27. import qubes.tests
  28. import qubes.tests.integ.backup
  29. QUBESXML_R2B2 = '''
  30. <QubesVmCollection updatevm="3" default_kernel="3.7.6-2" default_netvm="3" default_fw_netvm="2" default_template="1" clockvm="2">
  31. <QubesTemplateVm installed_by_rpm="True" kernel="3.7.6-2" uses_default_kernelopts="True" qid="1" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="fedora-18-x64.conf" label="black" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-18-x64" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/fedora-18-x64"/>
  32. <QubesNetVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="2" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="netvm.conf" label="red" template_qid="1" kernelopts="iommu=soft swiotlb=4096" memory="200" default_user="user" volatile_img="volatile.img" services="{'ntpd': False, 'meminfo-writer': False}" maxmem="1535" pcidevs="['02:00.0', '03:00.0']" name="netvm" netid="1" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/netvm"/>
  33. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="3" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="firewallvm.conf" label="green" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="firewallvm" netid="2" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/firewallvm"/>
  34. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="4" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="True" conf_file="fedora-18-x64-dvm.conf" label="gray" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-18-x64-dvm" private_img="private.img" vcpus="1" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/fedora-18-x64-dvm"/>
  35. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="5" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-work.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-work" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-work"/>
  36. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="6" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="banking.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="banking" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/banking"/>
  37. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="7" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="personal.conf" label="yellow" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="personal" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/personal"/>
  38. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="8" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="untrusted.conf" label="red" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="12" uses_default_netvm="False" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="untrusted" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/untrusted"/>
  39. <QubesTemplateVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="9" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-template-clone.conf" label="green" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-template-clone" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/test-template-clone"/>
  40. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="10" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-custom-template-appvm.conf" label="yellow" template_qid="9" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-custom-template-appvm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-custom-template-appvm"/>
  41. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="11" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-standalonevm.conf" label="blue" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-standalonevm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-standalonevm"/>
  42. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="12" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-testproxy.conf" label="red" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="3" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-testproxy" netid="3" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/test-testproxy"/>
  43. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="13" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="testproxy2.conf" label="red" template_qid="9" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="testproxy2" netid="4" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/testproxy2"/>
  44. <QubesHVm installed_by_rpm="False" netvm_qid="none" qid="14" include_in_backups="True" timezone="localtime" qrexec_timeout="60" conf_file="test-testhvm.conf" label="purple" template_qid="none" internal="False" memory="512" uses_default_netvm="True" services="{'meminfo-writer': False}" default_user="user" pcidevs="[]" name="test-testhvm" qrexec_installed="False" private_img="private.img" drive="None" vcpus="2" root_img="root.img" guiagent_installed="False" debug="False" dir_path="/var/lib/qubes/appvms/test-testhvm"/>
  45. <QubesDisposableVm dispid="50" firewall_conf="firewall.xml" label="red" name="disp50" netvm_qid="2" qid="15" template_qid="1"/>
  46. </QubesVmCollection>
  47. '''
  48. QUBESXML_R2 = '''
  49. <QubesVmCollection updatevm="3" default_kernel="3.7.6-2" default_netvm="3" default_fw_netvm="2" default_template="1" clockvm="2">
  50. <QubesTemplateVm installed_by_rpm="True" kernel="3.7.6-2" uses_default_kernelopts="True" qid="1" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="fedora-20-x64.conf" label="black" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{ 'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-20-x64" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/fedora-20-x64"/>
  51. <QubesNetVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="2" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="netvm.conf" label="red" template_qid="1" kernelopts="iommu=soft swiotlb=4096" memory="200" default_user="user" volatile_img="volatile.img" services="{'ntpd': False, 'meminfo-writer': False}" maxmem="1535" pcidevs="['02:00.0', '03:00.0']" name="netvm" netid="1" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/netvm"/>
  52. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="3" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="firewallvm.conf" label="green" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="firewallvm" netid="2" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/firewallvm"/>
  53. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="4" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="True" conf_file="fedora-20-x64-dvm.conf" label="gray" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{ 'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-20-x64-dvm" private_img="private.img" vcpus="1" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/fedora-20-x64-dvm"/>
  54. <QubesAppVm backup_content="True" backup_path="appvms/test-work" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="5" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-work.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-work" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-work"/>
  55. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="6" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="banking.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="banking" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/banking"/>
  56. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="7" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="personal.conf" label="yellow" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="personal" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/personal"/>
  57. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="8" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="untrusted.conf" label="red" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="12" uses_default_netvm="False" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="untrusted" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/untrusted"/>
  58. <QubesTemplateVm backup_size="104857600" backup_content="True" backup_path="vm-templates/test-template-clone" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="9" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-template-clone.conf" label="green" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-template-clone" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/test-template-clone"/>
  59. <QubesAppVm backup_size="104857600" backup_content="True" backup_path="appvms/test-custom-template-appvm" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="10" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-custom-template-appvm.conf" label="yellow" template_qid="9" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-custom-template-appvm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-custom-template-appvm"/>
  60. <QubesAppVm backup_size="104857600" backup_content="True" backup_path="appvms/test-standalonevm" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="11" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-standalonevm.conf" label="blue" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-standalonevm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-standalonevm"/>
  61. <QubesProxyVm backup_size="104857600" backup_content="True" backup_path="servicevms/test-testproxy" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="12" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-testproxy.conf" label="red" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="3" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-testproxy" netid="3" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/test-testproxy"/>
  62. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="13" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="testproxy2.conf" label="red" template_qid="9" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="testproxy2" netid="4" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/testproxy2"/>
  63. <QubesHVm backup_size="104857600" backup_content="True" backup_path="appvms/test-testhvm" installed_by_rpm="False" netvm_qid="none" qid="14" include_in_backups="True" timezone="localtime" qrexec_timeout="60" conf_file="test-testhvm.conf" label="purple" template_qid="none" internal="False" memory="512" uses_default_netvm="True" services="{'meminfo-writer': False}" default_user="user" pcidevs="[]" name="test-testhvm" qrexec_installed="False" private_img="private.img" drive="None" vcpus="2" root_img="root.img" guiagent_installed="False" debug="False" dir_path="/var/lib/qubes/appvms/test-testhvm"/>
  64. <QubesDisposableVm dispid="50" firewall_conf="firewall.xml" label="red" name="disp50" netvm_qid="2" qid="15" template_qid="1"/>
  65. </QubesVmCollection>
  66. '''
  67. MANGLED_SUBDIRS_R2 = {
  68. "test-work": "vm5",
  69. "test-template-clone": "vm9",
  70. "test-custom-template-appvm": "vm10",
  71. "test-standalonevm": "vm11",
  72. "test-testproxy": "vm12",
  73. "test-testhvm": "vm14",
  74. }
  75. APPTEMPLATE_R2B2 = '''
  76. [Desktop Entry]
  77. Name=%VMNAME%: {name}
  78. GenericName=%VMNAME%: {name}
  79. GenericName[ca]=%VMNAME%: Navegador web
  80. GenericName[cs]=%VMNAME%: Webový prohlížeč
  81. GenericName[es]=%VMNAME%: Navegador web
  82. GenericName[fa]=%VMNAME%: مرورر اینترنتی
  83. GenericName[fi]=%VMNAME%: WWW-selain
  84. GenericName[fr]=%VMNAME%: Navigateur Web
  85. GenericName[hu]=%VMNAME%: Webböngésző
  86. GenericName[it]=%VMNAME%: Browser Web
  87. GenericName[ja]=%VMNAME%: ウェブ・ブラウザ
  88. GenericName[ko]=%VMNAME%: 웹 브라우저
  89. GenericName[nb]=%VMNAME%: Nettleser
  90. GenericName[nl]=%VMNAME%: Webbrowser
  91. GenericName[nn]=%VMNAME%: Nettlesar
  92. GenericName[no]=%VMNAME%: Nettleser
  93. GenericName[pl]=%VMNAME%: Przeglądarka WWW
  94. GenericName[pt]=%VMNAME%: Navegador Web
  95. GenericName[pt_BR]=%VMNAME%: Navegador Web
  96. GenericName[sk]=%VMNAME%: Internetový prehliadač
  97. GenericName[sv]=%VMNAME%: Webbläsare
  98. Comment={comment}
  99. Comment[ca]=Navegueu per el web
  100. Comment[cs]=Prohlížení stránek World Wide Webu
  101. Comment[de]=Im Internet surfen
  102. Comment[es]=Navegue por la web
  103. Comment[fa]=صفحات شبه جهانی اینترنت را مرور نمایید
  104. Comment[fi]=Selaa Internetin WWW-sivuja
  105. Comment[fr]=Navigue sur Internet
  106. Comment[hu]=A világháló böngészése
  107. Comment[it]=Esplora il web
  108. Comment[ja]=ウェブを閲覧します
  109. Comment[ko]=웹을 돌아 다닙니다
  110. Comment[nb]=Surf på nettet
  111. Comment[nl]=Verken het internet
  112. Comment[nn]=Surf på nettet
  113. Comment[no]=Surf på nettet
  114. Comment[pl]=Przeglądanie stron WWW
  115. Comment[pt]=Navegue na Internet
  116. Comment[pt_BR]=Navegue na Internet
  117. Comment[sk]=Prehliadanie internetu
  118. Comment[sv]=Surfa på webben
  119. Exec=qvm-run -q --tray -a %VMNAME% '{command} %u'
  120. Categories=Network;WebBrowser;
  121. X-Qubes-VmName=%VMNAME%
  122. Icon=%VMDIR%/icon.png
  123. '''
  124. QUBESXML_R1 = '''<?xml version='1.0' encoding='UTF-8'?>
  125. <QubesVmCollection clockvm="2" default_fw_netvm="2" default_kernel="3.2.7-10" default_netvm="3" default_template="1" updatevm="3"><QubesTemplateVm conf_file="fedora-17-x64.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/vm-templates/fedora-17-x64" include_in_backups="True" installed_by_rpm="True" internal="False" kernel="3.2.7-10" kernelopts="" label="gray" maxmem="4063" memory="400" name="fedora-17-x64" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="1" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="none" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesNetVm conf_file="netvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/servicevms/netvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="iommu=soft swiotlb=2048" label="red" maxmem="4063" memory="200" name="netvm" netid="1" pcidevs="[&apos;00:19.0&apos;, &apos;03:00.0&apos;]" private_img="private.img" qid="2" root_img="root.img" services="{&apos;ntpd&apos;: False, &apos;meminfo-writer&apos;: False}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" vcpus="2" volatile_img="volatile.img" /><QubesProxyVm conf_file="firewallvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/servicevms/firewallvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="green" maxmem="4063" memory="200" name="firewallvm" netid="2" netvm_qid="2" pcidevs="[]" private_img="private.img" qid="3" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="fedora-17-x64-dvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/fedora-17-x64-dvm" include_in_backups="True" installed_by_rpm="False" internal="True" kernel="3.2.7-10" kernelopts="" label="gray" maxmem="4063" memory="400" name="fedora-17-x64-dvm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="4" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="1" volatile_img="volatile.img" /><QubesAppVm conf_file="test-work.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-work" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="green" maxmem="4063" memory="400" name="test-work" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="5" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="personal.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/personal" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="yellow" maxmem="4063" memory="400" name="personal" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="6" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="banking.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/banking" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="green" maxmem="4063" memory="400" name="banking" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="7" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="untrusted.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/untrusted" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="red" maxmem="4063" memory="400" name="untrusted" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="8" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="test-standalonevm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-standalonevm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="None" kernelopts="" label="red" maxmem="4063" memory="400" name="test-standalonevm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="9" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="none" uses_default_kernel="False" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="test-testvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-testvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="red" mac="00:16:3E:5E:6C:55" maxmem="4063" memory="400" name="test-testvm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="10" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesTemplateVm conf_file="test-template-clone.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/vm-templates/test-template-clone" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="gray" maxmem="4063" memory="400" name="test-template-clone" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="11" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="none" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="test-custom-template-appvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-custom-template-appvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="yellow" maxmem="4063" memory="400" name="test-custom-template-appvm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="12" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="11" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesProxyVm conf_file="test-testproxy.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/servicevms/test-testproxy" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="yellow" maxmem="4063" memory="200" name="test-testproxy" netid="3" netvm_qid="2" pcidevs="[]" private_img="private.img" qid="13" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" vcpus="2" volatile_img="volatile.img" /></QubesVmCollection>
  126. '''
  127. BACKUP_HEADER_R2 = '''version=3
  128. hmac-algorithm=SHA512
  129. crypto-algorithm=aes-256-cbc
  130. encrypted={encrypted}
  131. compressed={compressed}
  132. compression-filter=gzip
  133. '''
  134. class TC_00_BackupCompatibility(
  135. qubes.tests.integ.backup.BackupTestsMixin, qubes.tests.QubesTestCase):
  136. def tearDown(self):
  137. self.remove_test_vms(prefix="test-")
  138. super(TC_00_BackupCompatibility, self).tearDown()
  139. def create_whitelisted_appmenus(self, filename):
  140. f = open(filename, "w")
  141. f.write("gnome-terminal.desktop\n")
  142. f.write("nautilus.desktop\n")
  143. f.write("firefox.desktop\n")
  144. f.write("mozilla-thunderbird.desktop\n")
  145. f.write("libreoffice-startcenter.desktop\n")
  146. f.close()
  147. def create_appmenus(self, dir, template, list):
  148. for name in list:
  149. f = open(os.path.join(dir, name + ".desktop"), "w")
  150. f.write(template.format(name=name, comment=name, command=name))
  151. f.close()
  152. def create_private_img(self, filename):
  153. self.create_sparse(filename, 2*2**30)
  154. subprocess.check_call(["/usr/sbin/mkfs.ext4", "-q", "-F", filename])
  155. def create_volatile_img(self, filename):
  156. self.create_sparse(filename, 11.5*2**30)
  157. # here used to be sfdisk call with "0,1024,S\n,10240,L\n" input,
  158. # but since sfdisk folks like to change command arguments in
  159. # incompatible way, have an partition table verbatim here
  160. ptable = (
  161. '\x00\x00\x00\x00\x00\x00\x00\x00\xab\x39\xd5\xd4\x00\x00\x20\x00'
  162. '\x00\x21\xaa\x82\x82\x28\x08\x00\x00\x00\x00\x00\x00\x20\xaa\x00'
  163. '\x82\x29\x15\x83\x9c\x79\x08\x00\x00\x20\x00\x00\x01\x40\x00\x00'
  164. '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
  165. '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa\x55'
  166. )
  167. with open(filename, 'r+') as f:
  168. f.seek(0x1b0)
  169. f.write(ptable)
  170. # TODO: mkswap
  171. def fullpath(self, name):
  172. return os.path.join(self.backupdir, name)
  173. def create_v1_files(self, r2b2=False):
  174. appmenus_list = [
  175. "firefox", "gnome-terminal", "evince", "evolution",
  176. "mozilla-thunderbird", "libreoffice-startcenter", "nautilus",
  177. "gedit", "gpk-update-viewer", "gpk-application"
  178. ]
  179. os.mkdir(self.fullpath("appvms"))
  180. os.mkdir(self.fullpath("servicevms"))
  181. os.mkdir(self.fullpath("vm-templates"))
  182. # normal AppVM
  183. os.mkdir(self.fullpath("appvms/test-work"))
  184. self.create_whitelisted_appmenus(self.fullpath(
  185. "appvms/test-work/whitelisted-appmenus.list"))
  186. os.symlink("/usr/share/qubes/icons/green.png",
  187. self.fullpath("appvms/test-work/icon.png"))
  188. self.create_private_img(self.fullpath("appvms/test-work/private.img"))
  189. # StandaloneVM
  190. os.mkdir(self.fullpath("appvms/test-standalonevm"))
  191. self.create_whitelisted_appmenus(self.fullpath(
  192. "appvms/test-standalonevm/whitelisted-appmenus.list"))
  193. os.symlink("/usr/share/qubes/icons/blue.png",
  194. self.fullpath("appvms/test-standalonevm/icon.png"))
  195. self.create_private_img(self.fullpath(
  196. "appvms/test-standalonevm/private.img"))
  197. self.create_sparse(
  198. self.fullpath("appvms/test-standalonevm/root.img"), 10*2**30)
  199. self.fill_image(self.fullpath("appvms/test-standalonevm/root.img"),
  200. 100*1024*1024, True)
  201. os.mkdir(self.fullpath("appvms/test-standalonevm/apps.templates"))
  202. self.create_appmenus(self.fullpath("appvms/test-standalonevm/apps"
  203. ".templates"),
  204. APPTEMPLATE_R2B2,
  205. appmenus_list)
  206. os.mkdir(self.fullpath("appvms/test-standalonevm/kernels"))
  207. for k_file in ["initramfs", "vmlinuz", "modules.img"]:
  208. self.fill_image(self.fullpath("appvms/test-standalonevm/kernels/"
  209. + k_file), 10*1024*1024)
  210. # VM based on custom template
  211. subprocess.check_call(
  212. ["/bin/cp", "-a", self.fullpath("appvms/test-work"),
  213. self.fullpath("appvms/test-custom-template-appvm")])
  214. # HVM
  215. if r2b2:
  216. subprocess.check_call(
  217. ["/bin/cp", "-a", self.fullpath("appvms/test-standalonevm"),
  218. self.fullpath("appvms/test-testhvm")])
  219. # ProxyVM
  220. os.mkdir(self.fullpath("servicevms/test-testproxy"))
  221. self.create_whitelisted_appmenus(self.fullpath(
  222. "servicevms/test-testproxy/whitelisted-appmenus.list"))
  223. self.create_private_img(
  224. self.fullpath("servicevms/test-testproxy/private.img"))
  225. # Custom template
  226. os.mkdir(self.fullpath("vm-templates/test-template-clone"))
  227. self.create_private_img(
  228. self.fullpath("vm-templates/test-template-clone/private.img"))
  229. self.create_sparse(self.fullpath(
  230. "vm-templates/test-template-clone/root-cow.img"), 10*2**30)
  231. self.create_sparse(self.fullpath(
  232. "vm-templates/test-template-clone/root.img"), 10*2**30)
  233. self.fill_image(self.fullpath(
  234. "vm-templates/test-template-clone/root.img"), 1*2**30, True)
  235. self.create_volatile_img(self.fullpath(
  236. "vm-templates/test-template-clone/volatile.img"))
  237. subprocess.check_call([
  238. "/bin/tar", "cS",
  239. "-f", self.fullpath(
  240. "vm-templates/test-template-clone/clean-volatile.img.tar"),
  241. "-C", self.fullpath("vm-templates/test-template-clone"),
  242. "volatile.img"])
  243. self.create_whitelisted_appmenus(self.fullpath(
  244. "vm-templates/test-template-clone/whitelisted-appmenus.list"))
  245. self.create_whitelisted_appmenus(self.fullpath(
  246. "vm-templates/test-template-clone/vm-whitelisted-appmenus.list"))
  247. if r2b2:
  248. self.create_whitelisted_appmenus(self.fullpath(
  249. "vm-templates/test-template-clone/netvm-whitelisted-appmenus"
  250. ".list"))
  251. os.symlink("/usr/share/qubes/icons/green.png",
  252. self.fullpath("vm-templates/test-template-clone/icon.png"))
  253. os.mkdir(
  254. self.fullpath("vm-templates/test-template-clone/apps.templates"))
  255. self.create_appmenus(
  256. self.fullpath("vm-templates/test-template-clone/apps.templates"),
  257. APPTEMPLATE_R2B2,
  258. appmenus_list)
  259. os.mkdir(self.fullpath("vm-templates/test-template-clone/apps"))
  260. self.create_appmenus(
  261. self.fullpath("vm-templates/test-template-clone/apps"),
  262. APPTEMPLATE_R2B2.replace("%VMNAME%", "test-template-clone")
  263. .replace("%VMDIR%", self.fullpath(
  264. "vm-templates/test-template-clone")),
  265. appmenus_list)
  266. def calculate_hmac(self, f_name, algorithm="sha512", password="qubes"):
  267. subprocess.check_call(["openssl", "dgst", "-"+algorithm, "-hmac",
  268. password],
  269. stdin=open(self.fullpath(f_name), "r"),
  270. stdout=open(self.fullpath(f_name+".hmac"), "w"))
  271. def append_backup_stream(self, f_name, stream, basedir=None):
  272. if not basedir:
  273. basedir = self.backupdir
  274. subprocess.check_call(["tar", "-cO", "--posix", "-C", basedir,
  275. f_name],
  276. stdout=stream)
  277. def handle_v3_file(self, f_name, subdir, stream, compressed=True,
  278. encrypted=True):
  279. # create inner archive
  280. tar_cmdline = ["tar", "-Pc", '--sparse',
  281. '-C', self.fullpath(os.path.dirname(f_name)),
  282. '--xform', 's:^%s:%s\\0:' % (
  283. os.path.basename(f_name),
  284. subdir),
  285. os.path.basename(f_name)
  286. ]
  287. if compressed:
  288. tar_cmdline.insert(-1, "--use-compress-program=%s" % "gzip")
  289. tar = subprocess.Popen(tar_cmdline, stdout=subprocess.PIPE)
  290. if encrypted:
  291. encryptor = subprocess.Popen(
  292. ["openssl", "enc", "-e", "-aes-256-cbc", "-pass", "pass:qubes"],
  293. stdin=tar.stdout,
  294. stdout=subprocess.PIPE)
  295. data = encryptor.stdout
  296. else:
  297. data = tar.stdout
  298. stage1_dir = self.fullpath(os.path.join("stage1", subdir))
  299. if not os.path.exists(stage1_dir):
  300. os.makedirs(stage1_dir)
  301. subprocess.check_call(["split", "--numeric-suffixes",
  302. "--suffix-length=3",
  303. "--bytes="+str(100*1024*1024), "-",
  304. os.path.join(stage1_dir,
  305. os.path.basename(f_name+"."))],
  306. stdin=data)
  307. for part in sorted(os.listdir(stage1_dir)):
  308. if not re.match(
  309. r"^{}.[0-9][0-9][0-9]$".format(os.path.basename(f_name)),
  310. part):
  311. continue
  312. part_with_dir = os.path.join(subdir, part)
  313. self.calculate_hmac(os.path.join("stage1", part_with_dir))
  314. self.append_backup_stream(part_with_dir, stream,
  315. basedir=self.fullpath("stage1"))
  316. self.append_backup_stream(part_with_dir+".hmac", stream,
  317. basedir=self.fullpath("stage1"))
  318. def create_v3_backup(self, encrypted=True, compressed=True):
  319. """
  320. Create "backup format 3" backup - used in R2 and R3.0
  321. :param encrypt: Should the backup be encrypted
  322. :return:
  323. """
  324. output = open(self.fullpath("backup.bin"), "w")
  325. f = open(self.fullpath("backup-header"), "w")
  326. f.write(BACKUP_HEADER_R2.format(
  327. encrypted=str(encrypted),
  328. compressed=str(compressed)
  329. ))
  330. f.close()
  331. self.calculate_hmac("backup-header")
  332. self.append_backup_stream("backup-header", output)
  333. self.append_backup_stream("backup-header.hmac", output)
  334. f = open(self.fullpath("qubes.xml"), "w")
  335. if encrypted:
  336. qubesxml = QUBESXML_R2
  337. for vmname, subdir in MANGLED_SUBDIRS_R2.items():
  338. qubesxml = re.sub(r"[a-z-]*/{}".format(vmname),
  339. subdir, qubesxml)
  340. f.write(qubesxml)
  341. else:
  342. f.write(QUBESXML_R2)
  343. f.close()
  344. self.handle_v3_file("qubes.xml", "", output, encrypted=encrypted,
  345. compressed=compressed)
  346. self.create_v1_files(r2b2=True)
  347. for vm_type in ["appvms", "servicevms"]:
  348. for vm_name in os.listdir(self.fullpath(vm_type)):
  349. vm_dir = os.path.join(vm_type, vm_name)
  350. for f_name in os.listdir(self.fullpath(vm_dir)):
  351. if encrypted:
  352. subdir = MANGLED_SUBDIRS_R2[vm_name]
  353. else:
  354. subdir = vm_dir
  355. self.handle_v3_file(
  356. os.path.join(vm_dir, f_name),
  357. subdir+'/', output, encrypted=encrypted)
  358. for vm_name in os.listdir(self.fullpath("vm-templates")):
  359. vm_dir = os.path.join("vm-templates", vm_name)
  360. if encrypted:
  361. subdir = MANGLED_SUBDIRS_R2[vm_name]
  362. else:
  363. subdir = vm_dir
  364. self.handle_v3_file(
  365. os.path.join(vm_dir, "."),
  366. subdir+'/', output, encrypted=encrypted)
  367. output.close()
  368. def assertRestored(self, name, **kwargs):
  369. with self.assertNotRaises((KeyError, qubes.exc.QubesException)):
  370. vm = self.app.domains[name]
  371. vm.storage.verify()
  372. for prop, value in kwargs.items():
  373. if prop == 'klass':
  374. self.assertIsInstance(vm, value)
  375. elif value is qubes.property.DEFAULT:
  376. self.assertTrue(vm.property_is_default(prop),
  377. 'VM {} - property {} not default'.format(vm.name, prop))
  378. else:
  379. actual_value = getattr(vm, prop)
  380. if isinstance(actual_value, qubes.vm.BaseVM):
  381. self.assertEqual(value, actual_value.name,
  382. 'VM {} - property {}'.format(vm.name, prop))
  383. elif isinstance(actual_value, qubes.Label):
  384. self.assertEqual(value, actual_value.name,
  385. 'VM {} - property {}'.format(vm.name, prop))
  386. else:
  387. self.assertEqual(value, actual_value,
  388. 'VM {} - property {}'.format(vm.name, prop))
  389. def test_100_r1(self):
  390. self.create_v1_files(r2b2=False)
  391. f = open(self.fullpath("qubes.xml"), "w")
  392. f.write(QUBESXML_R1)
  393. f.close()
  394. self.restore_backup(self.backupdir,
  395. options={
  396. 'use-default-template': True,
  397. 'use-default-netvm': True,
  398. },
  399. )
  400. common_props = {
  401. 'installed_by_rpm': False,
  402. 'kernel': qubes.property.DEFAULT,
  403. 'kernelopts': qubes.property.DEFAULT,
  404. 'qrexec_timeout': qubes.property.DEFAULT,
  405. 'netvm': qubes.property.DEFAULT,
  406. 'default_user': qubes.property.DEFAULT,
  407. 'internal': qubes.property.DEFAULT,
  408. 'include_in_backups': True,
  409. 'debug': False,
  410. 'maxmem': 4000, # 4063 caped by 10*400
  411. 'memory': 400,
  412. }
  413. self.assertRestored("test-template-clone",
  414. klass=qubes.vm.templatevm.TemplateVM,
  415. label='gray',
  416. provides_network=False,
  417. **common_props)
  418. testproxy_props = common_props.copy()
  419. testproxy_props.update(
  420. label='yellow',
  421. provides_network=True,
  422. memory=200,
  423. maxmem=2000,
  424. template=self.app.default_template.name,
  425. )
  426. self.assertRestored("test-testproxy",
  427. klass=qubes.vm.appvm.AppVM,
  428. **testproxy_props)
  429. self.assertRestored("test-work",
  430. klass=qubes.vm.appvm.AppVM,
  431. template=self.app.default_template.name,
  432. label='green',
  433. **common_props)
  434. self.assertRestored("test-standalonevm",
  435. klass=qubes.vm.standalonevm.StandaloneVM,
  436. label='red',
  437. **common_props)
  438. self.assertRestored("test-custom-template-appvm",
  439. klass=qubes.vm.appvm.AppVM,
  440. template='test-template-clone',
  441. label='yellow',
  442. **common_props)
  443. def test_200_r2b2(self):
  444. self.create_v1_files(r2b2=True)
  445. f = open(self.fullpath("qubes.xml"), "w")
  446. f.write(QUBESXML_R2B2)
  447. f.close()
  448. self.restore_backup(self.backupdir, options={
  449. 'use-default-template': True,
  450. 'use-default-netvm': True,
  451. })
  452. common_props = {
  453. 'installed_by_rpm': False,
  454. 'kernel': qubes.property.DEFAULT,
  455. 'kernelopts': qubes.property.DEFAULT,
  456. 'qrexec_timeout': qubes.property.DEFAULT,
  457. 'netvm': qubes.property.DEFAULT,
  458. 'default_user': qubes.property.DEFAULT,
  459. 'internal': qubes.property.DEFAULT,
  460. 'include_in_backups': True,
  461. 'debug': False,
  462. 'maxmem': 1535,
  463. 'memory': 400,
  464. }
  465. template_clone_props = common_props.copy()
  466. template_clone_props.update(
  467. label='green',
  468. provides_network=False,
  469. )
  470. self.assertRestored("test-template-clone",
  471. klass=qubes.vm.templatevm.TemplateVM,
  472. **template_clone_props)
  473. testproxy_props = common_props.copy()
  474. testproxy_props.update(
  475. label='red',
  476. provides_network=True,
  477. memory=200,
  478. template=self.app.default_template.name,
  479. )
  480. self.assertRestored("test-testproxy",
  481. klass=qubes.vm.appvm.AppVM,
  482. **testproxy_props)
  483. self.assertRestored("test-work",
  484. klass=qubes.vm.appvm.AppVM,
  485. template=self.app.default_template.name,
  486. label='green',
  487. **common_props)
  488. self.assertRestored("test-standalonevm",
  489. klass=qubes.vm.standalonevm.StandaloneVM,
  490. label='blue',
  491. **common_props)
  492. self.assertRestored("test-custom-template-appvm",
  493. klass=qubes.vm.appvm.AppVM,
  494. template='test-template-clone',
  495. label='yellow',
  496. **common_props)
  497. def test_210_r2(self):
  498. self.create_v3_backup(False)
  499. self.restore_backup(self.fullpath("backup.bin"), options={
  500. 'use-default-template': True,
  501. 'use-default-netvm': True,
  502. })
  503. common_props = {
  504. 'installed_by_rpm': False,
  505. 'kernel': qubes.property.DEFAULT,
  506. 'kernelopts': qubes.property.DEFAULT,
  507. 'qrexec_timeout': qubes.property.DEFAULT,
  508. 'netvm': qubes.property.DEFAULT,
  509. 'default_user': qubes.property.DEFAULT,
  510. 'internal': qubes.property.DEFAULT,
  511. 'include_in_backups': True,
  512. 'debug': False,
  513. 'maxmem': 1535,
  514. 'memory': 400,
  515. }
  516. self.assertRestored("test-template-clone",
  517. klass=qubes.vm.templatevm.TemplateVM,
  518. label='green',
  519. provides_network=False,
  520. **common_props)
  521. testproxy_props = common_props.copy()
  522. testproxy_props.update(
  523. label='red',
  524. provides_network=True,
  525. memory=200,
  526. template=self.app.default_template.name,
  527. )
  528. self.assertRestored("test-testproxy",
  529. klass=qubes.vm.appvm.AppVM,
  530. **testproxy_props)
  531. self.assertRestored("test-work",
  532. klass=qubes.vm.appvm.AppVM,
  533. template=self.app.default_template.name,
  534. label='green',
  535. **common_props)
  536. self.assertRestored("test-standalonevm",
  537. klass=qubes.vm.standalonevm.StandaloneVM,
  538. label='blue',
  539. **common_props)
  540. self.assertRestored("test-custom-template-appvm",
  541. klass=qubes.vm.appvm.AppVM,
  542. template='test-template-clone',
  543. label='yellow',
  544. **common_props)
  545. def test_220_r2_encrypted(self):
  546. self.create_v3_backup(True)
  547. self.restore_backup(self.fullpath("backup.bin"), options={
  548. 'use-default-template': True,
  549. 'use-default-netvm': True,
  550. })
  551. common_props = {
  552. 'installed_by_rpm': False,
  553. 'kernel': qubes.property.DEFAULT,
  554. 'kernelopts': qubes.property.DEFAULT,
  555. 'qrexec_timeout': qubes.property.DEFAULT,
  556. 'netvm': qubes.property.DEFAULT,
  557. 'default_user': qubes.property.DEFAULT,
  558. 'internal': qubes.property.DEFAULT,
  559. 'include_in_backups': True,
  560. 'debug': False,
  561. 'maxmem': 1535, # 4063 caped by 10*400
  562. 'memory': 400,
  563. }
  564. self.assertRestored("test-template-clone",
  565. klass=qubes.vm.templatevm.TemplateVM,
  566. label='green',
  567. provides_network=False,
  568. **common_props)
  569. testproxy_props = common_props.copy()
  570. testproxy_props.update(
  571. label='red',
  572. provides_network=True,
  573. memory=200,
  574. template=self.app.default_template.name,
  575. )
  576. self.assertRestored("test-testproxy",
  577. klass=qubes.vm.appvm.AppVM,
  578. **testproxy_props)
  579. self.assertRestored("test-work",
  580. klass=qubes.vm.appvm.AppVM,
  581. template=self.app.default_template.name,
  582. label='green',
  583. **common_props)
  584. self.assertRestored("test-standalonevm",
  585. klass=qubes.vm.standalonevm.StandaloneVM,
  586. label='blue',
  587. **common_props)
  588. self.assertRestored("test-custom-template-appvm",
  589. klass=qubes.vm.appvm.AppVM,
  590. template='test-template-clone',
  591. label='yellow',
  592. **common_props)
  593. class TC_01_BackupCompatibilityIntoLVM(TC_00_BackupCompatibility):
  594. def setUp(self):
  595. super(TC_01_BackupCompatibilityIntoLVM, self).setUp()
  596. self.init_lvm_pool()
  597. def restore_backup(self, source=None, appvm=None, options=None,
  598. expect_errors=None, manipulate_restore_info=None):
  599. if options is None:
  600. options = {}
  601. options['override_pool'] = self.pool.name
  602. super(TC_01_BackupCompatibilityIntoLVM, self).restore_backup(source,
  603. appvm, options, expect_errors, manipulate_restore_info)