test_install.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the spm install 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. import salt.utils.yaml
  12. from tests.support.case import SPMCase
  13. from tests.support.helpers import Webserver, destructiveTest, slowTest
  14. @destructiveTest
  15. @pytest.mark.windows_whitelisted
  16. class SPMInstallTest(SPMCase):
  17. """
  18. Validate the spm install command
  19. """
  20. def setUp(self):
  21. self.config = self._spm_config()
  22. self._spm_build_files(self.config)
  23. self.spm_build_dir = self.config["spm_build_dir"]
  24. if "http" in self.id():
  25. # only start the webserver when testing http
  26. self.webserver = Webserver()
  27. self.webserver.root = self.spm_build_dir
  28. self.webserver.start()
  29. self.repo_dir = self.config["spm_repos_config"] + ".d"
  30. self.repo = os.path.join(self.repo_dir, "spm.repo")
  31. url = {"my_repo": {"url": self.webserver.url("")[:-1]}}
  32. if not os.path.exists(self.repo_dir):
  33. os.makedirs(self.repo_dir)
  34. with salt.utils.files.fopen(self.repo, "w") as fp:
  35. salt.utils.yaml.safe_dump(url, fp)
  36. def test_spm_install_http(self):
  37. """
  38. test spm install using http repo
  39. """
  40. build_spm = self.run_spm("build", self.config, self.formula_dir)
  41. spm_file = os.path.join(self.spm_build_dir, "apache-201506-2.spm")
  42. create_repo = self.run_spm("create_repo", self.config, self.spm_build_dir)
  43. for root, dirs, files in salt.utils.path.os_walk(self.spm_build_dir):
  44. for fp in files:
  45. self.webserver.url(fp)
  46. install = self.run_spm("install", self.config, "apache")
  47. sls = os.path.join(self.config["formula_path"], "apache", "apache.sls")
  48. self.assertTrue(os.path.exists(sls))
  49. @slowTest
  50. def test_spm_install_local_dir(self):
  51. """
  52. test spm install from local directory
  53. """
  54. build_spm = self.run_spm("build", self.config, self.formula_dir)
  55. spm_file = os.path.join(self.config["spm_build_dir"], "apache-201506-2.spm")
  56. install = self.run_spm("install", self.config, spm_file)
  57. sls = os.path.join(self.config["formula_path"], "apache", "apache.sls")
  58. self.assertTrue(os.path.exists(sls))
  59. @slowTest
  60. def test_spm_install_from_repo(self):
  61. """
  62. test spm install from repo
  63. """
  64. self._spm_create_update_repo(self.config)
  65. install = self.run_spm("install", self.config, "apache")
  66. sls = os.path.join(self.config["formula_path"], "apache", "apache.sls")
  67. self.assertTrue(os.path.exists(sls))
  68. def tearDown(self):
  69. if "http" in self.id():
  70. self.webserver.stop()
  71. shutil.rmtree(self._tmp_spm)