test_modjk_worker.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  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. # Import Salt Libs
  14. import salt.states.modjk_worker as modjk_worker
  15. class ModjkWorkerTestCase(TestCase, LoaderModuleMockMixin):
  16. '''
  17. Test cases for salt.states.modjk_worker
  18. '''
  19. def setup_loader_modules(self):
  20. return {modjk_worker: {}}
  21. # 'stop' function tests: 1
  22. def test_stop(self):
  23. '''
  24. Test to stop the named worker from the lbn load balancers
  25. at the targeted minions.
  26. '''
  27. name = "{{ grains['id'] }}"
  28. lbn = 'application'
  29. target = 'roles:balancer'
  30. ret = {'name': name,
  31. 'result': False,
  32. 'comment': '',
  33. 'changes': {}}
  34. comt = 'no servers answered the published command modjk.worker_status'
  35. mock = MagicMock(return_value=False)
  36. with patch.dict(modjk_worker.__salt__, {'publish.publish': mock}):
  37. ret.update({'comment': comt})
  38. self.assertDictEqual(modjk_worker.stop(name, lbn, target), ret)
  39. # 'activate' function tests: 1
  40. def test_activate(self):
  41. '''
  42. Test to activate the named worker from the lbn load balancers
  43. at the targeted minions.
  44. '''
  45. name = "{{ grains['id'] }}"
  46. lbn = 'application'
  47. target = 'roles:balancer'
  48. ret = {'name': name,
  49. 'result': False,
  50. 'comment': '',
  51. 'changes': {}}
  52. comt = 'no servers answered the published command modjk.worker_status'
  53. mock = MagicMock(return_value=False)
  54. with patch.dict(modjk_worker.__salt__, {'publish.publish': mock}):
  55. ret.update({'comment': comt})
  56. self.assertDictEqual(modjk_worker.activate(name, lbn, target), ret)
  57. # 'disable' function tests: 1
  58. def test_disable(self):
  59. '''
  60. Test to disable the named worker from the lbn load balancers
  61. at the targeted minions.
  62. '''
  63. name = "{{ grains['id'] }}"
  64. lbn = 'application'
  65. target = 'roles:balancer'
  66. ret = {'name': name,
  67. 'result': False,
  68. 'comment': '',
  69. 'changes': {}}
  70. comt = 'no servers answered the published command modjk.worker_status'
  71. mock = MagicMock(return_value=False)
  72. with patch.dict(modjk_worker.__salt__, {'publish.publish': mock}):
  73. ret.update({'comment': comt})
  74. self.assertDictEqual(modjk_worker.disable(name, lbn, target), ret)