test_ansiblegate.py 2.7 KB

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