test_build.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Tests for the spm build utility
  4. '''
  5. # Import python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import os
  8. import shutil
  9. import pytest
  10. # Import Salt libs
  11. import salt.utils.files
  12. import salt.utils.path
  13. # Import Salt Testing libs
  14. from tests.support.case import SPMCase, ModuleCase
  15. from tests.support.unit import skipIf
  16. @pytest.mark.destructive_test
  17. class SPMBuildTest(SPMCase, ModuleCase):
  18. '''
  19. Validate the spm build command
  20. '''
  21. def setUp(self):
  22. self.config = self._spm_config()
  23. self._spm_build_files(self.config)
  24. def test_spm_build(self):
  25. '''
  26. test spm build
  27. '''
  28. self.run_spm('build', self.config, self.formula_dir)
  29. spm_file = os.path.join(self.config['spm_build_dir'], 'apache-201506-2.spm')
  30. # Make sure .spm file gets created
  31. self.assertTrue(os.path.exists(spm_file))
  32. # Make sure formula path dir is created
  33. self.assertTrue(os.path.isdir(self.config['formula_path']))
  34. @skipIf(salt.utils.path.which('fallocate') is None, 'fallocate not installed')
  35. def test_spm_build_big_file(self):
  36. '''
  37. test spm build with a big file
  38. '''
  39. # check to make sure there is enough space to run this test
  40. check_space = self.run_function('status.diskusage', ['/tmp'])
  41. space = check_space['/tmp']['available']
  42. if space < 3000000000:
  43. self.skipTest('Not enough space on host to run this test')
  44. self.run_function('cmd.run',
  45. ['fallocate -l 1G {0}'.format(os.path.join(self.formula_sls_dir,
  46. 'bigfile.txt'))])
  47. self.run_spm('build', self.config, self.formula_dir)
  48. spm_file = os.path.join(self.config['spm_build_dir'], 'apache-201506-2.spm')
  49. self.run_spm('install', self.config, spm_file)
  50. get_files = self.run_spm('files', self.config, 'apache')
  51. files = ['apache.sls', 'bigfile.txt']
  52. for sls in files:
  53. self.assertIn(sls, ' '.join(get_files))
  54. def test_spm_build_exclude(self):
  55. '''
  56. test spm build while excluding directory
  57. '''
  58. git_dir = os.path.join(self.formula_sls_dir, '.git')
  59. os.makedirs(git_dir)
  60. files = ['donotbuild1', 'donotbuild2', 'donotbuild3']
  61. for git_file in files:
  62. with salt.utils.files.fopen(os.path.join(git_dir, git_file), 'w') as fp:
  63. fp.write('Please do not include me in build')
  64. self.run_spm('build', self.config, self.formula_dir)
  65. spm_file = os.path.join(self.config['spm_build_dir'], 'apache-201506-2.spm')
  66. self.run_spm('install', self.config, spm_file)
  67. get_files = self.run_spm('files', self.config, 'apache')
  68. for git_file in files:
  69. self.assertNotIn(git_file, ' '.join(get_files))
  70. def tearDown(self):
  71. shutil.rmtree(self._tmp_spm)