1
0

test_disk.py 2.8 KB

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