1
0

test_build.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the spm build utility
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os
  7. import shutil
  8. import pytest
  9. import salt.utils.files
  10. import salt.utils.path
  11. from tests.support.case import ModuleCase, SPMCase
  12. from tests.support.unit import skipIf
  13. @pytest.mark.destructive_test
  14. @pytest.mark.windows_whitelisted
  15. class SPMBuildTest(SPMCase, ModuleCase):
  16. """
  17. Validate the spm build command
  18. """
  19. def setUp(self):
  20. self.config = self._spm_config()
  21. self._spm_build_files(self.config)
  22. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  23. def test_spm_build(self):
  24. """
  25. test spm build
  26. """
  27. self.run_spm("build", self.config, self.formula_dir)
  28. spm_file = os.path.join(self.config["spm_build_dir"], "apache-201506-2.spm")
  29. # Make sure .spm file gets created
  30. self.assertTrue(os.path.exists(spm_file))
  31. # Make sure formula path dir is created
  32. self.assertTrue(os.path.isdir(self.config["formula_path"]))
  33. @skipIf(salt.utils.path.which("fallocate") is None, "fallocate not installed")
  34. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  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(
  45. "cmd.run",
  46. [
  47. "fallocate -l 1G {0}".format(
  48. os.path.join(self.formula_sls_dir, "bigfile.txt")
  49. )
  50. ],
  51. )
  52. self.run_spm("build", self.config, self.formula_dir)
  53. spm_file = os.path.join(self.config["spm_build_dir"], "apache-201506-2.spm")
  54. self.run_spm("install", self.config, spm_file)
  55. get_files = self.run_spm("files", self.config, "apache")
  56. files = ["apache.sls", "bigfile.txt"]
  57. for sls in files:
  58. self.assertIn(sls, " ".join(get_files))
  59. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  60. def test_spm_build_exclude(self):
  61. """
  62. test spm build while excluding directory
  63. """
  64. git_dir = os.path.join(self.formula_sls_dir, ".git")
  65. os.makedirs(git_dir)
  66. files = ["donotbuild1", "donotbuild2", "donotbuild3"]
  67. for git_file in files:
  68. with salt.utils.files.fopen(os.path.join(git_dir, git_file), "w") as fp:
  69. fp.write("Please do not include me in build")
  70. self.run_spm("build", self.config, self.formula_dir)
  71. spm_file = os.path.join(self.config["spm_build_dir"], "apache-201506-2.spm")
  72. self.run_spm("install", self.config, spm_file)
  73. get_files = self.run_spm("files", self.config, "apache")
  74. for git_file in files:
  75. self.assertNotIn(git_file, " ".join(get_files))
  76. def tearDown(self):
  77. shutil.rmtree(self._tmp_spm)