1
0

test_supervisord.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch
  13. )
  14. # Import Salt Libs
  15. import salt.states.supervisord as supervisord
  16. class SupervisordTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.states.supervisord
  19. '''
  20. def setup_loader_modules(self):
  21. return {supervisord: {}}
  22. # 'running' function tests: 1
  23. def test_running(self):
  24. '''
  25. Test to ensure the named service is running.
  26. '''
  27. name = 'wsgi_server'
  28. ret = {'name': name,
  29. 'changes': {},
  30. 'result': True,
  31. 'comment': ''}
  32. comt = ('Supervisord module not activated.'
  33. ' Do you need to install supervisord?')
  34. ret.update({'comment': comt, 'result': False})
  35. self.assertDictEqual(supervisord.running(name), ret)
  36. mock = MagicMock(return_value={name: {'state': 'running'}})
  37. with patch.dict(supervisord.__salt__, {'supervisord.status': mock}):
  38. with patch.dict(supervisord.__opts__, {'test': True}):
  39. comt = ('Service wsgi_server is already running')
  40. ret.update({'comment': comt, 'result': True})
  41. self.assertDictEqual(supervisord.running(name), ret)
  42. with patch.dict(supervisord.__opts__, {'test': False}):
  43. comt = ('Not starting already running service: wsgi_server')
  44. ret.update({'comment': comt})
  45. self.assertDictEqual(supervisord.running(name), ret)
  46. # 'dead' function tests: 1
  47. def test_dead(self):
  48. '''
  49. Test to ensure the named service is dead (not running).
  50. '''
  51. name = 'wsgi_server'
  52. ret = {'name': name,
  53. 'changes': {},
  54. 'result': None,
  55. 'comment': ''}
  56. with patch.dict(supervisord.__opts__, {'test': True}):
  57. comt = ('Service {0} is set to be stopped'.format(name))
  58. ret.update({'comment': comt})
  59. self.assertDictEqual(supervisord.dead(name), ret)
  60. # 'mod_watch' function tests: 1
  61. def test_mod_watch(self):
  62. '''
  63. Test to always restart on watch.
  64. '''
  65. name = 'wsgi_server'
  66. ret = {'name': name,
  67. 'changes': {},
  68. 'result': None,
  69. 'comment': ''}
  70. comt = ('Supervisord module not activated.'
  71. ' Do you need to install supervisord?')
  72. ret.update({'comment': comt, 'result': False})
  73. self.assertDictEqual(supervisord.mod_watch(name), ret)