init.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. # pylint: disable=protected-access
  4. #
  5. # The Qubes OS Project, https://www.qubes-os.org/
  6. #
  7. # Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  8. # Copyright (C) 2014-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 lxml.etree
  25. import qubes
  26. import qubes.events
  27. import qubes.vm
  28. import qubes.tests
  29. class TestVM(qubes.vm.BaseVM):
  30. qid = qubes.property('qid', type=int)
  31. name = qubes.property('name')
  32. testprop = qubes.property('testprop')
  33. testlabel = qubes.property('testlabel')
  34. defaultprop = qubes.property('defaultprop', default='defaultvalue')
  35. class TC_10_BaseVM(qubes.tests.QubesTestCase):
  36. def setUp(self):
  37. self.xml = lxml.etree.XML('''
  38. <qubes version="3"> <!-- xmlns="https://qubes-os.org/QubesXML/1" -->
  39. <labels>
  40. <label id="label-1" color="#cc0000">red</label>
  41. </labels>
  42. <domains>
  43. <domain id="domain-1" class="TestVM">
  44. <properties>
  45. <property name="qid">1</property>
  46. <property name="name">domain1</property>
  47. <property name="testprop">testvalue</property>
  48. <property name="testlabel" ref="label-1" />
  49. </properties>
  50. <tags>
  51. <tag name="testtag">tagvalue</tag>
  52. </tags>
  53. <features>
  54. <feature name="testfeature_none"/>
  55. <feature name="testfeature_empty"></feature>
  56. <feature name="testfeature_aqq">aqq</feature>
  57. </features>
  58. <devices class="pci">
  59. <device>00:11.22</device>
  60. </devices>
  61. <devices class="usb" />
  62. <devices class="audio-in" />
  63. <devices class="firewire" />
  64. <devices class="i2c" />
  65. <devices class="isa" />
  66. </domain>
  67. </domains>
  68. </qubes>
  69. ''')
  70. def test_000_load(self):
  71. node = self.xml.xpath('//domain')[0]
  72. vm = TestVM(None, node)
  73. vm.load_properties(load_stage=None)
  74. self.assertEqual(vm.qid, 1)
  75. self.assertEqual(vm.testprop, 'testvalue')
  76. self.assertEqual(vm.testprop, 'testvalue')
  77. self.assertEqual(vm.testlabel, 'label-1')
  78. self.assertEqual(vm.defaultprop, 'defaultvalue')
  79. self.assertEqual(vm.tags, {'testtag': 'tagvalue'})
  80. self.assertEqual(vm.features, {
  81. 'testfeature_none': None,
  82. 'testfeature_empty': '',
  83. 'testfeature_aqq': 'aqq',
  84. })
  85. self.assertItemsEqual(vm.devices.keys(), ('pci',))
  86. self.assertItemsEqual(vm.devices['pci'], ('00:11.22',))
  87. self.assertXMLIsValid(vm.__xml__(), 'domain.rng')
  88. def test_001_nxproperty(self):
  89. xml = lxml.etree.XML('''
  90. <qubes version="3">
  91. <domains>
  92. <domain id="domain-1" class="TestVM">
  93. <properties>
  94. <property name="qid">1</property>
  95. <property name="name">domain1</property>
  96. <property name="nxproperty">nxvalue</property>
  97. </properties>
  98. </domain>
  99. </domains>
  100. </qubes>
  101. ''')
  102. node = xml.xpath('//domain')[0]
  103. with self.assertRaises(TypeError):
  104. TestVM(None, node)