IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

68 řádky
2.5KB

  1. from focker.jail import backup_file, \
  2. jail_fs_create
  3. import tempfile
  4. import os
  5. import subprocess
  6. from focker.zfs import zfs_mountpoint, \
  7. zfs_exists, \
  8. zfs_tag
  9. def test_backup_file():
  10. with tempfile.TemporaryDirectory() as d:
  11. fname = os.path.join(d, 'dummy.conf')
  12. with open(fname, 'w') as f:
  13. f.write('init')
  14. nbackups = 10
  15. for i in range(15):
  16. backup_file(fname, nbackups=nbackups, chmod=0o640)
  17. with open(fname, 'w') as f:
  18. f.write(str(i))
  19. fname = os.path.join(d, 'dummy.conf')
  20. with open(fname, 'r') as f:
  21. assert f.read() == '14'
  22. for i in range(nbackups):
  23. fname = os.path.join(d, 'dummy.conf.%d' % i)
  24. assert os.path.exists(fname)
  25. with open(fname, 'r') as f:
  26. if i < 5:
  27. assert f.read() == str(i + 9)
  28. else:
  29. assert f.read() == str(i - 1)
  30. def test_jail_fs_create_01():
  31. subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-jail-fs-create-01'])
  32. subprocess.check_output(['focker', 'bootstrap', '--empty', '-t', 'test-jail-fs-create-01'])
  33. name = jail_fs_create('test-jail-fs-create-01')
  34. assert zfs_exists(name)
  35. mountpoint = zfs_mountpoint(name)
  36. assert os.path.exists(mountpoint)
  37. with open(os.path.join(mountpoint, 'test.txt'), 'w') as f:
  38. f.write('test\n')
  39. assert os.path.exists(os.path.join(mountpoint, 'test.txt'))
  40. with open(os.path.join(mountpoint, 'test.txt'), 'r') as f:
  41. assert f.read() == 'test\n'
  42. subprocess.check_output(['focker', 'image', 'remove', '-R', 'test-jail-fs-create-01'])
  43. assert not zfs_exists(name)
  44. assert not os.path.exists(mountpoint)
  45. def test_jail_fs_create_02():
  46. subprocess.check_output(['focker', 'jail', 'remove', '--force', 'test-jail-fs-create-02'])
  47. name = jail_fs_create()
  48. zfs_tag(name, ['test-jail-fs-create-02'])
  49. assert zfs_exists(name)
  50. mountpoint = zfs_mountpoint(name)
  51. assert os.path.exists(mountpoint)
  52. with open(os.path.join(mountpoint, 'test.txt'), 'w') as f:
  53. f.write('test\n')
  54. assert os.path.exists(os.path.join(mountpoint, 'test.txt'))
  55. with open(os.path.join(mountpoint, 'test.txt'), 'r') as f:
  56. assert f.read() == 'test\n'
  57. subprocess.check_output(['focker', 'jail', 'remove', 'test-jail-fs-create-02'])
  58. assert not zfs_exists(name)
  59. assert not os.path.exists(mountpoint)