test_drbd.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. )
  14. # Import Salt Libs
  15. import salt.modules.drbd as drbd
  16. class DrbdTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.modules.drbd
  19. '''
  20. def setup_loader_modules(self):
  21. return {drbd: {}}
  22. # 'overview' function tests: 1
  23. def test_overview(self):
  24. '''
  25. Test if it shows status of the DRBD devices
  26. '''
  27. ret = {'connection state': 'True',
  28. 'device': 'Stack',
  29. 'fs': 'None',
  30. 'local disk state': 'UpToDate',
  31. 'local role': 'master',
  32. 'minor number': 'Salt',
  33. 'mountpoint': 'True',
  34. 'partner disk state': 'UpToDate',
  35. 'partner role': 'minion',
  36. 'percent': '888',
  37. 'remains': '666',
  38. 'total size': '50',
  39. 'used': '50'}
  40. mock = MagicMock(return_value='Salt:Stack True master/minion \
  41. UpToDate/UpToDate True None 50 50 666 888')
  42. with patch.dict(drbd.__salt__, {'cmd.run': mock}):
  43. self.assertDictEqual(drbd.overview(), ret)
  44. ret = {'connection state': 'True',
  45. 'device': 'Stack',
  46. 'local disk state': 'UpToDate',
  47. 'local role': 'master',
  48. 'minor number': 'Salt',
  49. 'partner disk state': 'partner',
  50. 'partner role': 'minion',
  51. 'synched': '5050',
  52. 'synchronisation: ': 'syncbar'}
  53. mock = MagicMock(return_value='Salt:Stack True master/minion \
  54. UpToDate/partner syncbar None 50 50')
  55. with patch.dict(drbd.__salt__, {'cmd.run': mock}):
  56. self.assertDictEqual(drbd.overview(), ret)