1
0

test_thin.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. import tarfile
  4. import tempfile
  5. import subprocess
  6. import sys
  7. import os
  8. from tests.support.unit import TestCase
  9. import salt.utils.files
  10. import salt.utils.thin
  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)