__init__.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 TestApp(qubes.tests.TestEmitter):
  37. labels = {1: qubes.Label(1, '0xcc0000', 'red')}
  38. check_updates_vm = False
  39. def get_label(self, label):
  40. # pylint: disable=unused-argument
  41. if label in self.labels:
  42. return self.labels[label]
  43. for l in self.labels.values():
  44. if l.name == label:
  45. return l
  46. raise KeyError(label)
  47. def get_pool(self, pool):
  48. return self.pools[pool]
  49. def __init__(self):
  50. super(TestApp, self).__init__()
  51. self.vmm = TestVMM()
  52. self.host = TestHost()
  53. self.pools = {}
  54. self.default_pool_volatile = 'default'
  55. self.default_pool_root = 'default'
  56. self.default_pool_private = 'default'
  57. self.default_pool_kernel = 'linux-kernel'
  58. self.domains = {}
  59. #: jinja2 environment for libvirt XML templates
  60. self.env = jinja2.Environment(
  61. loader=jinja2.FileSystemLoader([
  62. 'templates',
  63. '/etc/qubes/templates',
  64. '/usr/share/qubes/templates',
  65. ]),
  66. undefined=jinja2.StrictUndefined)