__init__.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # pylint: disable=protected-access,pointless-statement
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  6. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  7. #
  8. # This library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Lesser General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2.1 of the License, or (at your option) any later version.
  12. #
  13. # This library 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 GNU
  16. # Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public
  19. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  20. #
  21. import jinja2
  22. import qubes.tests
  23. class TestVMM(object):
  24. # pylint: disable=too-few-public-methods
  25. def __init__(self, offline_mode=False):
  26. self.offline_mode = offline_mode
  27. @property
  28. def libvirt_conn(self):
  29. import libvirt
  30. raise libvirt.libvirtError('phony error')
  31. class TestHost(object):
  32. # pylint: disable=too-few-public-methods
  33. def __init__(self):
  34. self.memory_total = 1000 * 1024
  35. self.no_cpus = 4
  36. class TestVMsCollection(dict):
  37. def get_vms_connected_to(self, vm):
  38. return set()
  39. def close(self):
  40. self.clear()
  41. class TestVolume(object):
  42. def __init__(self, pool):
  43. self.pool = pool
  44. self.size = 0
  45. self.source = None
  46. class TestPool(object):
  47. def init_volume(self, *args, **kwargs):
  48. return TestVolume(self)
  49. class TestApp(qubes.tests.TestEmitter):
  50. labels = {1: qubes.Label(1, '0xcc0000', 'red')}
  51. check_updates_vm = False
  52. def get_label(self, label):
  53. # pylint: disable=unused-argument
  54. if label in self.labels:
  55. return self.labels[label]
  56. for l in self.labels.values():
  57. if l.name == label:
  58. return l
  59. raise KeyError(label)
  60. def get_pool(self, pool):
  61. return self.pools[pool]
  62. def __init__(self):
  63. super(TestApp, self).__init__()
  64. self.vmm = TestVMM()
  65. self.host = TestHost()
  66. default_pool = TestPool()
  67. self.pools = {
  68. 'default': default_pool,
  69. default_pool: default_pool,
  70. 'linux-kernel': TestPool(),
  71. }
  72. self.default_pool_volatile = 'default'
  73. self.default_pool_root = 'default'
  74. self.default_pool_private = 'default'
  75. self.default_pool_kernel = 'linux-kernel'
  76. self.default_netvm = None
  77. self.domains = TestVMsCollection()
  78. #: jinja2 environment for libvirt XML templates
  79. self.env = jinja2.Environment(
  80. loader=jinja2.FileSystemLoader([
  81. 'templates',
  82. '/etc/qubes/templates',
  83. '/usr/share/qubes/templates',
  84. ]),
  85. undefined=jinja2.StrictUndefined)