regressions.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 time
  26. import unittest
  27. import qubes.qubes
  28. import qubes.tests
  29. class TC_00_Regressions(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
  30. # Bug: #906
  31. def test_000_bug_906_db_locking(self):
  32. def create_vm(vmname):
  33. qc = qubes.qubes.QubesVmCollection()
  34. qc.lock_db_for_writing()
  35. qc.load()
  36. time.sleep(1)
  37. qc.add_new_vm('QubesAppVm',
  38. name=vmname, template=qc.get_default_template())
  39. qc.save()
  40. qc.unlock_db()
  41. vmname1, vmname2 = map(self.make_vm_name, ('test1', 'test2'))
  42. t = multiprocessing.Process(target=create_vm, args=(vmname1,))
  43. t.start()
  44. create_vm(vmname2)
  45. t.join()
  46. qc = qubes.qubes.QubesVmCollection()
  47. qc.lock_db_for_reading()
  48. qc.load()
  49. qc.unlock_db()
  50. self.assertIsNotNone(qc.get_vm_by_name(vmname1))
  51. self.assertIsNotNone(qc.get_vm_by_name(vmname2))