test_modjk_worker.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 Libs
  8. import salt.states.modjk_worker as modjk_worker
  9. # Import Salt Testing Libs
  10. from tests.support.mixins import LoaderModuleMockMixin
  11. from tests.support.mock import MagicMock, patch
  12. from tests.support.unit import TestCase
  13. class ModjkWorkerTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Test cases for salt.states.modjk_worker
  16. """
  17. def setup_loader_modules(self):
  18. return {modjk_worker: {}}
  19. # 'stop' function tests: 1
  20. def test_stop(self):
  21. """
  22. Test to stop the named worker from the lbn load balancers
  23. at the targeted minions.
  24. """
  25. name = "{{ grains['id'] }}"
  26. lbn = "application"
  27. target = "roles:balancer"
  28. ret = {"name": name, "result": False, "comment": "", "changes": {}}
  29. comt = "no servers answered the published command modjk.worker_status"
  30. mock = MagicMock(return_value=False)
  31. with patch.dict(modjk_worker.__salt__, {"publish.publish": mock}):
  32. ret.update({"comment": comt})
  33. self.assertDictEqual(modjk_worker.stop(name, lbn, target), ret)
  34. # 'activate' function tests: 1
  35. def test_activate(self):
  36. """
  37. Test to activate the named worker from the lbn load balancers
  38. at the targeted minions.
  39. """
  40. name = "{{ grains['id'] }}"
  41. lbn = "application"
  42. target = "roles:balancer"
  43. ret = {"name": name, "result": False, "comment": "", "changes": {}}
  44. comt = "no servers answered the published command modjk.worker_status"
  45. mock = MagicMock(return_value=False)
  46. with patch.dict(modjk_worker.__salt__, {"publish.publish": mock}):
  47. ret.update({"comment": comt})
  48. self.assertDictEqual(modjk_worker.activate(name, lbn, target), ret)
  49. # 'disable' function tests: 1
  50. def test_disable(self):
  51. """
  52. Test to disable the named worker from the lbn load balancers
  53. at the targeted minions.
  54. """
  55. name = "{{ grains['id'] }}"
  56. lbn = "application"
  57. target = "roles:balancer"
  58. ret = {"name": name, "result": False, "comment": "", "changes": {}}
  59. comt = "no servers answered the published command modjk.worker_status"
  60. mock = MagicMock(return_value=False)
  61. with patch.dict(modjk_worker.__salt__, {"publish.publish": mock}):
  62. ret.update({"comment": comt})
  63. self.assertDictEqual(modjk_worker.disable(name, lbn, target), ret)