net.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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-2016 Joanna Rutkowska <joanna@invisiblethingslab.com>
  8. # Copyright (C) 2014-2016 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 unittest
  25. import qubes
  26. import qubes.vm.qubesvm
  27. import qubes.tests
  28. import qubes.tests.vm.qubesvm
  29. class TC_00_NetVMMixin(
  30. qubes.tests.vm.qubesvm.QubesVMTestsMixin, qubes.tests.QubesTestCase):
  31. def setUp(self):
  32. super(TC_00_NetVMMixin, self).setUp()
  33. self.app = qubes.tests.vm.TestApp()
  34. self.app.vmm.offline_mode = True
  35. def setup_netvms(self, vm):
  36. # usage of QubesVM here means that those tests should be after
  37. # testing properties used here
  38. self.netvm1 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=2,
  39. name=qubes.tests.VMPREFIX + 'netvm1',
  40. provides_network=True)
  41. self.netvm2 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=3,
  42. name=qubes.tests.VMPREFIX + 'netvm2',
  43. provides_network=True)
  44. self.nonetvm = qubes.vm.qubesvm.QubesVM(self.app, None, qid=4,
  45. name=qubes.tests.VMPREFIX + 'nonet')
  46. self.app.domains = qubes.app.VMCollection(self.app)
  47. for domain in (vm, self.netvm1, self.netvm2, self.nonetvm):
  48. self.app.domains._dict[domain.qid] = domain
  49. self.app.default_netvm = self.netvm1
  50. self.app.default_fw_netvm = self.netvm1
  51. @qubes.tests.skipUnlessDom0
  52. def test_140_netvm(self):
  53. vm = self.get_vm()
  54. self.setup_netvms(vm)
  55. self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
  56. self.assertPropertyValue(vm, 'netvm', self.netvm2, self.netvm2,
  57. self.netvm2.name)
  58. del vm.netvm
  59. self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
  60. self.assertPropertyValue(vm, 'netvm', self.netvm2.name, self.netvm2,
  61. self.netvm2.name)
  62. self.assertPropertyValue(vm, 'netvm', None, None, '')
  63. def test_141_netvm_invalid(self):
  64. vm = self.get_vm()
  65. self.setup_netvms(vm)
  66. self.assertPropertyInvalidValue(vm, 'netvm', 'invalid')
  67. self.assertPropertyInvalidValue(vm, 'netvm', 123)
  68. def test_142_netvm_netvm(self):
  69. vm = self.get_vm()
  70. self.setup_netvms(vm)
  71. self.assertPropertyInvalidValue(vm, 'netvm', self.nonetvm)
  72. def test_143_netvm_loopback(self):
  73. vm = self.get_vm()
  74. self.app.domains = {1: vm, vm: vm}
  75. self.assertPropertyInvalidValue(vm, 'netvm', vm)
  76. @unittest.skip('TODO: probably remove')
  77. def test_290_dispvm_netvm(self):
  78. vm = self.get_vm()
  79. self.setup_netvms(vm)
  80. self.assertPropertyDefaultValue(vm, 'dispvm_netvm',
  81. self.app.default_netvm)
  82. self.assertPropertyValue(vm, 'dispvm_netvm', self.netvm2, self.netvm2,
  83. self.netvm2.name)
  84. del vm.dispvm_netvm
  85. self.assertPropertyDefaultValue(vm, 'dispvm_netvm',
  86. self.app.default_netvm)
  87. self.assertPropertyValue(vm, 'dispvm_netvm', self.netvm2.name,
  88. self.netvm2, self.netvm2.name)
  89. # XXX FIXME xml value
  90. self.assertPropertyValue(vm, 'dispvm_netvm', None, None, 'None')
  91. @unittest.skip('TODO: probably remove')
  92. def test_291_dispvm_netvm_invalid(self):
  93. vm = self.get_vm()
  94. self.setup_netvms(vm)
  95. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', 'invalid')
  96. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', 123)
  97. @unittest.skip('TODO: probably remove')
  98. def test_291_dispvm_netvm_netvm(self):
  99. vm = self.get_vm()
  100. nonetvm = TestVM(qid=2, app=self.app, name='nonetvm')
  101. self.app.domains = {1: vm, 2: nonetvm}
  102. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', nonetvm)
  103. @unittest.skip('TODO: probably remove')
  104. def test_291_dispvm_netvm_default(self):
  105. """Check if vm.dispvm_netvm default is really vm.netvm"""
  106. vm = self.get_vm()
  107. self.setup_netvms(vm)
  108. vm.netvm = self.netvm2
  109. self.assertPropertyDefaultValue(vm, 'dispvm_netvm', self.netvm2)
  110. del vm.netvm
  111. self.assertPropertyDefaultValue(vm, 'dispvm_netvm', self.netvm1)
  112. @unittest.skip('TODO: probably remove')
  113. def test_292_dispvm_netvm_loopback(self):
  114. vm = self.get_vm()
  115. self.app.domains = {1: vm, vm: vm}
  116. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', vm)