regressions.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 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 multiprocessing
  25. import os
  26. import time
  27. import unittest
  28. import qubes.qubes
  29. import qubes.tests
  30. import subprocess
  31. class TC_00_Regressions(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  32. # Bug: #906
  33. def test_000_bug_906_db_locking(self):
  34. def create_vm(vmname):
  35. qc = qubes.qubes.QubesVmCollection()
  36. qc.lock_db_for_writing()
  37. qc.load()
  38. time.sleep(1)
  39. qc.add_new_vm('QubesAppVm',
  40. name=vmname, template=qc.get_default_template())
  41. qc.save()
  42. qc.unlock_db()
  43. vmname1, vmname2 = map(self.make_vm_name, ('test1', 'test2'))
  44. t = multiprocessing.Process(target=create_vm, args=(vmname1,))
  45. t.start()
  46. create_vm(vmname2)
  47. t.join()
  48. qc = qubes.qubes.QubesVmCollection()
  49. qc.lock_db_for_reading()
  50. qc.load()
  51. qc.unlock_db()
  52. self.assertIsNotNone(qc.get_vm_by_name(vmname1))
  53. self.assertIsNotNone(qc.get_vm_by_name(vmname2))
  54. def test_bug_1389_dispvm_qubesdb_crash(self):
  55. """
  56. Sometimes QubesDB instance in DispVM crashes at startup.
  57. Unfortunately we don't have reliable way to reproduce it, so try twice
  58. :return:
  59. """
  60. self.qc.unlock_db()
  61. for try_no in xrange(2):
  62. p = subprocess.Popen(['/usr/lib/qubes/qfile-daemon-dvm',
  63. 'qubes.VMShell', 'dom0', 'DEFAULT'],
  64. stdin=subprocess.PIPE,
  65. stdout=subprocess.PIPE,
  66. stderr=open(os.devnull, 'w'))
  67. p.stdin.write("qubesdb-read /name || echo ERROR\n")
  68. dispvm_name = p.stdout.readline()
  69. p.stdin.close()
  70. self.assertTrue(dispvm_name.startswith("disp"),
  71. "Try {} failed".format(try_no))