regressions.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/python2 -O
  2. # coding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2014-2015
  7. # Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  8. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This library is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU Lesser General Public
  12. # License as published by the Free Software Foundation; either
  13. # version 2.1 of the License, or (at your option) any later version.
  14. #
  15. # This library 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 GNU
  18. # Lesser General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Lesser General Public
  21. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  22. #
  23. import multiprocessing
  24. import os
  25. import time
  26. import unittest
  27. import qubes.qubes
  28. import qubes.tests
  29. import subprocess
  30. class TC_00_Regressions(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  31. # Bug: #906
  32. def test_000_bug_906_db_locking(self):
  33. def create_vm(vmname):
  34. qc = qubes.qubes.QubesVmCollection()
  35. qc.lock_db_for_writing()
  36. qc.load()
  37. time.sleep(1)
  38. qc.add_new_vm('QubesAppVm',
  39. name=vmname, template=qc.get_default_template())
  40. qc.save()
  41. qc.unlock_db()
  42. vmname1, vmname2 = map(self.make_vm_name, ('test1', 'test2'))
  43. t = multiprocessing.Process(target=create_vm, args=(vmname1,))
  44. t.start()
  45. create_vm(vmname2)
  46. t.join()
  47. qc = qubes.qubes.QubesVmCollection()
  48. qc.lock_db_for_reading()
  49. qc.load()
  50. qc.unlock_db()
  51. self.assertIsNotNone(qc.get_vm_by_name(vmname1))
  52. self.assertIsNotNone(qc.get_vm_by_name(vmname2))
  53. def test_bug_1389_dispvm_qubesdb_crash(self):
  54. """
  55. Sometimes QubesDB instance in DispVM crashes at startup.
  56. Unfortunately we don't have reliable way to reproduce it, so try twice
  57. :return:
  58. """
  59. self.qc.unlock_db()
  60. for try_no in xrange(2):
  61. p = subprocess.Popen(['/usr/lib/qubes/qfile-daemon-dvm',
  62. 'qubes.VMShell', 'dom0', 'DEFAULT'],
  63. stdin=subprocess.PIPE,
  64. stdout=subprocess.PIPE,
  65. stderr=open(os.devnull, 'w'))
  66. p.stdin.write("qubesdb-read /name || echo ERROR\n")
  67. dispvm_name = p.stdout.readline()
  68. p.stdin.close()
  69. self.assertTrue(dispvm_name.startswith("disp"),
  70. "Try {} failed".format(try_no))