qubesvm.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. # pylint: disable=protected-access
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  6. # Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. #
  22. import os
  23. import unittest
  24. import uuid
  25. import datetime
  26. import qubes
  27. import qubes.exc
  28. import qubes.config
  29. import qubes.vm.qubesvm
  30. import qubes.tests
  31. class TestApp(object):
  32. labels = {1: qubes.Label(1, '0xcc0000', 'red')}
  33. def __init__(self):
  34. self.domains = {}
  35. class TestProp(object):
  36. # pylint: disable=too-few-public-methods
  37. __name__ = 'testprop'
  38. class TestVM(object):
  39. # pylint: disable=too-few-public-methods
  40. app = TestApp()
  41. def __init__(self, **kwargs):
  42. self.running = False
  43. self.installed_by_rpm = False
  44. for k, v in kwargs.items():
  45. setattr(self, k, v)
  46. def is_running(self):
  47. return self.running
  48. class TC_00_setters(qubes.tests.QubesTestCase):
  49. def setUp(self):
  50. self.vm = TestVM()
  51. self.prop = TestProp()
  52. def test_000_setter_qid(self):
  53. self.assertEqual(
  54. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, 5), 5)
  55. def test_001_setter_qid_lt_0(self):
  56. with self.assertRaises(ValueError):
  57. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, -1)
  58. def test_002_setter_qid_gt_max(self):
  59. with self.assertRaises(ValueError):
  60. qubes.vm.qubesvm._setter_qid(self.vm,
  61. self.prop, qubes.config.max_qid + 5)
  62. def test_010_setter_name(self):
  63. self.assertEqual(
  64. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'),
  65. 'test_name-1')
  66. def test_011_setter_name_not_a_string(self):
  67. # pylint: disable=invalid-name
  68. with self.assertRaises(TypeError):
  69. qubes.vm.qubesvm._setter_name(self.vm, self.prop, False)
  70. def test_012_setter_name_longer_than_31(self):
  71. # pylint: disable=invalid-name
  72. with self.assertRaises(ValueError):
  73. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32)
  74. def test_013_setter_name_illegal_character(self):
  75. # pylint: disable=invalid-name
  76. with self.assertRaises(ValueError):
  77. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#')
  78. def test_014_setter_name_first_not_letter(self):
  79. # pylint: disable=invalid-name
  80. with self.assertRaises(ValueError):
  81. qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test')
  82. def test_015_setter_name_running(self):
  83. self.vm.running = True
  84. with self.assertRaises(qubes.exc.QubesVMNotHaltedError):
  85. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  86. def test_016_setter_name_installed_by_rpm(self):
  87. # pylint: disable=invalid-name
  88. self.vm.installed_by_rpm = True
  89. with self.assertRaises(qubes.exc.QubesException):
  90. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  91. def test_017_setter_name_duplicate(self):
  92. # pylint: disable=invalid-name
  93. self.vm.app.domains['duplicate'] = TestVM(name='duplicate')
  94. with self.assertRaises(qubes.exc.QubesException):
  95. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'duplicate')
  96. @unittest.skip('test not implemented')
  97. def test_020_setter_kernel(self):
  98. pass
  99. def test_030_setter_label_object(self):
  100. label = TestApp.labels[1]
  101. self.assertIs(label,
  102. qubes.vm.qubesvm._setter_label(self.vm, self.prop, label))
  103. def test_031_setter_label_getitem(self):
  104. label = TestApp.labels[1]
  105. self.assertIs(label,
  106. qubes.vm.qubesvm._setter_label(self.vm, self.prop, 'label-1'))
  107. # there is no check for self.app.get_label()
  108. class QubesVMTestsMixin(object):
  109. property_no_default = object()
  110. def setUp(self):
  111. super(QubesVMTestsMixin, self).setUp()
  112. self.app = qubes.tests.vm.TestApp()
  113. self.app.vmm.offline_mode = True
  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. def assertPropertyValue(self, vm, prop_name, set_value, expected_value,
  119. expected_xml_content=None):
  120. # FIXME: any better exception list? or maybe all of that should be a
  121. # single exception?
  122. with self.assertNotRaises((ValueError, TypeError, KeyError)):
  123. setattr(vm, prop_name, set_value)
  124. self.assertEquals(getattr(vm, prop_name), expected_value)
  125. if expected_xml_content is not None:
  126. xml = vm.__xml__()
  127. prop_xml = xml.xpath(
  128. './properties/property[@name=\'{}\']'.format(prop_name))
  129. self.assertEquals(len(prop_xml), 1, "Property not found in XML")
  130. self.assertEquals(prop_xml[0].text, expected_xml_content)
  131. def assertPropertyInvalidValue(self, vm, prop_name, set_value):
  132. orig_value_set = True
  133. orig_value = None
  134. try:
  135. orig_value = getattr(vm, prop_name)
  136. except AttributeError:
  137. orig_value_set = False
  138. # FIXME: any better exception list? or maybe all of that should be a
  139. # single exception?
  140. with self.assertRaises((ValueError, TypeError, KeyError)):
  141. setattr(vm, prop_name, set_value)
  142. if orig_value_set:
  143. self.assertEquals(getattr(vm, prop_name), orig_value)
  144. else:
  145. with self.assertRaises(AttributeError):
  146. getattr(vm, prop_name)
  147. def assertPropertyDefaultValue(self, vm, prop_name,
  148. expected_default=property_no_default):
  149. if expected_default is self.property_no_default:
  150. with self.assertRaises(AttributeError):
  151. getattr(vm, prop_name)
  152. else:
  153. with self.assertNotRaises(AttributeError):
  154. self.assertEquals(getattr(vm, prop_name), expected_default)
  155. xml = vm.__xml__()
  156. prop_xml = xml.xpath(
  157. './properties/property[@name=\'{}\']'.format(prop_name))
  158. self.assertEquals(len(prop_xml), 0, "Property still found in XML")
  159. def _test_generic_bool_property(self, vm, prop_name, default=False):
  160. self.assertPropertyDefaultValue(vm, prop_name, default)
  161. self.assertPropertyValue(vm, prop_name, False, False, 'False')
  162. self.assertPropertyValue(vm, prop_name, True, True, 'True')
  163. delattr(vm, prop_name)
  164. self.assertPropertyDefaultValue(vm, prop_name, default)
  165. self.assertPropertyValue(vm, prop_name, 'True', True, 'True')
  166. self.assertPropertyValue(vm, prop_name, 'False', False, 'False')
  167. self.assertPropertyInvalidValue(vm, prop_name, 'xxx')
  168. self.assertPropertyValue(vm, prop_name, 123, True)
  169. self.assertPropertyInvalidValue(vm, prop_name, '')
  170. class TC_90_QubesVM(QubesVMTestsMixin,qubes.tests.QubesTestCase):
  171. def test_000_init(self):
  172. self.get_vm()
  173. def test_001_init_no_qid_or_name(self):
  174. with self.assertRaises(AssertionError):
  175. qubes.vm.qubesvm.QubesVM(self.app, None,
  176. name=qubes.tests.VMPREFIX + 'test')
  177. with self.assertRaises(AssertionError):
  178. qubes.vm.qubesvm.QubesVM(self.app, None,
  179. qid=1)
  180. def test_003_init_fire_domain_init(self):
  181. class TestVM2(qubes.vm.qubesvm.QubesVM):
  182. event_fired = False
  183. @qubes.events.handler('domain-init')
  184. def on_domain_init(self, event): # pylint: disable=unused-argument
  185. self.__class__.event_fired = True
  186. TestVM2(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test')
  187. self.assertTrue(TestVM2.event_fired)
  188. def test_004_uuid_autogen(self):
  189. vm = self.get_vm()
  190. self.assertTrue(hasattr(vm, 'uuid'))
  191. def test_100_qid(self):
  192. vm = self.get_vm()
  193. self.assertIsInstance(vm.qid, int)
  194. with self.assertRaises(AttributeError):
  195. vm.qid = 2
  196. def test_110_name(self):
  197. vm = self.get_vm()
  198. self.assertIsInstance(vm.name, str)
  199. def test_120_uuid(self):
  200. my_uuid = uuid.uuid4()
  201. vm = self.get_vm(uuid=my_uuid)
  202. self.assertIsInstance(vm.uuid, uuid.UUID)
  203. self.assertIs(vm.uuid, my_uuid)
  204. with self.assertRaises(AttributeError):
  205. vm.uuid = uuid.uuid4()
  206. @unittest.skip('TODO: how to not fail on making an icon symlink here?')
  207. def test_130_label(self):
  208. vm = self.get_vm()
  209. self.assertPropertyDefaultValue(vm, 'label')
  210. self.assertPropertyValue(vm, 'label', self.app.labels[1],
  211. self.app.labels[1], 'label-1')
  212. del vm.label
  213. self.assertPropertyDefaultValue(vm, 'label')
  214. self.assertPropertyValue(vm, 'label', 'red',
  215. self.app.labels[1], 'label-1')
  216. self.assertPropertyValue(vm, 'label', 'label-1',
  217. self.app.labels[1], 'label-1')
  218. def test_131_label_invalid(self):
  219. vm = self.get_vm()
  220. self.assertPropertyInvalidValue(vm, 'label', 'invalid')
  221. self.assertPropertyInvalidValue(vm, 'label', 123)
  222. def test_150_hvm(self):
  223. vm = self.get_vm()
  224. self._test_generic_bool_property(vm, 'hvm')
  225. def test_160_memory(self):
  226. vm = self.get_vm()
  227. self.assertPropertyDefaultValue(vm, 'memory', 400)
  228. self.assertPropertyValue(vm, 'memory', 500, 500, '500')
  229. del vm.memory
  230. self.assertPropertyDefaultValue(vm, 'memory', 400)
  231. self.assertPropertyValue(vm, 'memory', '500', 500, '500')
  232. def test_161_memory_invalid(self):
  233. vm = self.get_vm()
  234. self.assertPropertyInvalidValue(vm, 'memory', -100)
  235. self.assertPropertyInvalidValue(vm, 'memory', '-100')
  236. self.assertPropertyInvalidValue(vm, 'memory', '')
  237. # TODO: higher than maxmem
  238. # TODO: human readable setter (500M, 4G)?
  239. def test_170_maxmem(self):
  240. vm = self.get_vm()
  241. self.assertPropertyDefaultValue(vm, 'maxmem',
  242. self.app.host.memory_total / 1024 / 2)
  243. self.assertPropertyValue(vm, 'maxmem', 500, 500, '500')
  244. del vm.maxmem
  245. self.assertPropertyDefaultValue(vm, 'maxmem',
  246. self.app.host.memory_total / 1024 / 2)
  247. self.assertPropertyValue(vm, 'maxmem', '500', 500, '500')
  248. def test_171_maxmem_invalid(self):
  249. vm = self.get_vm()
  250. self.assertPropertyInvalidValue(vm, 'maxmem', -100)
  251. self.assertPropertyInvalidValue(vm, 'maxmem', '-100')
  252. self.assertPropertyInvalidValue(vm, 'maxmem', '')
  253. # TODO: lower than memory
  254. # TODO: human readable setter (500M, 4G)?
  255. def test_180_internal(self):
  256. vm = self.get_vm(label='red')
  257. self._test_generic_bool_property(vm, 'internal', False)
  258. def test_190_vcpus(self):
  259. vm = self.get_vm()
  260. self.assertPropertyDefaultValue(vm, 'vcpus', self.app.host.no_cpus)
  261. self.assertPropertyValue(vm, 'vcpus', 3, 3, '3')
  262. del vm.vcpus
  263. self.assertPropertyDefaultValue(vm, 'vcpus', self.app.host.no_cpus)
  264. self.assertPropertyValue(vm, 'vcpus', '3', 3, '3')
  265. def test_191_vcpus_invalid(self):
  266. vm = self.get_vm()
  267. self.assertPropertyInvalidValue(vm, 'vcpus', 0)
  268. self.assertPropertyInvalidValue(vm, 'vcpus', -2)
  269. self.assertPropertyInvalidValue(vm, 'vcpus', '-2')
  270. self.assertPropertyInvalidValue(vm, 'vcpus', '')
  271. def test_200_debug(self):
  272. vm = self.get_vm()
  273. self._test_generic_bool_property(vm, 'debug', False)
  274. def test_210_installed_by_rpm(self):
  275. vm = self.get_vm()
  276. self._test_generic_bool_property(vm, 'installed_by_rpm', False)
  277. def test_220_include_in_backups(self):
  278. vm = self.get_vm()
  279. self._test_generic_bool_property(vm, 'include_in_backups', True)
  280. @qubes.tests.skipUnlessDom0
  281. def test_250_kernel(self):
  282. kernels = os.listdir(os.path.join(
  283. qubes.config.qubes_base_dir,
  284. qubes.config.system_path['qubes_kernels_base_dir']))
  285. if not len(kernels):
  286. self.skipTest('Needs at least one kernel installed')
  287. self.app.default_kernel = kernels[0]
  288. vm = self.get_vm()
  289. self.assertPropertyDefaultValue(vm, 'kernel', kernels[0])
  290. self.assertPropertyValue(vm, 'kernel', kernels[-1], kernels[-1],
  291. kernels[-1])
  292. del vm.kernel
  293. self.assertPropertyDefaultValue(vm, 'kernel', kernels[0])
  294. @qubes.tests.skipUnlessDom0
  295. def test_251_kernel_invalid(self):
  296. vm = self.get_vm()
  297. self.assertPropertyInvalidValue(vm, 'kernel', 123)
  298. self.assertPropertyInvalidValue(vm, 'kernel', 'invalid')
  299. def test_260_kernelopts(self):
  300. vm = self.get_vm()
  301. self.assertPropertyDefaultValue(vm, 'kernelopts',
  302. qubes.config.defaults['kernelopts'])
  303. self.assertPropertyValue(vm, 'kernelopts', 'some options',
  304. 'some options', 'some options')
  305. del vm.kernelopts
  306. self.assertPropertyDefaultValue(vm, 'kernelopts',
  307. qubes.config.defaults['kernelopts'])
  308. self.assertPropertyValue(vm, 'kernelopts', '',
  309. '', '')
  310. # TODO?
  311. # self.assertPropertyInvalidValue(vm, 'kernelopts', None),
  312. @unittest.skip('test not implemented')
  313. def test_261_kernelopts_pcidevs(self):
  314. vm = self.get_vm()
  315. # how to do that here? use dummy DeviceManager/DeviceCollection?
  316. # Disable events?
  317. vm.devices['pci'].attach('something')
  318. self.assertPropertyDefaultValue(vm, 'kernelopts',
  319. qubes.config.defaults['kernelopts_pcidevs'])
  320. def test_270_qrexec_timeout(self):
  321. vm = self.get_vm()
  322. self.assertPropertyDefaultValue(vm, 'qrexec_timeout', 60)
  323. self.assertPropertyValue(vm, 'qrexec_timeout', 3, 3, '3')
  324. del vm.qrexec_timeout
  325. self.assertPropertyDefaultValue(vm, 'qrexec_timeout', 60)
  326. self.assertPropertyValue(vm, 'qrexec_timeout', '3', 3, '3')
  327. def test_271_qrexec_timeout_invalid(self):
  328. vm = self.get_vm()
  329. self.assertPropertyInvalidValue(vm, 'qrexec_timeout', -2)
  330. self.assertPropertyInvalidValue(vm, 'qrexec_timeout', '-2')
  331. self.assertPropertyInvalidValue(vm, 'qrexec_timeout', '')
  332. def test_280_autostart(self):
  333. vm = self.get_vm()
  334. # FIXME any better idea to not involve systemctl call at this stage?
  335. vm.events_enabled = False
  336. self._test_generic_bool_property(vm, 'autostart', False)
  337. @qubes.tests.skipUnlessDom0
  338. def test_281_autostart_systemd(self):
  339. vm = self.get_vm()
  340. self.assertFalse(os.path.exists(
  341. '/etc/systemd/system/multi-user.target.wants/'
  342. 'qubes-vm@{}.service'.format(vm.name)),
  343. "systemd service enabled before setting autostart")
  344. vm.autostart = True
  345. self.assertTrue(os.path.exists(
  346. '/etc/systemd/system/multi-user.target.wants/'
  347. 'qubes-vm@{}.service'.format(vm.name)),
  348. "systemd service not enabled by autostart=True")
  349. vm.autostart = False
  350. self.assertFalse(os.path.exists(
  351. '/etc/systemd/system/multi-user.target.wants/'
  352. 'qubes-vm@{}.service'.format(vm.name)),
  353. "systemd service not disabled by autostart=False")
  354. vm.autostart = True
  355. del vm.autostart
  356. self.assertFalse(os.path.exists(
  357. '/etc/systemd/system/multi-user.target.wants/'
  358. 'qubes-vm@{}.service'.format(vm.name)),
  359. "systemd service not disabled by resetting autostart")
  360. @unittest.skip('TODO')
  361. def test_300_qrexec_installed(self):
  362. vm = self.get_vm()
  363. self._test_generic_bool_property(vm, 'qrexec_installed', True)
  364. @unittest.skip('TODO')
  365. def test_301_qrexec_installed_default(self):
  366. vm = self.get_vm()
  367. vm.hvm = False
  368. self.assertPropertyDefaultValue(vm, 'qrexec_installed', True)
  369. vm.hvm = True
  370. self.assertPropertyDefaultValue(vm, 'qrexec_installed', False)
  371. # TODO: check inheritance from a template - in appvm copy of this test
  372. @unittest.skip('TODO')
  373. def test_310_guiagent_installed(self):
  374. vm = self.get_vm()
  375. self._test_generic_bool_property(vm, 'guiagent_installed', True)
  376. # TODO: check inheritance from a template - in appvm copy of this test
  377. @unittest.skip('TODO')
  378. def test_311_guiagent_installed_default(self):
  379. vm = self.get_vm()
  380. vm.hvm = False
  381. self.assertPropertyDefaultValue(vm, 'guiagent_installed', True)
  382. vm.hvm = True
  383. self.assertPropertyDefaultValue(vm, 'guiagent_installed', False)
  384. # TODO: check inheritance from a template - in appvm copy of this test
  385. @unittest.skip('TODO')
  386. def test_320_seamless_gui_mode(self):
  387. vm = self.get_vm()
  388. self._test_generic_bool_property(vm, 'seamless_gui_mode')
  389. # TODO: reject setting to True when guiagent_installed is false
  390. def test_330_mac(self):
  391. vm = self.get_vm()
  392. # TODO: calculate proper default here
  393. default_mac = vm.mac
  394. self.assertIsNotNone(default_mac)
  395. self.assertPropertyDefaultValue(vm, 'mac', default_mac)
  396. self.assertPropertyValue(vm, 'mac', '00:11:22:33:44:55',
  397. '00:11:22:33:44:55', '00:11:22:33:44:55')
  398. del vm.mac
  399. self.assertPropertyDefaultValue(vm, 'mac', default_mac)
  400. def test_331_mac_invalid(self):
  401. vm = self.get_vm()
  402. self.assertPropertyInvalidValue(vm, 'mac', 123)
  403. self.assertPropertyInvalidValue(vm, 'mac', 'invalid')
  404. self.assertPropertyInvalidValue(vm, 'mac', '00:11:22:33:44:55:66')
  405. def test_340_default_user(self):
  406. vm = self.get_vm()
  407. self.assertPropertyDefaultValue(vm, 'default_user', 'user')
  408. self.assertPropertyValue(vm, 'default_user', 'someuser', 'someuser',
  409. 'someuser')
  410. del vm.default_user
  411. self.assertPropertyDefaultValue(vm, 'default_user', 'user')
  412. self.assertPropertyValue(vm, 'default_user', 123, '123', '123')
  413. # TODO: check propagation for template-based VMs
  414. @unittest.skip('TODO')
  415. def test_350_timezone(self):
  416. vm = self.get_vm()
  417. self.assertPropertyDefaultValue(vm, 'timezone', 'localtime')
  418. self.assertPropertyValue(vm, 'timezone', 0, 0, '0')
  419. del vm.timezone
  420. self.assertPropertyDefaultValue(vm, 'timezone', 'localtime')
  421. self.assertPropertyValue(vm, 'timezone', '0', 0, '0')
  422. self.assertPropertyValue(vm, 'timezone', -3600, -3600, '-3600')
  423. self.assertPropertyValue(vm, 'timezone', 7200, 7200, '7200')
  424. @unittest.skip('TODO')
  425. def test_350_timezone_invalid(self):
  426. vm = self.get_vm()
  427. self.assertPropertyInvalidValue(vm, 'timezone', 'xxx')
  428. @unittest.skip('TODO')
  429. def test_360_drive(self):
  430. vm = self.get_vm()
  431. self.assertPropertyDefaultValue(vm, 'drive', None)
  432. # self.execute_tests('drive', [
  433. # ('hd:dom0:/tmp/drive.img', 'hd:dom0:/tmp/drive.img', True),
  434. # ('hd:/tmp/drive.img', 'hd:dom0:/tmp/drive.img', True),
  435. # ('cdrom:dom0:/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
  436. # ('cdrom:/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
  437. # ('/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
  438. # ('hd:drive.img', '', False),
  439. # ('drive.img', '', False),
  440. # ])
  441. @unittest.skip('TODO')
  442. def test_370_pci_strictreset(self):
  443. vm = self.get_vm()
  444. self._test_generic_bool_property(vm, 'pci_strictreset')
  445. def test_400_backup_timestamp(self):
  446. vm = self.get_vm()
  447. timestamp = datetime.datetime(2016, 1, 1, 12, 14, 2)
  448. timestamp_str = timestamp.strftime('%s')
  449. self.assertPropertyDefaultValue(vm, 'backup_timestamp', None)
  450. self.assertPropertyValue(vm, 'backup_timestamp', timestamp,
  451. timestamp, timestamp_str)
  452. del vm.backup_timestamp
  453. self.assertPropertyDefaultValue(vm, 'backup_timestamp', None)
  454. self.assertPropertyValue(vm, 'backup_timestamp', timestamp_str,
  455. timestamp)
  456. def test_401_backup_timestamp_invalid(self):
  457. vm = self.get_vm()
  458. self.assertPropertyInvalidValue(vm, 'backup_timestamp', 'xxx')
  459. self.assertPropertyInvalidValue(vm, 'backup_timestamp', None)