disk_availability_test.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import pytest
  2. from openshift_checks.disk_availability import DiskAvailability, OpenShiftCheckException
  3. @pytest.mark.parametrize('group_names,is_active', [
  4. (['masters'], True),
  5. (['nodes'], True),
  6. (['etcd'], True),
  7. (['masters', 'nodes'], True),
  8. (['masters', 'etcd'], True),
  9. ([], False),
  10. (['lb'], False),
  11. (['nfs'], False),
  12. ])
  13. def test_is_active(group_names, is_active):
  14. task_vars = dict(
  15. group_names=group_names,
  16. )
  17. assert DiskAvailability(None, task_vars).is_active() == is_active
  18. @pytest.mark.parametrize('ansible_mounts,extra_words', [
  19. ([], ['none']), # empty ansible_mounts
  20. ([{'mount': '/mnt'}], ['/mnt']), # missing relevant mount paths
  21. ([{'mount': '/var'}], ['/var']), # missing size_available
  22. ])
  23. def test_cannot_determine_available_disk(ansible_mounts, extra_words):
  24. task_vars = dict(
  25. group_names=['masters'],
  26. ansible_mounts=ansible_mounts,
  27. )
  28. with pytest.raises(OpenShiftCheckException) as excinfo:
  29. DiskAvailability(fake_execute_module, task_vars).run()
  30. for word in 'determine disk availability'.split() + extra_words:
  31. assert word in str(excinfo.value)
  32. @pytest.mark.parametrize('group_names,configured_min,ansible_mounts', [
  33. (
  34. ['masters'],
  35. 0,
  36. [{
  37. 'mount': '/',
  38. 'size_available': 40 * 10**9 + 1,
  39. }],
  40. ),
  41. (
  42. ['nodes'],
  43. 0,
  44. [{
  45. 'mount': '/',
  46. 'size_available': 15 * 10**9 + 1,
  47. }],
  48. ),
  49. (
  50. ['etcd'],
  51. 0,
  52. [{
  53. 'mount': '/',
  54. 'size_available': 20 * 10**9 + 1,
  55. }],
  56. ),
  57. (
  58. ['etcd'],
  59. 1, # configure lower threshold
  60. [{
  61. 'mount': '/',
  62. 'size_available': 1 * 10**9 + 1, # way smaller than recommended
  63. }],
  64. ),
  65. (
  66. ['etcd'],
  67. 0,
  68. [{
  69. # not enough space on / ...
  70. 'mount': '/',
  71. 'size_available': 2 * 10**9,
  72. }, {
  73. # ... but enough on /var
  74. 'mount': '/var',
  75. 'size_available': 20 * 10**9 + 1,
  76. }],
  77. ),
  78. ])
  79. def test_succeeds_with_recommended_disk_space(group_names, configured_min, ansible_mounts):
  80. task_vars = dict(
  81. group_names=group_names,
  82. openshift_check_min_host_disk_gb=configured_min,
  83. ansible_mounts=ansible_mounts,
  84. )
  85. result = DiskAvailability(fake_execute_module, task_vars).run()
  86. assert not result.get('failed', False)
  87. @pytest.mark.parametrize('group_names,configured_min,ansible_mounts,extra_words', [
  88. (
  89. ['masters'],
  90. 0,
  91. [{
  92. 'mount': '/',
  93. 'size_available': 1,
  94. }],
  95. ['0.0 GB'],
  96. ),
  97. (
  98. ['masters'],
  99. 100, # set a higher threshold
  100. [{
  101. 'mount': '/',
  102. 'size_available': 50 * 10**9, # would normally be enough...
  103. }],
  104. ['100.0 GB'],
  105. ),
  106. (
  107. ['nodes'],
  108. 0,
  109. [{
  110. 'mount': '/',
  111. 'size_available': 1 * 10**9,
  112. }],
  113. ['1.0 GB'],
  114. ),
  115. (
  116. ['etcd'],
  117. 0,
  118. [{
  119. 'mount': '/',
  120. 'size_available': 1,
  121. }],
  122. ['0.0 GB'],
  123. ),
  124. (
  125. ['nodes', 'masters'],
  126. 0,
  127. [{
  128. 'mount': '/',
  129. # enough space for a node, not enough for a master
  130. 'size_available': 15 * 10**9 + 1,
  131. }],
  132. ['15.0 GB'],
  133. ),
  134. (
  135. ['etcd'],
  136. 0,
  137. [{
  138. # enough space on / ...
  139. 'mount': '/',
  140. 'size_available': 20 * 10**9 + 1,
  141. }, {
  142. # .. but not enough on /var
  143. 'mount': '/var',
  144. 'size_available': 0,
  145. }],
  146. ['0.0 GB'],
  147. ),
  148. ])
  149. def test_fails_with_insufficient_disk_space(group_names, configured_min, ansible_mounts, extra_words):
  150. task_vars = dict(
  151. group_names=group_names,
  152. openshift_check_min_host_disk_gb=configured_min,
  153. ansible_mounts=ansible_mounts,
  154. )
  155. result = DiskAvailability(fake_execute_module, task_vars).run()
  156. assert result['failed']
  157. for word in 'below recommended'.split() + extra_words:
  158. assert word in result['msg']
  159. def fake_execute_module(*args):
  160. raise AssertionError('this function should not be called')