openshift_master_facts_default_predicates_tests.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import pytest
  2. # Predicates ordered according to OpenShift Origin source:
  3. # origin/vendor/k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
  4. DEFAULT_PREDICATES_1_1 = [
  5. {'name': 'PodFitsHostPorts'},
  6. {'name': 'PodFitsResources'},
  7. {'name': 'NoDiskConflict'},
  8. {'name': 'MatchNodeSelector'},
  9. ]
  10. DEFAULT_PREDICATES_1_2 = [
  11. {'name': 'PodFitsHostPorts'},
  12. {'name': 'PodFitsResources'},
  13. {'name': 'NoDiskConflict'},
  14. {'name': 'NoVolumeZoneConflict'},
  15. {'name': 'MatchNodeSelector'},
  16. {'name': 'MaxEBSVolumeCount'},
  17. {'name': 'MaxGCEPDVolumeCount'}
  18. ]
  19. DEFAULT_PREDICATES_1_3 = [
  20. {'name': 'NoDiskConflict'},
  21. {'name': 'NoVolumeZoneConflict'},
  22. {'name': 'MaxEBSVolumeCount'},
  23. {'name': 'MaxGCEPDVolumeCount'},
  24. {'name': 'GeneralPredicates'},
  25. {'name': 'PodToleratesNodeTaints'},
  26. {'name': 'CheckNodeMemoryPressure'}
  27. ]
  28. DEFAULT_PREDICATES_1_4 = [
  29. {'name': 'NoDiskConflict'},
  30. {'name': 'NoVolumeZoneConflict'},
  31. {'name': 'MaxEBSVolumeCount'},
  32. {'name': 'MaxGCEPDVolumeCount'},
  33. {'name': 'GeneralPredicates'},
  34. {'name': 'PodToleratesNodeTaints'},
  35. {'name': 'CheckNodeMemoryPressure'},
  36. {'name': 'CheckNodeDiskPressure'},
  37. {'name': 'MatchInterPodAffinity'}
  38. ]
  39. DEFAULT_PREDICATES_1_5 = [
  40. {'name': 'NoVolumeZoneConflict'},
  41. {'name': 'MaxEBSVolumeCount'},
  42. {'name': 'MaxGCEPDVolumeCount'},
  43. {'name': 'MatchInterPodAffinity'},
  44. {'name': 'NoDiskConflict'},
  45. {'name': 'GeneralPredicates'},
  46. {'name': 'PodToleratesNodeTaints'},
  47. {'name': 'CheckNodeMemoryPressure'},
  48. {'name': 'CheckNodeDiskPressure'},
  49. ]
  50. DEFAULT_PREDICATES_3_6 = DEFAULT_PREDICATES_1_5
  51. DEFAULT_PREDICATES_3_7 = [
  52. {'name': 'NoVolumeZoneConflict'},
  53. {'name': 'MaxEBSVolumeCount'},
  54. {'name': 'MaxGCEPDVolumeCount'},
  55. {'name': 'MaxAzureDiskVolumeCount'},
  56. {'name': 'MatchInterPodAffinity'},
  57. {'name': 'NoDiskConflict'},
  58. {'name': 'GeneralPredicates'},
  59. {'name': 'PodToleratesNodeTaints'},
  60. {'name': 'CheckNodeMemoryPressure'},
  61. {'name': 'CheckNodeDiskPressure'},
  62. {'name': 'NoVolumeNodeConflict'},
  63. ]
  64. DEFAULT_PREDICATES_3_9 = DEFAULT_PREDICATES_3_8 = DEFAULT_PREDICATES_3_7
  65. REGION_PREDICATE = {
  66. 'name': 'Region',
  67. 'argument': {
  68. 'serviceAffinity': {
  69. 'labels': ['region']
  70. }
  71. }
  72. }
  73. TEST_VARS = [
  74. ('1.1', 'origin', DEFAULT_PREDICATES_1_1),
  75. ('3.1', 'openshift-enterprise', DEFAULT_PREDICATES_1_1),
  76. ('1.2', 'origin', DEFAULT_PREDICATES_1_2),
  77. ('3.2', 'openshift-enterprise', DEFAULT_PREDICATES_1_2),
  78. ('1.3', 'origin', DEFAULT_PREDICATES_1_3),
  79. ('3.3', 'openshift-enterprise', DEFAULT_PREDICATES_1_3),
  80. ('1.4', 'origin', DEFAULT_PREDICATES_1_4),
  81. ('3.4', 'openshift-enterprise', DEFAULT_PREDICATES_1_4),
  82. ('1.5', 'origin', DEFAULT_PREDICATES_1_5),
  83. ('3.5', 'openshift-enterprise', DEFAULT_PREDICATES_1_5),
  84. ('3.6', 'origin', DEFAULT_PREDICATES_3_6),
  85. ('3.6', 'openshift-enterprise', DEFAULT_PREDICATES_3_6),
  86. ('3.7', 'origin', DEFAULT_PREDICATES_3_7),
  87. ('3.7', 'openshift-enterprise', DEFAULT_PREDICATES_3_7),
  88. ('3.8', 'origin', DEFAULT_PREDICATES_3_8),
  89. ('3.8', 'openshift-enterprise', DEFAULT_PREDICATES_3_8),
  90. ('3.9', 'origin', DEFAULT_PREDICATES_3_9),
  91. ('3.9', 'openshift-enterprise', DEFAULT_PREDICATES_3_9),
  92. ]
  93. def assert_ok(predicates_lookup, default_predicates, regions_enabled, **kwargs):
  94. results = predicates_lookup.run(None, regions_enabled=regions_enabled, **kwargs)
  95. if regions_enabled:
  96. assert results == default_predicates + [REGION_PREDICATE]
  97. else:
  98. assert results == default_predicates
  99. def test_openshift_version(predicates_lookup, openshift_version_fixture, regions_enabled):
  100. facts, default_predicates = openshift_version_fixture
  101. assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
  102. @pytest.fixture(params=TEST_VARS)
  103. def openshift_version_fixture(request, facts):
  104. version, deployment_type, default_predicates = request.param
  105. version += '.1'
  106. facts['openshift_version'] = version
  107. facts['openshift']['common']['deployment_type'] = deployment_type
  108. return facts, default_predicates
  109. def test_openshift_release(predicates_lookup, openshift_release_fixture, regions_enabled):
  110. facts, default_predicates = openshift_release_fixture
  111. assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
  112. @pytest.fixture(params=TEST_VARS)
  113. def openshift_release_fixture(request, facts, release_mod):
  114. release, deployment_type, default_predicates = request.param
  115. facts['openshift_release'] = release_mod(release)
  116. facts['openshift']['common']['deployment_type'] = deployment_type
  117. return facts, default_predicates
  118. def test_short_version(predicates_lookup, short_version_fixture, regions_enabled):
  119. facts, default_predicates = short_version_fixture
  120. assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
  121. @pytest.fixture(params=TEST_VARS)
  122. def short_version_fixture(request, facts):
  123. short_version, deployment_type, default_predicates = request.param
  124. facts['openshift']['common']['short_version'] = short_version
  125. facts['openshift']['common']['deployment_type'] = deployment_type
  126. return facts, default_predicates
  127. def test_short_version_kwarg(predicates_lookup, short_version_kwarg_fixture, regions_enabled):
  128. facts, short_version, default_predicates = short_version_kwarg_fixture
  129. assert_ok(
  130. predicates_lookup, default_predicates, variables=facts,
  131. regions_enabled=regions_enabled, short_version=short_version)
  132. @pytest.fixture(params=TEST_VARS)
  133. def short_version_kwarg_fixture(request, facts):
  134. short_version, deployment_type, default_predicates = request.param
  135. facts['openshift']['common']['deployment_type'] = deployment_type
  136. return facts, short_version, default_predicates
  137. def test_deployment_type_kwarg(predicates_lookup, deployment_type_kwarg_fixture, regions_enabled):
  138. facts, deployment_type, default_predicates = deployment_type_kwarg_fixture
  139. assert_ok(
  140. predicates_lookup, default_predicates, variables=facts,
  141. regions_enabled=regions_enabled, deployment_type=deployment_type)
  142. @pytest.fixture(params=TEST_VARS)
  143. def deployment_type_kwarg_fixture(request, facts):
  144. short_version, deployment_type, default_predicates = request.param
  145. facts['openshift']['common']['short_version'] = short_version
  146. return facts, deployment_type, default_predicates
  147. def test_short_version_deployment_type_kwargs(
  148. predicates_lookup, short_version_deployment_type_kwargs_fixture, regions_enabled):
  149. short_version, deployment_type, default_predicates = short_version_deployment_type_kwargs_fixture
  150. assert_ok(
  151. predicates_lookup, default_predicates, regions_enabled=regions_enabled,
  152. short_version=short_version, deployment_type=deployment_type)
  153. @pytest.fixture(params=TEST_VARS)
  154. def short_version_deployment_type_kwargs_fixture(request):
  155. return request.param