1
0

test_disk.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import os
  4. import shutil
  5. import pytest
  6. import salt.utils.platform
  7. from salt.ext import six
  8. from tests.support.case import ModuleCase
  9. from tests.support.unit import skipIf
  10. @pytest.mark.destructive_test
  11. @pytest.mark.windows_whitelisted
  12. @skipIf(salt.utils.platform.is_darwin(), "No mtab on Darwin")
  13. @skipIf(salt.utils.platform.is_freebsd(), "No mtab on FreeBSD")
  14. @skipIf(salt.utils.platform.is_windows(), "No mtab on Windows")
  15. class DiskModuleVirtualizationTest(ModuleCase):
  16. """
  17. Test to make sure we return a clean result under Docker. Refs #8976
  18. This is factored into its own class so that we can have some certainty that setUp() and tearDown() are run.
  19. """
  20. def setUp(self):
  21. # Make /etc/mtab unreadable
  22. if os.path.isfile("/etc/mtab"):
  23. shutil.move("/etc/mtab", "/tmp/mtab")
  24. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  25. def test_no_mtab(self):
  26. ret = self.run_function("disk.usage")
  27. self.assertDictEqual(ret, {})
  28. def tearDown(self):
  29. if os.path.isfile("/tmp/mtab"):
  30. shutil.move("/tmp/mtab", "/etc/mtab")
  31. @pytest.mark.windows_whitelisted
  32. class DiskModuleTest(ModuleCase):
  33. """
  34. Validate the disk module
  35. """
  36. @pytest.mark.slow_test(seconds=30) # Test takes >10 and <=30 seconds
  37. def test_usage(self):
  38. """
  39. disk.usage
  40. """
  41. ret = self.run_function("disk.usage")
  42. self.assertTrue(isinstance(ret, dict))
  43. if not isinstance(ret, dict):
  44. return
  45. if salt.utils.platform.is_darwin():
  46. for key, val in six.iteritems(ret):
  47. self.assertTrue("filesystem" in val)
  48. self.assertTrue("512-blocks" in val)
  49. self.assertTrue("used" in val)
  50. self.assertTrue("available" in val)
  51. self.assertTrue("capacity" in val)
  52. self.assertTrue("iused" in val)
  53. self.assertTrue("ifree" in val)
  54. self.assertTrue("%iused" in val)
  55. else:
  56. for key, val in six.iteritems(ret):
  57. self.assertTrue("filesystem" in val)
  58. self.assertTrue("1K-blocks" in val)
  59. self.assertTrue("used" in val)
  60. self.assertTrue("available" in val)
  61. self.assertTrue("capacity" in val)
  62. @skipIf(salt.utils.platform.is_windows(), "inode info not available on Windows")
  63. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  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)