regressions.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/python2 -O
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2014-2015
  6. # Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  7. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. import multiprocessing
  24. import time
  25. import unittest
  26. import qubes.qubes
  27. import qubes.tests
  28. class TC_00_Regressions(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  29. # Bug: #906
  30. def test_000_bug_906_db_locking(self):
  31. def create_vm(vmname):
  32. qc = qubes.qubes.QubesVmCollection()
  33. qc.lock_db_for_writing()
  34. qc.load()
  35. time.sleep(1)
  36. qc.add_new_vm('QubesAppVm',
  37. name=vmname, template=qc.get_default_template())
  38. qc.save()
  39. qc.unlock_db()
  40. vmname1, vmname2 = map(self.make_vm_name, ('test1', 'test2'))
  41. t = multiprocessing.Process(target=create_vm, args=(vmname1,))
  42. t.start()
  43. create_vm(vmname2)
  44. t.join()
  45. qc = qubes.qubes.QubesVmCollection()
  46. qc.lock_db_for_reading()
  47. qc.load()
  48. qc.unlock_db()
  49. self.assertIsNotNone(qc.get_vm_by_name(vmname1))
  50. self.assertIsNotNone(qc.get_vm_by_name(vmname2))