etcd_volume_test.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import pytest
  2. from openshift_checks.etcd_volume import EtcdVolume, OpenShiftCheckException
  3. @pytest.mark.parametrize('ansible_mounts,extra_words', [
  4. ([], ['none']), # empty ansible_mounts
  5. ([{'mount': '/mnt'}], ['/mnt']), # missing relevant mount paths
  6. ])
  7. def test_cannot_determine_available_disk(ansible_mounts, extra_words):
  8. task_vars = dict(
  9. ansible_mounts=ansible_mounts,
  10. )
  11. with pytest.raises(OpenShiftCheckException) as excinfo:
  12. EtcdVolume(fake_execute_module, task_vars).run()
  13. for word in 'Unable to find etcd storage mount point'.split() + extra_words:
  14. assert word in str(excinfo.value)
  15. @pytest.mark.parametrize('size_limit,ansible_mounts', [
  16. (
  17. # if no size limit is specified, expect max usage
  18. # limit to default to 90% of size_total
  19. None,
  20. [{
  21. 'mount': '/',
  22. 'size_available': 40 * 10**9,
  23. 'size_total': 80 * 10**9
  24. }],
  25. ),
  26. (
  27. 1,
  28. [{
  29. 'mount': '/',
  30. 'size_available': 30 * 10**9,
  31. 'size_total': 30 * 10**9,
  32. }],
  33. ),
  34. (
  35. 20000000000,
  36. [{
  37. 'mount': '/',
  38. 'size_available': 20 * 10**9,
  39. 'size_total': 40 * 10**9,
  40. }],
  41. ),
  42. (
  43. 5000000000,
  44. [{
  45. # not enough space on / ...
  46. 'mount': '/',
  47. 'size_available': 0,
  48. 'size_total': 0,
  49. }, {
  50. # not enough space on /var/lib ...
  51. 'mount': '/var/lib',
  52. 'size_available': 2 * 10**9,
  53. 'size_total': 21 * 10**9,
  54. }, {
  55. # ... but enough on /var/lib/etcd
  56. 'mount': '/var/lib/etcd',
  57. 'size_available': 36 * 10**9,
  58. 'size_total': 40 * 10**9
  59. }],
  60. )
  61. ])
  62. def test_succeeds_with_recommended_disk_space(size_limit, ansible_mounts):
  63. task_vars = dict(
  64. etcd_device_usage_threshold_percent=size_limit,
  65. ansible_mounts=ansible_mounts,
  66. )
  67. if task_vars["etcd_device_usage_threshold_percent"] is None:
  68. task_vars.pop("etcd_device_usage_threshold_percent")
  69. result = EtcdVolume(fake_execute_module, task_vars).run()
  70. assert not result.get('failed', False)
  71. @pytest.mark.parametrize('size_limit_percent,ansible_mounts,extra_words', [
  72. (
  73. # if no size limit is specified, expect max usage
  74. # limit to default to 90% of size_total
  75. None,
  76. [{
  77. 'mount': '/',
  78. 'size_available': 1 * 10**9,
  79. 'size_total': 100 * 10**9,
  80. }],
  81. ['99.0%'],
  82. ),
  83. (
  84. 70.0,
  85. [{
  86. 'mount': '/',
  87. 'size_available': 1 * 10**6,
  88. 'size_total': 5 * 10**9,
  89. }],
  90. ['100.0%'],
  91. ),
  92. (
  93. 40.0,
  94. [{
  95. 'mount': '/',
  96. 'size_available': 2 * 10**9,
  97. 'size_total': 6 * 10**9,
  98. }],
  99. ['66.7%'],
  100. ),
  101. (
  102. None,
  103. [{
  104. # enough space on /var ...
  105. 'mount': '/var',
  106. 'size_available': 20 * 10**9,
  107. 'size_total': 20 * 10**9,
  108. }, {
  109. # .. but not enough on /var/lib
  110. 'mount': '/var/lib',
  111. 'size_available': 1 * 10**9,
  112. 'size_total': 20 * 10**9,
  113. }],
  114. ['95.0%'],
  115. ),
  116. ])
  117. def test_fails_with_insufficient_disk_space(size_limit_percent, ansible_mounts, extra_words):
  118. task_vars = dict(
  119. etcd_device_usage_threshold_percent=size_limit_percent,
  120. ansible_mounts=ansible_mounts,
  121. )
  122. if task_vars["etcd_device_usage_threshold_percent"] is None:
  123. task_vars.pop("etcd_device_usage_threshold_percent")
  124. result = EtcdVolume(fake_execute_module, task_vars).run()
  125. assert result['failed']
  126. for word in extra_words:
  127. assert word in result['msg']
  128. def fake_execute_module(*args):
  129. raise AssertionError('this function should not be called')