1
0

test_ansiblegate.py 2.5 KB

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