test_ansiblegate.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. Test AnsibleGate State Module
  3. """
  4. import os
  5. import shutil
  6. import tempfile
  7. import pytest
  8. import salt.utils.files
  9. import salt.utils.path
  10. import yaml
  11. from tests.support.case import ModuleCase
  12. from tests.support.helpers import destructiveTest, flaky, requires_system_grains
  13. from tests.support.mixins import SaltReturnAssertsMixin
  14. from tests.support.runtests import RUNTIME_VARS
  15. from tests.support.unit import SkipTest, skipIf
  16. @destructiveTest
  17. @pytest.mark.requires_sshd_server
  18. @skipIf(
  19. not salt.utils.path.which("ansible-playbook"), "ansible-playbook is not installed"
  20. )
  21. class AnsiblePlaybooksTestCase(ModuleCase, SaltReturnAssertsMixin):
  22. """
  23. Test ansible.playbooks states
  24. """
  25. @classmethod
  26. @requires_system_grains
  27. def setUpClass(cls, grains=None): # pylint: disable=arguments-differ
  28. if grains.get("os_family") == "RedHat" and grains.get("osmajorrelease") == 6:
  29. raise SkipTest(
  30. "This test hangs the test suite on RedHat 6. Skipping for now."
  31. )
  32. def setUp(self):
  33. priv_file = os.path.join(RUNTIME_VARS.TMP_SSH_CONF_DIR, "client_key")
  34. data = {
  35. "all": {
  36. "hosts": {
  37. "localhost": {
  38. "ansible_host": "127.0.0.1",
  39. "ansible_port": 2827,
  40. "ansible_user": RUNTIME_VARS.RUNNING_TESTS_USER,
  41. "ansible_ssh_private_key_file": priv_file,
  42. "ansible_ssh_extra_args": (
  43. "-o StrictHostKeyChecking=false "
  44. "-o UserKnownHostsFile=/dev/null "
  45. ),
  46. },
  47. },
  48. },
  49. }
  50. self.tempdir = tempfile.mkdtemp()
  51. self.inventory = self.tempdir + "inventory"
  52. with salt.utils.files.fopen(self.inventory, "w") as yaml_file:
  53. yaml.dump(data, yaml_file, default_flow_style=False)
  54. def tearDown(self):
  55. shutil.rmtree(self.tempdir)
  56. delattr(self, "tempdir")
  57. delattr(self, "inventory")
  58. @flaky
  59. def test_ansible_playbook(self):
  60. ret = self.run_state(
  61. "ansible.playbooks",
  62. name="remove.yml",
  63. git_repo="git://github.com/gtmanfred/playbooks.git",
  64. ansible_kwargs={"inventory": self.inventory},
  65. )
  66. self.assertSaltTrueReturn(ret)
  67. ret = self.run_state(
  68. "ansible.playbooks",
  69. name="install.yml",
  70. git_repo="git://github.com/gtmanfred/playbooks.git",
  71. ansible_kwargs={"inventory": self.inventory},
  72. )
  73. self.assertSaltTrueReturn(ret)