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!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 line
2.0KB

  1. import pytest
  2. from focker.image import validate_spec, \
  3. build_squeeze
  4. import subprocess
  5. from tempfile import TemporaryDirectory
  6. import focker.image
  7. import os
  8. from focker.zfs import zfs_find, \
  9. zfs_mountpoint
  10. from focker.misc import focker_unlock
  11. def test_validate_spec_01():
  12. spec = { 'base': 'base', 'steps': 'steps' }
  13. validate_spec(spec)
  14. def test_validate_spec_02():
  15. spec = { 'steps': 'steps' }
  16. with pytest.raises(ValueError):
  17. validate_spec(spec)
  18. def test_validate_spec_03():
  19. spec = { 'base': 'base' }
  20. with pytest.raises(ValueError):
  21. validate_spec(spec)
  22. def test_validate_spec_04():
  23. spec = {}
  24. with pytest.raises(ValueError):
  25. validate_spec(spec)
  26. def test_build_squeeze(monkeypatch):
  27. focker_unlock()
  28. subprocess.check_output(['focker', 'image', 'remove', '--force', '-R', 'test-build-squeeze-base'])
  29. subprocess.check_output(['focker', 'bootstrap', '--dry-run', '-t', 'test-build-squeeze-base'])
  30. spec = dict(base='test-build-squeeze-base', steps=[
  31. dict(copy=['/etc/localtime', '/etc/localtime']),
  32. dict(copy=['/etc/hosts', '/etc/hosts'])
  33. ])
  34. _, base_sha256 = zfs_find('test-build-squeeze-base', focker_type='image')
  35. def fail(sha256, *args, **kwargs):
  36. if sha256 != base_sha256:
  37. raise RuntimeError('No pre-existing layers expected apart from base')
  38. monkeypatch.setattr(focker.image, 'zfs_snapshot_by_sha256', fail)
  39. with TemporaryDirectory() as d:
  40. args = lambda: 0
  41. args.focker_dir = d
  42. name, _ = build_squeeze(spec, args)
  43. focker_unlock()
  44. mountpoint = zfs_mountpoint(name.split('@')[0])
  45. print('name:', name, 'mountpoint:', mountpoint)
  46. assert os.path.exists(os.path.join(mountpoint, 'etc/localtime'))
  47. assert os.path.exists(os.path.join(mountpoint, 'etc/hosts'))
  48. subprocess.check_output(['focker', 'image', 'remove', '-R', 'test-build-squeeze-base'])
  49. assert not os.path.exists(mountpoint)