1
0

test_thin.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. import os
  4. import subprocess
  5. import sys
  6. import tarfile
  7. import tempfile
  8. import salt.utils.files
  9. import salt.utils.thin
  10. from tests.support.unit import TestCase
  11. try:
  12. import virtualenv
  13. HAS_VENV = True
  14. except ImportError:
  15. HAS_VENV = False
  16. class TestThinDir(TestCase):
  17. def setUp(self):
  18. self.tmpdir = tempfile.mkdtemp()
  19. def tearDown(self):
  20. salt.utils.files.rm_rf(self.tmpdir)
  21. def test_thin_dir(self):
  22. """
  23. Test the thin dir to make sure salt-call can run
  24. Run salt call via a python in a new virtual environment to ensure
  25. salt-call has all dependencies needed.
  26. """
  27. venv_dir = os.path.join(self.tmpdir, "venv")
  28. virtualenv.create_environment(venv_dir)
  29. salt.utils.thin.gen_thin(self.tmpdir)
  30. thin_dir = os.path.join(self.tmpdir, "thin")
  31. thin_archive = os.path.join(thin_dir, "thin.tgz")
  32. tar = tarfile.open(thin_archive)
  33. tar.extractall(thin_dir)
  34. tar.close()
  35. bins = "bin"
  36. if sys.platform == "win32":
  37. bins = "Scripts"
  38. cmd = [
  39. os.path.join(venv_dir, bins, "python"),
  40. os.path.join(thin_dir, "salt-call"),
  41. "--version",
  42. ]
  43. proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  44. stdout, stderr = proc.communicate()
  45. proc.wait()
  46. assert proc.returncode == 0, (stdout, stderr, proc.returncode)