test_disk.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. import shutil
  6. # Import Salt Testing libs
  7. from tests.support.case import ModuleCase
  8. from tests.support.unit import skipIf
  9. from tests.support.helpers import destructiveTest
  10. # Import Salt libs
  11. import salt.utils.platform
  12. # Import 3rd-party libs
  13. from salt.ext import six
  14. @destructiveTest
  15. @skipIf(salt.utils.platform.is_windows(), 'No mtab on Windows')
  16. @skipIf(salt.utils.platform.is_darwin(), 'No mtab on Darwin')
  17. class DiskModuleVirtualizationTest(ModuleCase):
  18. '''
  19. Test to make sure we return a clean result under Docker. Refs #8976
  20. This is factored into its own class so that we can have some certainty that setUp() and tearDown() are run.
  21. '''
  22. def setUp(self):
  23. # Make /etc/mtab unreadable
  24. if os.path.isfile('/etc/mtab'):
  25. shutil.move('/etc/mtab', '/tmp/mtab')
  26. def test_no_mtab(self):
  27. ret = self.run_function('disk.usage')
  28. self.assertDictEqual(ret, {})
  29. def tearDown(self):
  30. if os.path.isfile('/tmp/mtab'):
  31. shutil.move('/tmp/mtab', '/etc/mtab')
  32. class DiskModuleTest(ModuleCase):
  33. '''
  34. Validate the disk module
  35. '''
  36. def test_usage(self):
  37. '''
  38. disk.usage
  39. '''
  40. ret = self.run_function('disk.usage')
  41. self.assertTrue(isinstance(ret, dict))
  42. if not isinstance(ret, dict):
  43. return
  44. if salt.utils.platform.is_darwin():
  45. for key, val in six.iteritems(ret):
  46. self.assertTrue('filesystem' in val)
  47. self.assertTrue('512-blocks' in val)
  48. self.assertTrue('used' in val)
  49. self.assertTrue('available' in val)
  50. self.assertTrue('capacity' in val)
  51. self.assertTrue('iused' in val)
  52. self.assertTrue('ifree' in val)
  53. self.assertTrue('%iused' in val)
  54. else:
  55. for key, val in six.iteritems(ret):
  56. self.assertTrue('filesystem' in val)
  57. self.assertTrue('1K-blocks' in val)
  58. self.assertTrue('used' in val)
  59. self.assertTrue('available' in val)
  60. self.assertTrue('capacity' in val)
  61. @skipIf(salt.utils.platform.is_windows(), 'inode info not available on Windows')
  62. def test_inodeusage(self):
  63. '''
  64. disk.inodeusage
  65. '''
  66. ret = self.run_function('disk.inodeusage')
  67. self.assertTrue(isinstance(ret, dict))
  68. if not isinstance(ret, dict):
  69. return
  70. for key, val in six.iteritems(ret):
  71. self.assertTrue('inodes' in val)
  72. self.assertTrue('used' in val)
  73. self.assertTrue('free' in val)
  74. self.assertTrue('use' in val)
  75. self.assertTrue('filesystem' in val)