qubesvm.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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 os
  25. import unittest
  26. import uuid
  27. import datetime
  28. import qubes
  29. import qubes.exc
  30. import qubes.config
  31. import qubes.vm.qubesvm
  32. import qubes.tests
  33. class TestApp(object):
  34. labels = {1: qubes.Label(1, '0xcc0000', 'red')}
  35. def __init__(self):
  36. self.domains = {}
  37. class TestProp(object):
  38. # pylint: disable=too-few-public-methods
  39. __name__ = 'testprop'
  40. class TestVM(object):
  41. # pylint: disable=too-few-public-methods
  42. app = TestApp()
  43. def __init__(self, **kwargs):
  44. self.running = False
  45. self.installed_by_rpm = False
  46. for k, v in kwargs.items():
  47. setattr(self, k, v)
  48. def is_running(self):
  49. return self.running
  50. class TC_00_setters(qubes.tests.QubesTestCase):
  51. def setUp(self):
  52. self.vm = TestVM()
  53. self.prop = TestProp()
  54. def test_000_setter_qid(self):
  55. self.assertEqual(
  56. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, 5), 5)
  57. def test_001_setter_qid_lt_0(self):
  58. with self.assertRaises(ValueError):
  59. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, -1)
  60. def test_002_setter_qid_gt_max(self):
  61. with self.assertRaises(ValueError):
  62. qubes.vm.qubesvm._setter_qid(self.vm,
  63. self.prop, qubes.config.max_qid + 5)
  64. def test_010_setter_name(self):
  65. self.assertEqual(
  66. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'),
  67. 'test_name-1')
  68. def test_011_setter_name_not_a_string(self):
  69. # pylint: disable=invalid-name
  70. with self.assertRaises(TypeError):
  71. qubes.vm.qubesvm._setter_name(self.vm, self.prop, False)
  72. def test_012_setter_name_longer_than_31(self):
  73. # pylint: disable=invalid-name
  74. with self.assertRaises(ValueError):
  75. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32)
  76. def test_013_setter_name_illegal_character(self):
  77. # pylint: disable=invalid-name
  78. with self.assertRaises(ValueError):
  79. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#')
  80. def test_014_setter_name_first_not_letter(self):
  81. # pylint: disable=invalid-name
  82. with self.assertRaises(ValueError):
  83. qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test')
  84. def test_015_setter_name_running(self):
  85. self.vm.running = True
  86. with self.assertRaises(qubes.exc.QubesVMNotHaltedError):
  87. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  88. def test_016_setter_name_installed_by_rpm(self):
  89. # pylint: disable=invalid-name
  90. self.vm.installed_by_rpm = True
  91. with self.assertRaises(qubes.exc.QubesException):
  92. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  93. def test_017_setter_name_duplicate(self):
  94. # pylint: disable=invalid-name
  95. self.vm.app.domains['duplicate'] = TestVM(name='duplicate')
  96. with self.assertRaises(qubes.exc.QubesException):
  97. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'duplicate')
  98. @unittest.skip('test not implemented')
  99. def test_020_setter_kernel(self):
  100. pass
  101. def test_030_setter_label_object(self):
  102. label = TestApp.labels[1]
  103. self.assertIs(label,
  104. qubes.vm.qubesvm._setter_label(self.vm, self.prop, label))
  105. def test_031_setter_label_getitem(self):
  106. label = TestApp.labels[1]
  107. self.assertIs(label,
  108. qubes.vm.qubesvm._setter_label(self.vm, self.prop, 'label-1'))
  109. # there is no check for self.app.get_label()
  110. class TC_90_QubesVM(qubes.tests.QubesTestCase):
  111. def setUp(self):
  112. super(TC_90_QubesVM, self).setUp()
  113. self.app = qubes.tests.vm.TestApp()
  114. def get_vm(self, **kwargs):
  115. return qubes.vm.qubesvm.QubesVM(self.app, None,
  116. qid=1, name=qubes.tests.VMPREFIX + 'test',
  117. **kwargs)
  118. property_no_default = object()
  119. def assertPropertyValue(self, vm, prop_name, set_value, expected_value,
  120. expected_xml_content=None):
  121. # FIXME: any better exception list? or maybe all of that should be a
  122. # single exception?
  123. with self.assertNotRaises((ValueError, TypeError, KeyError)):
  124. setattr(vm, prop_name, set_value)
  125. self.assertEquals(getattr(vm, prop_name), expected_value)
  126. if expected_xml_content is not None:
  127. xml = vm.__xml__()
  128. prop_xml = xml.xpath(
  129. './properties/property[@name=\'{}\']'.format(prop_name))
  130. self.assertEquals(len(prop_xml), 1, "Property not found in XML")
  131. self.assertEquals(prop_xml[0].text, expected_xml_content)
  132. def assertPropertyInvalidValue(self, vm, prop_name, set_value):
  133. orig_value_set = True
  134. orig_value = None
  135. try:
  136. orig_value = getattr(vm, prop_name)
  137. except AttributeError:
  138. orig_value_set = False
  139. # FIXME: any better exception list? or maybe all of that should be a
  140. # single exception?
  141. with self.assertRaises((ValueError, TypeError, KeyError)):
  142. setattr(vm, prop_name, set_value)
  143. if orig_value_set:
  144. self.assertEquals(getattr(vm, prop_name), orig_value)
  145. else:
  146. with self.assertRaises(AttributeError):
  147. getattr(vm, prop_name)
  148. def assertPropertyDefaultValue(self, vm, prop_name,
  149. expected_default=property_no_default):
  150. if expected_default is self.property_no_default:
  151. with self.assertRaises(AttributeError):
  152. getattr(vm, prop_name)
  153. else:
  154. with self.assertNotRaises(AttributeError):
  155. self.assertEquals(getattr(vm, prop_name), expected_default)
  156. xml = vm.__xml__()
  157. prop_xml = xml.xpath(
  158. './properties/property[@name=\'{}\']'.format(prop_name))
  159. self.assertEquals(len(prop_xml), 0, "Property still found in XML")
  160. def _test_generic_bool_property(self, vm, prop_name, default=False):
  161. self.assertPropertyDefaultValue(vm, prop_name, default)
  162. self.assertPropertyValue(vm, prop_name, False, False, 'False')
  163. self.assertPropertyValue(vm, prop_name, True, True, 'True')
  164. delattr(vm, prop_name)
  165. self.assertPropertyDefaultValue(vm, prop_name, default)
  166. self.assertPropertyValue(vm, prop_name, 'True', True, 'True')
  167. self.assertPropertyValue(vm, prop_name, 'False', False, 'False')
  168. self.assertPropertyInvalidValue(vm, prop_name, 'xxx')
  169. self.assertPropertyValue(vm, prop_name, 123, True)
  170. self.assertPropertyInvalidValue(vm, prop_name, '')
  171. def setup_netvms(self, vm):
  172. # usage of QubesVM here means that those tests should be after
  173. # testing properties used here
  174. self.netvm1 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=2,
  175. name=qubes.tests.VMPREFIX + 'netvm1',
  176. provides_network=True)
  177. self.netvm2 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=3,
  178. name=qubes.tests.VMPREFIX + 'netvm2',
  179. provides_network=True)
  180. self.nonetvm = qubes.vm.qubesvm.QubesVM(self.app, None, qid=4,
  181. name=qubes.tests.VMPREFIX + 'nonet')
  182. self.app.domains = {}
  183. for domain in (vm, self.netvm1, self.netvm2, self.nonetvm):
  184. self.app.domains[domain.qid] = domain
  185. self.app.domains[domain] = domain
  186. self.app.domains[domain.name] = domain
  187. self.app.default_netvm = self.netvm1
  188. def test_000_init(self):
  189. self.get_vm()
  190. def test_001_init_no_qid_or_name(self):
  191. with self.assertRaises(AssertionError):
  192. qubes.vm.qubesvm.QubesVM(self.app, None,
  193. name=qubes.tests.VMPREFIX + 'test')
  194. with self.assertRaises(AssertionError):
  195. qubes.vm.qubesvm.QubesVM(self.app, None,
  196. qid=1)
  197. def test_003_init_fire_domain_init(self):
  198. class TestVM2(qubes.vm.qubesvm.QubesVM):
  199. event_fired = False
  200. @qubes.events.handler('domain-init')
  201. def on_domain_init(self, event): # pylint: disable=unused-argument
  202. self.__class__.event_fired = True
  203. TestVM2(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test')
  204. self.assertTrue(TestVM2.event_fired)
  205. def test_004_uuid_autogen(self):
  206. vm = self.get_vm()
  207. self.assertTrue(hasattr(vm, 'uuid'))
  208. def test_100_qid(self):
  209. vm = self.get_vm()
  210. self.assertIsInstance(vm.qid, int)
  211. with self.assertRaises(AttributeError):
  212. vm.qid = 2
  213. def test_110_name(self):
  214. vm = self.get_vm()
  215. self.assertIsInstance(vm.name, basestring)
  216. def test_120_uuid(self):
  217. my_uuid = uuid.uuid4()
  218. vm = self.get_vm(uuid=my_uuid)
  219. self.assertIsInstance(vm.uuid, uuid.UUID)
  220. self.assertIs(vm.uuid, my_uuid)
  221. with self.assertRaises(AttributeError):
  222. vm.uuid = uuid.uuid4()
  223. @unittest.skip('TODO: how to not fail on making an icon symlink here?')
  224. def test_130_label(self):
  225. vm = self.get_vm()
  226. self.assertPropertyDefaultValue(vm, 'label')
  227. self.assertPropertyValue(vm, 'label', self.app.labels[1],
  228. self.app.labels[1], 'label-1')
  229. del vm.label
  230. self.assertPropertyDefaultValue(vm, 'label')
  231. self.assertPropertyValue(vm, 'label', 'red',
  232. self.app.labels[1], 'label-1')
  233. self.assertPropertyValue(vm, 'label', 'label-1',
  234. self.app.labels[1], 'label-1')
  235. def test_131_label_invalid(self):
  236. vm = self.get_vm()
  237. self.assertPropertyInvalidValue(vm, 'label', 'invalid')
  238. self.assertPropertyInvalidValue(vm, 'label', 123)
  239. def test_140_netvm(self):
  240. vm = self.get_vm()
  241. self.setup_netvms(vm)
  242. self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
  243. self.assertPropertyValue(vm, 'netvm', self.netvm2, self.netvm2,
  244. self.netvm2.name)
  245. del vm.netvm
  246. self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
  247. self.assertPropertyValue(vm, 'netvm', self.netvm2.name, self.netvm2,
  248. self.netvm2.name)
  249. self.assertPropertyValue(vm, 'netvm', None, None, '')
  250. def test_141_netvm_invalid(self):
  251. vm = self.get_vm()
  252. self.setup_netvms(vm)
  253. self.assertPropertyInvalidValue(vm, 'netvm', 'invalid')
  254. self.assertPropertyInvalidValue(vm, 'netvm', 123)
  255. def test_142_netvm_netvm(self):
  256. vm = self.get_vm()
  257. self.setup_netvms(vm)
  258. self.assertPropertyInvalidValue(vm, 'netvm', self.nonetvm)
  259. def test_143_netvm_loopback(self):
  260. vm = self.get_vm()
  261. self.app.domains = {1: vm, vm: vm}
  262. self.assertPropertyInvalidValue(vm, 'netvm', vm)
  263. def test_150_hvm(self):
  264. vm = self.get_vm()
  265. self._test_generic_bool_property(vm, 'hvm')
  266. def test_160_memory(self):
  267. vm = self.get_vm()
  268. self.assertPropertyDefaultValue(vm, 'memory', 400)
  269. self.assertPropertyValue(vm, 'memory', 500, 500, '500')
  270. del vm.memory
  271. self.assertPropertyDefaultValue(vm, 'memory', 400)
  272. self.assertPropertyValue(vm, 'memory', '500', 500, '500')
  273. def test_161_memory_invalid(self):
  274. vm = self.get_vm()
  275. self.assertPropertyInvalidValue(vm, 'memory', -100)
  276. self.assertPropertyInvalidValue(vm, 'memory', '-100')
  277. self.assertPropertyInvalidValue(vm, 'memory', '')
  278. def test_162_memory_more_than_host(self):
  279. vm = self.get_vm()
  280. self.assertPropertyInvalidValue(vm, 'memory',
  281. 2 * self.app.host.memory_total)
  282. # TODO: higher than maxmem
  283. # TODO: human readable setter (500M, 4G)?
  284. def test_170_maxmem(self):
  285. vm = self.get_vm()
  286. self.assertPropertyDefaultValue(vm, 'maxmem',
  287. self.app.host.memory_total / 1024 / 2)
  288. self.assertPropertyValue(vm, 'maxmem', 500, 500, '500')
  289. del vm.maxmem
  290. self.assertPropertyDefaultValue(vm, 'maxmem',
  291. self.app.host.memory_total / 1024 / 2)
  292. self.assertPropertyValue(vm, 'maxmem', '500', 500, '500')
  293. def test_171_maxmem_invalid(self):
  294. vm = self.get_vm()
  295. self.assertPropertyInvalidValue(vm, 'maxmem', -100)
  296. self.assertPropertyInvalidValue(vm, 'maxmem', '-100')
  297. self.assertPropertyInvalidValue(vm, 'maxmem', '')
  298. def test_172_maxmem_more_than_host(self):
  299. vm = self.get_vm()
  300. self.assertPropertyInvalidValue(vm, 'maxmem',
  301. 2 * self.app.host.memory_total)
  302. # TODO: lower than memory
  303. # TODO: human readable setter (500M, 4G)?
  304. def test_180_internal(self):
  305. vm = self.get_vm()
  306. self._test_generic_bool_property(vm, 'internal', False)
  307. def test_190_vcpus(self):
  308. vm = self.get_vm()
  309. self.assertPropertyDefaultValue(vm, 'vcpus', self.app.host.no_cpus)
  310. self.assertPropertyValue(vm, 'vcpus', 3, 3, '3')
  311. del vm.vcpus
  312. self.assertPropertyDefaultValue(vm, 'vcpus', self.app.host.no_cpus)
  313. self.assertPropertyValue(vm, 'vcpus', '3', 3, '3')
  314. def test_191_vcpus_invalid(self):
  315. vm = self.get_vm()
  316. self.assertPropertyInvalidValue(vm, 'vcpus', 0)
  317. self.assertPropertyInvalidValue(vm, 'vcpus', -2)
  318. self.assertPropertyInvalidValue(vm, 'vcpus', '-2')
  319. self.assertPropertyInvalidValue(vm, 'vcpus', '')
  320. self.assertPropertyInvalidValue(vm, 'vcpus',
  321. 2 * self.app.host.no_cpus)
  322. def test_200_debug(self):
  323. vm = self.get_vm()
  324. self._test_generic_bool_property(vm, 'debug', False)
  325. def test_210_installed_by_rpm(self):
  326. vm = self.get_vm()
  327. self._test_generic_bool_property(vm, 'installed_by_rpm', False)
  328. def test_220_include_in_backups(self):
  329. vm = self.get_vm()
  330. self._test_generic_bool_property(vm, 'include_in_backups', True)
  331. def test_230_backup_content(self):
  332. vm = self.get_vm()
  333. self._test_generic_bool_property(vm, 'backup_content', False)
  334. def test_240_firewall_conf(self):
  335. vm = self.get_vm()
  336. self.assertPropertyDefaultValue(vm, 'firewall_conf', 'firewall.xml')
  337. self.assertPropertyValue(vm, 'firewall_conf', 'other.xml',
  338. 'other.xml', 'other.xml')
  339. del vm.firewall_conf
  340. self.assertPropertyDefaultValue(vm, 'firewall_conf',
  341. 'firewall.xml')
  342. def test_241_firewall_conf_invalid(self):
  343. vm = self.get_vm()
  344. self.assertPropertyInvalidValue(vm, 'firewall_conf', None)
  345. @qubes.tests.skipUnlessDom0
  346. def test_250_kernel(self):
  347. kernels = os.listdir(os.path.join(
  348. qubes.config.qubes_base_dir,
  349. qubes.config.system_path['qubes_kernels_base_dir']))
  350. if not len(kernels):
  351. self.skipTest('Needs at least one kernel installed')
  352. self.app.default_kernel = kernels[0]
  353. vm = self.get_vm()
  354. self.assertPropertyDefaultValue(vm, 'kernel', kernels[0])
  355. self.assertPropertyValue(vm, 'kernel', kernels[-1], kernels[-1],
  356. kernels[-1])
  357. del vm.kernel
  358. self.assertPropertyDefaultValue(vm, 'kernel', kernels[0])
  359. @qubes.tests.skipUnlessDom0
  360. def test_251_kernel_invalid(self):
  361. vm = self.get_vm()
  362. self.assertPropertyInvalidValue(vm, 'kernel', 123)
  363. self.assertPropertyInvalidValue(vm, 'kernel', 'invalid')
  364. def test_260_kernelopts(self):
  365. vm = self.get_vm()
  366. self.assertPropertyDefaultValue(vm, 'kernelopts',
  367. qubes.config.defaults['kernelopts'])
  368. self.assertPropertyValue(vm, 'kernelopts', 'some options',
  369. 'some options', 'some options')
  370. del vm.kernelopts
  371. self.assertPropertyDefaultValue(vm, 'kernelopts',
  372. qubes.config.defaults['kernelopts'])
  373. self.assertPropertyValue(vm, 'kernelopts', '',
  374. '', '')
  375. # TODO?
  376. # self.assertPropertyInvalidValue(vm, 'kernelopts', None),
  377. @unittest.skip('test not implemented')
  378. def test_261_kernelopts_pcidevs(self):
  379. vm = self.get_vm()
  380. # how to do that here? use dummy DeviceManager/DeviceCollection?
  381. # Disable events?
  382. vm.devices['pci'].attach('something')
  383. self.assertPropertyDefaultValue(vm, 'kernelopts',
  384. qubes.config.defaults['kernelopts_pcidevs'])
  385. def test_270_qrexec_timeout(self):
  386. vm = self.get_vm()
  387. self.assertPropertyDefaultValue(vm, 'qrexec_timeout', 60)
  388. self.assertPropertyValue(vm, 'qrexec_timeout', 3, 3, '3')
  389. del vm.qrexec_timeout
  390. self.assertPropertyDefaultValue(vm, 'qrexec_timeout', 60)
  391. self.assertPropertyValue(vm, 'qrexec_timeout', '3', 3, '3')
  392. def test_271_qrexec_timeout_invalid(self):
  393. vm = self.get_vm()
  394. self.assertPropertyInvalidValue(vm, 'qrexec_timeout', -2)
  395. self.assertPropertyInvalidValue(vm, 'qrexec_timeout', '-2')
  396. self.assertPropertyInvalidValue(vm, 'qrexec_timeout', '')
  397. def test_280_autostart(self):
  398. vm = self.get_vm()
  399. # FIXME any better idea to not involve systemctl call at this stage?
  400. vm.events_enabled = False
  401. self._test_generic_bool_property(vm, 'autostart', False)
  402. @qubes.tests.skipUnlessDom0
  403. def test_281_autostart_systemd(self):
  404. vm = self.get_vm()
  405. self.assertFalse(os.path.exists(
  406. '/etc/systemd/system/multi-user.target.wants/'
  407. 'qubes-vm@{}.service'.format(vm.name)),
  408. "systemd service enabled before setting autostart")
  409. vm.autostart = True
  410. self.assertTrue(os.path.exists(
  411. '/etc/systemd/system/multi-user.target.wants/'
  412. 'qubes-vm@{}.service'.format(vm.name)),
  413. "systemd service not enabled by autostart=True")
  414. vm.autostart = False
  415. self.assertFalse(os.path.exists(
  416. '/etc/systemd/system/multi-user.target.wants/'
  417. 'qubes-vm@{}.service'.format(vm.name)),
  418. "systemd service not disabled by autostart=False")
  419. vm.autostart = True
  420. del vm.autostart
  421. self.assertFalse(os.path.exists(
  422. '/etc/systemd/system/multi-user.target.wants/'
  423. 'qubes-vm@{}.service'.format(vm.name)),
  424. "systemd service not disabled by resetting autostart")
  425. def test_290_dispvm_netvm(self):
  426. vm = self.get_vm()
  427. self.setup_netvms(vm)
  428. self.assertPropertyDefaultValue(vm, 'dispvm_netvm',
  429. self.app.default_netvm)
  430. self.assertPropertyValue(vm, 'dispvm_netvm', self.netvm2, self.netvm2,
  431. self.netvm2.name)
  432. del vm.dispvm_netvm
  433. self.assertPropertyDefaultValue(vm, 'dispvm_netvm',
  434. self.app.default_netvm)
  435. self.assertPropertyValue(vm, 'dispvm_netvm', self.netvm2.name,
  436. self.netvm2, self.netvm2.name)
  437. # XXX FIXME xml value
  438. self.assertPropertyValue(vm, 'dispvm_netvm', None, None, 'None')
  439. def test_291_dispvm_netvm_invalid(self):
  440. vm = self.get_vm()
  441. self.setup_netvms(vm)
  442. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', 'invalid')
  443. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', 123)
  444. def test_291_dispvm_netvm_netvm(self):
  445. vm = self.get_vm()
  446. nonetvm = TestVM(qid=2, app=self.app, name='nonetvm')
  447. self.app.domains = {1: vm, 2: nonetvm}
  448. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', nonetvm)
  449. def test_291_dispvm_netvm_default(self):
  450. """Check if vm.dispvm_netvm default is really vm.netvm"""
  451. vm = self.get_vm()
  452. self.setup_netvms(vm)
  453. vm.netvm = self.netvm2
  454. self.assertPropertyDefaultValue(vm, 'dispvm_netvm', self.netvm2)
  455. del vm.netvm
  456. self.assertPropertyDefaultValue(vm, 'dispvm_netvm', self.netvm1)
  457. def test_292_dispvm_netvm_loopback(self):
  458. vm = self.get_vm()
  459. self.app.domains = {1: vm, vm: vm}
  460. self.assertPropertyInvalidValue(vm, 'dispvm_netvm', vm)
  461. @unittest.skip('TODO')
  462. def test_300_qrexec_installed(self):
  463. vm = self.get_vm()
  464. self._test_generic_bool_property(vm, 'qrexec_installed', True)
  465. @unittest.skip('TODO')
  466. def test_301_qrexec_installed_default(self):
  467. vm = self.get_vm()
  468. vm.hvm = False
  469. self.assertPropertyDefaultValue(vm, 'qrexec_installed', True)
  470. vm.hvm = True
  471. self.assertPropertyDefaultValue(vm, 'qrexec_installed', False)
  472. # TODO: check inheritance from a template - in appvm copy of this test
  473. @unittest.skip('TODO')
  474. def test_310_guiagent_installed(self):
  475. vm = self.get_vm()
  476. self._test_generic_bool_property(vm, 'guiagent_installed', True)
  477. # TODO: check inheritance from a template - in appvm copy of this test
  478. @unittest.skip('TODO')
  479. def test_311_guiagent_installed_default(self):
  480. vm = self.get_vm()
  481. vm.hvm = False
  482. self.assertPropertyDefaultValue(vm, 'guiagent_installed', True)
  483. vm.hvm = True
  484. self.assertPropertyDefaultValue(vm, 'guiagent_installed', False)
  485. # TODO: check inheritance from a template - in appvm copy of this test
  486. @unittest.skip('TODO')
  487. def test_320_seamless_gui_mode(self):
  488. vm = self.get_vm()
  489. self._test_generic_bool_property(vm, 'seamless_gui_mode')
  490. # TODO: reject setting to True when guiagent_installed is false
  491. def test_330_mac(self):
  492. vm = self.get_vm()
  493. # TODO: calculate proper default here
  494. default_mac = vm.mac
  495. self.assertIsNotNone(default_mac)
  496. self.assertPropertyDefaultValue(vm, 'mac', default_mac)
  497. self.assertPropertyValue(vm, 'mac', '00:11:22:33:44:55',
  498. '00:11:22:33:44:55', '00:11:22:33:44:55')
  499. del vm.mac
  500. self.assertPropertyDefaultValue(vm, 'mac', default_mac)
  501. def test_331_mac_invalid(self):
  502. vm = self.get_vm()
  503. self.assertPropertyInvalidValue(vm, 'mac', 123)
  504. self.assertPropertyInvalidValue(vm, 'mac', 'invalid')
  505. self.assertPropertyInvalidValue(vm, 'mac', '00:11:22:33:44:55:66')
  506. def test_340_default_user(self):
  507. vm = self.get_vm()
  508. self.assertPropertyDefaultValue(vm, 'default_user', 'user')
  509. self.assertPropertyValue(vm, 'default_user', 'someuser', 'someuser',
  510. 'someuser')
  511. del vm.default_user
  512. self.assertPropertyDefaultValue(vm, 'default_user', 'user')
  513. self.assertPropertyValue(vm, 'default_user', 123, '123', '123')
  514. # TODO: check propagation for template-based VMs
  515. @unittest.skip('TODO')
  516. def test_350_timezone(self):
  517. vm = self.get_vm()
  518. self.assertPropertyDefaultValue(vm, 'timezone', 'localtime')
  519. self.assertPropertyValue(vm, 'timezone', 0, 0, '0')
  520. del vm.timezone
  521. self.assertPropertyDefaultValue(vm, 'timezone', 'localtime')
  522. self.assertPropertyValue(vm, 'timezone', '0', 0, '0')
  523. self.assertPropertyValue(vm, 'timezone', -3600, -3600, '-3600')
  524. self.assertPropertyValue(vm, 'timezone', 7200, 7200, '7200')
  525. @unittest.skip('TODO')
  526. def test_350_timezone_invalid(self):
  527. vm = self.get_vm()
  528. self.assertPropertyInvalidValue(vm, 'timezone', 'xxx')
  529. @unittest.skip('TODO')
  530. def test_360_drive(self):
  531. vm = self.get_vm()
  532. self.assertPropertyDefaultValue(vm, 'drive', None)
  533. # self.execute_tests('drive', [
  534. # ('hd:dom0:/tmp/drive.img', 'hd:dom0:/tmp/drive.img', True),
  535. # ('hd:/tmp/drive.img', 'hd:dom0:/tmp/drive.img', True),
  536. # ('cdrom:dom0:/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
  537. # ('cdrom:/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
  538. # ('/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
  539. # ('hd:drive.img', '', False),
  540. # ('drive.img', '', False),
  541. # ])
  542. @unittest.skip('TODO')
  543. def test_370_pci_strictreset(self):
  544. vm = self.get_vm()
  545. self._test_generic_bool_property(vm, 'pci_strictreset')
  546. def test_400_backup_timestamp(self):
  547. vm = self.get_vm()
  548. timestamp = datetime.datetime(2016, 1, 1, 12, 14, 2)
  549. timestamp_str = timestamp.strftime('%s')
  550. self.assertPropertyDefaultValue(vm, 'backup_timestamp', None)
  551. self.assertPropertyValue(vm, 'backup_timestamp', timestamp,
  552. timestamp, timestamp_str)
  553. del vm.backup_timestamp
  554. self.assertPropertyDefaultValue(vm, 'backup_timestamp', None)
  555. self.assertPropertyValue(vm, 'backup_timestamp', timestamp_str,
  556. timestamp)
  557. def test_401_backup_timestamp_invalid(self):
  558. vm = self.get_vm()
  559. self.assertPropertyInvalidValue(vm, 'backup_timestamp', 'xxx')
  560. self.assertPropertyInvalidValue(vm, 'backup_timestamp', None)