test_riak.py 3.8 KB

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