__init__.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 unittest.mock
  23. import qubes.tests
  24. class TestVMM(object):
  25. # pylint: disable=too-few-public-methods
  26. def __init__(self, offline_mode=False):
  27. self.offline_mode = offline_mode
  28. self.xs = unittest.mock.Mock()
  29. @property
  30. def libvirt_conn(self):
  31. import libvirt
  32. raise libvirt.libvirtError('phony error')
  33. class TestHost(object):
  34. # pylint: disable=too-few-public-methods
  35. def __init__(self):
  36. self.memory_total = 1000 * 1024
  37. self.no_cpus = 4
  38. class TestVMsCollection(dict):
  39. def get_vms_connected_to(self, vm):
  40. return set()
  41. def close(self):
  42. self.clear()
  43. class TestVolume(object):
  44. def __init__(self, pool):
  45. self.pool = pool
  46. self.size = 0
  47. self.source = None
  48. class TestPool(object):
  49. def init_volume(self, *args, **kwargs):
  50. return TestVolume(self)
  51. class TestApp(qubes.tests.TestEmitter):
  52. labels = {1: qubes.Label(1, '0xcc0000', 'red')}
  53. check_updates_vm = False
  54. def get_label(self, label):
  55. # pylint: disable=unused-argument
  56. if label in self.labels:
  57. return self.labels[label]
  58. for l in self.labels.values():
  59. if l.name == label:
  60. return l
  61. raise KeyError(label)
  62. def get_pool(self, pool):
  63. return self.pools[pool]
  64. def __init__(self):
  65. super(TestApp, self).__init__()
  66. self.vmm = TestVMM()
  67. self.host = TestHost()
  68. default_pool = TestPool()
  69. self.pools = {
  70. 'default': default_pool,
  71. default_pool: default_pool,
  72. 'linux-kernel': TestPool(),
  73. }
  74. self.default_pool_volatile = 'default'
  75. self.default_pool_root = 'default'
  76. self.default_pool_private = 'default'
  77. self.default_pool_kernel = 'linux-kernel'
  78. self.default_netvm = None
  79. self.domains = TestVMsCollection()
  80. #: jinja2 environment for libvirt XML templates
  81. self.env = jinja2.Environment(
  82. loader=jinja2.FileSystemLoader([
  83. 'templates',
  84. '/etc/qubes/templates',
  85. '/usr/share/qubes/templates',
  86. ]),
  87. undefined=jinja2.StrictUndefined)