memory_availability_test.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import pytest
  2. from openshift_checks.memory_availability import MemoryAvailability
  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 MemoryAvailability.is_active(task_vars=task_vars) == is_active
  18. @pytest.mark.parametrize('group_names,configured_min,ansible_memtotal_mb', [
  19. (
  20. ['masters'],
  21. 0,
  22. 17200,
  23. ),
  24. (
  25. ['nodes'],
  26. 0,
  27. 8200,
  28. ),
  29. (
  30. ['nodes'],
  31. 1, # configure lower threshold
  32. 2000, # too low for recommended but not for configured
  33. ),
  34. (
  35. ['nodes'],
  36. 2, # configure threshold where adjustment pushes it over
  37. 1900,
  38. ),
  39. (
  40. ['etcd'],
  41. 0,
  42. 8200,
  43. ),
  44. (
  45. ['masters', 'nodes'],
  46. 0,
  47. 17000,
  48. ),
  49. ])
  50. def test_succeeds_with_recommended_memory(group_names, configured_min, ansible_memtotal_mb):
  51. task_vars = dict(
  52. group_names=group_names,
  53. openshift_check_min_host_memory_gb=configured_min,
  54. ansible_memtotal_mb=ansible_memtotal_mb,
  55. )
  56. check = MemoryAvailability(execute_module=fake_execute_module)
  57. result = check.run(tmp=None, task_vars=task_vars)
  58. assert not result.get('failed', False)
  59. @pytest.mark.parametrize('group_names,configured_min,ansible_memtotal_mb,extra_words', [
  60. (
  61. ['masters'],
  62. 0,
  63. 0,
  64. ['0.0 GiB'],
  65. ),
  66. (
  67. ['nodes'],
  68. 0,
  69. 100,
  70. ['0.1 GiB'],
  71. ),
  72. (
  73. ['nodes'],
  74. 24, # configure higher threshold
  75. 20 * 1024, # enough to meet recommended but not configured
  76. ['20.0 GiB'],
  77. ),
  78. (
  79. ['nodes'],
  80. 24, # configure higher threshold
  81. 22 * 1024, # not enough for adjustment to push over threshold
  82. ['22.0 GiB'],
  83. ),
  84. (
  85. ['etcd'],
  86. 0,
  87. 6 * 1024,
  88. ['6.0 GiB'],
  89. ),
  90. (
  91. ['etcd', 'masters'],
  92. 0,
  93. 9 * 1024, # enough memory for etcd, not enough for a master
  94. ['9.0 GiB'],
  95. ),
  96. (
  97. ['nodes', 'masters'],
  98. 0,
  99. # enough memory for a node, not enough for a master
  100. 11 * 1024,
  101. ['11.0 GiB'],
  102. ),
  103. ])
  104. def test_fails_with_insufficient_memory(group_names, configured_min, ansible_memtotal_mb, extra_words):
  105. task_vars = dict(
  106. group_names=group_names,
  107. openshift_check_min_host_memory_gb=configured_min,
  108. ansible_memtotal_mb=ansible_memtotal_mb,
  109. )
  110. check = MemoryAvailability(execute_module=fake_execute_module)
  111. result = check.run(tmp=None, task_vars=task_vars)
  112. assert result.get('failed', False)
  113. for word in 'below recommended'.split() + extra_words:
  114. assert word in result['msg']
  115. def fake_execute_module(*args):
  116. raise AssertionError('this function should not be called')