1
0

test_build.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Salt libs
  10. import salt.utils.files
  11. import salt.utils.path
  12. # Import Salt Testing libs
  13. from tests.support.case import SPMCase, ModuleCase
  14. from tests.support.helpers import destructiveTest
  15. from tests.support.unit import skipIf
  16. @destructiveTest
  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)