test_riak.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.modules.riak as riak
  9. # Import Salt Testing Libs
  10. from tests.support.mixins import LoaderModuleMockMixin
  11. from tests.support.mock import patch
  12. from tests.support.unit import TestCase
  13. class RiakTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Test cases for salt.modules.riak
  16. """
  17. def setup_loader_modules(self):
  18. return {riak: {}}
  19. def test_start(self):
  20. """
  21. Test for start Riak
  22. """
  23. with patch.object(
  24. riak, "__execute_cmd", return_value={"retcode": 0, "stdout": "success"}
  25. ):
  26. self.assertEqual(riak.start(), {"success": True, "comment": "success"})
  27. def test_stop(self):
  28. """
  29. Test for stop Riak
  30. """
  31. with patch.object(
  32. riak, "__execute_cmd", return_value={"retcode": 0, "stdout": "success"}
  33. ):
  34. self.assertEqual(riak.stop(), {"success": True, "comment": "success"})
  35. def test_cluster_join(self):
  36. """
  37. Test for Join a Riak cluster
  38. """
  39. with patch.object(
  40. riak, "__execute_cmd", return_value={"retcode": 0, "stdout": "success"}
  41. ):
  42. self.assertEqual(
  43. riak.cluster_join("A", "B"), {"success": True, "comment": "success"}
  44. )
  45. def test_cluster_leave(self):
  46. """
  47. Test for leaving a Riak cluster
  48. """
  49. with patch.object(
  50. riak, "__execute_cmd", return_value={"retcode": 0, "stdout": "success"}
  51. ):
  52. self.assertEqual(
  53. riak.cluster_leave("A", "B"), {"success": True, "comment": "success"}
  54. )
  55. def test_cluster_plan(self):
  56. """
  57. Test for Review Cluster Plan
  58. """
  59. with patch.object(
  60. riak, "__execute_cmd", return_value={"retcode": 0, "stdout": "success"}
  61. ):
  62. self.assertTrue(riak.cluster_plan())
  63. def test_cluster_commit(self):
  64. """
  65. Test for Commit Cluster Changes
  66. """
  67. with patch.object(
  68. riak, "__execute_cmd", return_value={"retcode": 0, "stdout": "success"}
  69. ):
  70. self.assertEqual(
  71. riak.cluster_commit(), {"success": True, "comment": "success"}
  72. )
  73. def test_member_status(self):
  74. """
  75. Test for Get cluster member status
  76. """
  77. with patch.object(
  78. riak, "__execute_cmd", return_value={"stdout": "A:a/B:b\nC:c/D:d"}
  79. ):
  80. self.assertDictEqual(
  81. riak.member_status(),
  82. {
  83. "membership": {},
  84. "summary": {
  85. "A": "a",
  86. "C": "c",
  87. "B": "b",
  88. "D": "d",
  89. "Exiting": 0,
  90. "Down": 0,
  91. "Valid": 0,
  92. "Leaving": 0,
  93. "Joining": 0,
  94. },
  95. },
  96. )
  97. def test_status(self):
  98. """
  99. Test status information
  100. """
  101. ret = {"stdout": "vnode_map_update_time_95 : 0\nvnode_map_update_time_99 : 0"}
  102. with patch.object(riak, "__execute_cmd", return_value=ret):
  103. self.assertEqual(
  104. riak.status(),
  105. {"vnode_map_update_time_95": "0", "vnode_map_update_time_99": "0"},
  106. )
  107. def test_test(self):
  108. """
  109. Test the Riak test
  110. """
  111. with patch.object(
  112. riak, "__execute_cmd", return_value={"retcode": 0, "stdout": "success"}
  113. ):
  114. self.assertEqual(riak.test(), {"success": True, "comment": "success"})
  115. def test_services(self):
  116. """
  117. Test Riak Service List
  118. """
  119. with patch.object(riak, "__execute_cmd", return_value={"stdout": "[a,b,c]"}):
  120. self.assertEqual(riak.services(), ["a", "b", "c"])