test_ansiblegate.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Test AnsibleGate State Module
  4. '''
  5. from __future__ import absolute_import, unicode_literals, print_function
  6. # Import python libraries
  7. import os
  8. import shutil
  9. import tempfile
  10. import yaml
  11. import pytest
  12. # Import salt libraries
  13. import salt.utils.files
  14. import salt.utils.path
  15. # Import testing libraries
  16. from tests.support.case import ModuleCase
  17. from tests.support.helpers import (
  18. requires_sshd_server,
  19. flaky
  20. )
  21. from tests.support.mixins import SaltReturnAssertsMixin
  22. from tests.support.runtests import RUNTIME_VARS
  23. @pytest.mark.destructive_test
  24. @requires_sshd_server
  25. @pytest.mark.skipif(not salt.utils.path.which('ansible-playbook'), reason='ansible-playbook is not installed')
  26. @pytest.mark.skipif("grains['os_family'] == 'RedHat' and grains.get('osmajorrelease') == 6",
  27. reason='This test hangs the test suite on RedHat 6. Skipping for now.')
  28. class AnsiblePlaybooksTestCase(ModuleCase, SaltReturnAssertsMixin):
  29. '''
  30. Test ansible.playbooks states
  31. '''
  32. def setUp(self):
  33. priv_file = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'key_test')
  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)