disk_availability_test.py 4.4 KB

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