1
0

test_ansiblegate.py 2.8 KB

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