init.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_empty"></feature>
  55. <feature name="testfeature_aqq">aqq</feature>
  56. </features>
  57. <devices class="pci">
  58. <device>00:11.22</device>
  59. </devices>
  60. <devices class="usb" />
  61. <devices class="audio-in" />
  62. <devices class="firewire" />
  63. <devices class="i2c" />
  64. <devices class="isa" />
  65. </domain>
  66. </domains>
  67. </qubes>
  68. ''')
  69. def test_000_load(self):
  70. node = self.xml.xpath('//domain')[0]
  71. vm = TestVM(None, node)
  72. vm.load_properties(load_stage=None)
  73. self.assertEqual(vm.qid, 1)
  74. self.assertEqual(vm.testprop, 'testvalue')
  75. self.assertEqual(vm.testprop, 'testvalue')
  76. self.assertEqual(vm.testlabel, 'label-1')
  77. self.assertEqual(vm.defaultprop, 'defaultvalue')
  78. self.assertEqual(vm.tags, {'testtag': 'tagvalue'})
  79. self.assertEqual(vm.features, {
  80. 'testfeature_empty': '',
  81. 'testfeature_aqq': 'aqq',
  82. })
  83. self.assertItemsEqual(vm.devices.keys(), ('pci',))
  84. self.assertItemsEqual(vm.devices['pci'], ('00:11.22',))
  85. self.assertXMLIsValid(vm.__xml__(), 'domain.rng')
  86. def test_001_nxproperty(self):
  87. xml = lxml.etree.XML('''
  88. <qubes version="3">
  89. <domains>
  90. <domain id="domain-1" class="TestVM">
  91. <properties>
  92. <property name="qid">1</property>
  93. <property name="name">domain1</property>
  94. <property name="nxproperty">nxvalue</property>
  95. </properties>
  96. </domain>
  97. </domains>
  98. </qubes>
  99. ''')
  100. node = xml.xpath('//domain')[0]
  101. with self.assertRaises(TypeError):
  102. TestVM(None, node)
  103. def test_002_save_nxproperty(self):
  104. vm = TestVM(None, None, qid=1, name='testvm')
  105. vm.nxproperty = 'value'
  106. xml = vm.__xml__()
  107. self.assertNotIn('nxproperty', xml)