vm.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/python2 -O
  2. import sys
  3. import unittest
  4. import lxml.etree
  5. sys.path.insert(0, '../')
  6. import qubes.vm
  7. class TestVM(qubes.vm.BaseVM):
  8. testprop = qubes.vm.property('testprop')
  9. testlabel = qubes.vm.property('testlabel')
  10. defaultprop = qubes.vm.property('defaultprop', default='defaultvalue')
  11. class TC_BaseVM(unittest.TestCase):
  12. def setUp(self):
  13. self.xml = lxml.etree.XML('''
  14. <qubes version="3"> <!-- xmlns="https://qubes-os.org/QubesXML/1" -->
  15. <labels>
  16. <label id="label-1" color="#cc0000">red</label>
  17. </labels>
  18. <domains>
  19. <domain id="domain-1" class="TestVM">
  20. <properties>
  21. <property name="testprop">testvalue</property>
  22. <property name="testlabel" ref="label-1" />
  23. </properties>
  24. <tags>
  25. <tag name="testtag">tagvalue</tag>
  26. </tags>
  27. <services>
  28. <service>testservice</service>
  29. <service enabled="True">enabledservice</service>
  30. <service enabled="False">disabledservice</service>
  31. </services>
  32. <devices class="pci">
  33. <device>00:11.22</device>
  34. </devices>
  35. <devices class="usb" />
  36. <devices class="audio-in" />
  37. <devices class="firewire" />
  38. <devices class="i2c" />
  39. <devices class="isa" />
  40. </domain>
  41. </domains>
  42. </qubes>
  43. ''')
  44. def test_000_BaseVM_load(self):
  45. node = self.xml.xpath('//domain')[0]
  46. vm = TestVM(node)
  47. self.assertEqual(vm.testprop, 'testvalue')
  48. self.assertEqual(vm.testlabel, 'label-1')
  49. self.assertEqual(vm.defaultprop, 'defaultvalue')
  50. self.assertEqual(vm.tags, {'testtag': 'tagvalue'})
  51. self.assertEqual(vm.devices, {'pci': ['00:11.22']})
  52. self.assertEqual(vm.services, {
  53. 'testservice': True,
  54. 'enabledservice': True,
  55. 'disabledservice': False,
  56. })
  57. def test_001_BaseVM_nxproperty(self):
  58. xml = lxml.etree.XML('''
  59. <qubes version="3">
  60. <domains>
  61. <domain id="domain-1" class="TestVM">
  62. <properties>
  63. <property name="nxproperty">nxvalue</property>
  64. </properties>
  65. </domain>
  66. </domains>
  67. </qubes>
  68. ''')
  69. node = xml.xpath('//domain')[0]
  70. def f():
  71. vm = TestVM(node)
  72. self.assertRaises(AttributeError, f)