test_rabbitmq_cluster.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Rahul Handay <rahulha@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.rabbitmq_cluster as rabbitmq_cluster
  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 RabbitmqClusterTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Validate the rabbitmq_cluster state
  16. """
  17. def setup_loader_modules(self):
  18. return {rabbitmq_cluster: {}}
  19. def test_joined(self):
  20. """
  21. Test to ensure the current node joined
  22. to a cluster with node user@host
  23. """
  24. ret = {"name": "salt", "changes": {}, "result": True, "comment": ""}
  25. mock = MagicMock(side_effect=[["rahulha@salt"], [""], [""]])
  26. with patch.dict(rabbitmq_cluster.__salt__, {"rabbitmq.cluster_status": mock}):
  27. ret.update({"comment": "Already in cluster"})
  28. self.assertDictEqual(
  29. rabbitmq_cluster.joined("salt", "salt", "rahulha"), ret
  30. )
  31. with patch.dict(rabbitmq_cluster.__opts__, {"test": True}):
  32. ret.update(
  33. {
  34. "result": None,
  35. "comment": "Node is set to join " "cluster rahulha@salt",
  36. "changes": {"new": "rahulha@salt", "old": ""},
  37. }
  38. )
  39. self.assertDictEqual(
  40. rabbitmq_cluster.joined("salt", "salt", "rahulha"), ret
  41. )
  42. with patch.dict(rabbitmq_cluster.__opts__, {"test": False}):
  43. mock = MagicMock(return_value={"Error": "ERR"})
  44. with patch.dict(
  45. rabbitmq_cluster.__salt__, {"rabbitmq.join_cluster": mock}
  46. ):
  47. ret.update({"result": False, "comment": "ERR", "changes": {}})
  48. self.assertDictEqual(
  49. rabbitmq_cluster.joined("salt", "salt", "rahulha"), ret
  50. )