test_hadoop.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Rupesh Tare <rupesht@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.hadoop as hadoop
  16. class HadoopTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.modules.hadoop
  19. '''
  20. def setup_loader_modules(self):
  21. return {hadoop: {}}
  22. def test_version(self):
  23. '''
  24. Test for Return version from hadoop version
  25. '''
  26. mock = MagicMock(return_value="A \nB \n")
  27. with patch.dict(hadoop.__salt__, {'cmd.run': mock}):
  28. self.assertEqual(hadoop.version(), 'B')
  29. def test_dfs(self):
  30. '''
  31. Test for Execute a command on DFS
  32. '''
  33. with patch.object(hadoop, '_hadoop_cmd', return_value='A'):
  34. self.assertEqual(hadoop.dfs('command'), 'A')
  35. self.assertEqual(hadoop.dfs(), 'Error: command must be provided')
  36. def test_dfs_present(self):
  37. '''
  38. Test for Check if a file or directory is present on the distributed FS.
  39. '''
  40. with patch.object(hadoop, '_hadoop_cmd',
  41. side_effect=['No such file or directory', 'A']):
  42. self.assertFalse(hadoop.dfs_present('path'))
  43. self.assertTrue(hadoop.dfs_present('path'))
  44. def test_dfs_absent(self):
  45. '''
  46. Test for Check if a file or directory is absent on the distributed FS.
  47. '''
  48. with patch.object(hadoop, '_hadoop_cmd',
  49. side_effect=['No such file or directory', 'A']):
  50. self.assertTrue(hadoop.dfs_absent('path'))
  51. self.assertFalse(hadoop.dfs_absent('path'))
  52. def test_namenode_format(self):
  53. '''
  54. Test for Format a name node
  55. '''
  56. with patch.object(hadoop, '_hadoop_cmd', return_value='A'):
  57. self.assertEqual(hadoop.namenode_format('force'), 'A')