test_ansiblegate.py 2.7 KB

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