openshift_master_facts_default_predicates_tests.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_3_6 = [
  5. {'name': 'NoVolumeZoneConflict'},
  6. {'name': 'MaxEBSVolumeCount'},
  7. {'name': 'MaxGCEPDVolumeCount'},
  8. {'name': 'MatchInterPodAffinity'},
  9. {'name': 'NoDiskConflict'},
  10. {'name': 'GeneralPredicates'},
  11. {'name': 'PodToleratesNodeTaints'},
  12. {'name': 'CheckNodeMemoryPressure'},
  13. {'name': 'CheckNodeDiskPressure'},
  14. ]
  15. DEFAULT_PREDICATES_3_7 = [
  16. {'name': 'NoVolumeZoneConflict'},
  17. {'name': 'MaxEBSVolumeCount'},
  18. {'name': 'MaxGCEPDVolumeCount'},
  19. {'name': 'MaxAzureDiskVolumeCount'},
  20. {'name': 'MatchInterPodAffinity'},
  21. {'name': 'NoDiskConflict'},
  22. {'name': 'GeneralPredicates'},
  23. {'name': 'PodToleratesNodeTaints'},
  24. {'name': 'CheckNodeMemoryPressure'},
  25. {'name': 'CheckNodeDiskPressure'},
  26. {'name': 'NoVolumeNodeConflict'},
  27. ]
  28. DEFAULT_PREDICATES_3_8 = DEFAULT_PREDICATES_3_7
  29. DEFAULT_PREDICATES_3_9 = [
  30. {'name': 'NoVolumeZoneConflict'},
  31. {'name': 'MaxEBSVolumeCount'},
  32. {'name': 'MaxGCEPDVolumeCount'},
  33. {'name': 'MaxAzureDiskVolumeCount'},
  34. {'name': 'MatchInterPodAffinity'},
  35. {'name': 'NoDiskConflict'},
  36. {'name': 'GeneralPredicates'},
  37. {'name': 'PodToleratesNodeTaints'},
  38. {'name': 'CheckNodeMemoryPressure'},
  39. {'name': 'CheckNodeDiskPressure'},
  40. {'name': 'CheckVolumeBinding'},
  41. ]
  42. DEFAULT_PREDICATES_3_11 = DEFAULT_PREDICATES_3_10 = DEFAULT_PREDICATES_3_9
  43. REGION_PREDICATE = {
  44. 'name': 'Region',
  45. 'argument': {
  46. 'serviceAffinity': {
  47. 'labels': ['region']
  48. }
  49. }
  50. }
  51. TEST_VARS = [
  52. ('3.6', DEFAULT_PREDICATES_3_6),
  53. ('3.7', DEFAULT_PREDICATES_3_7),
  54. ('3.8', DEFAULT_PREDICATES_3_8),
  55. ('3.9', DEFAULT_PREDICATES_3_9),
  56. ('3.10', DEFAULT_PREDICATES_3_10),
  57. ('3.11', DEFAULT_PREDICATES_3_11),
  58. ]
  59. def assert_ok(predicates_lookup, default_predicates, regions_enabled, **kwargs):
  60. results = predicates_lookup.run(None, regions_enabled=regions_enabled, **kwargs)
  61. if regions_enabled:
  62. assert results == default_predicates + [REGION_PREDICATE]
  63. else:
  64. assert results == default_predicates
  65. def test_openshift_version(predicates_lookup, openshift_version_fixture, regions_enabled):
  66. facts, default_predicates = openshift_version_fixture
  67. assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
  68. @pytest.fixture(params=TEST_VARS)
  69. def openshift_version_fixture(request, facts):
  70. version, default_predicates = request.param
  71. version += '.1'
  72. facts['openshift_version'] = version
  73. return facts, default_predicates
  74. def test_openshift_release(predicates_lookup, openshift_release_fixture, regions_enabled):
  75. facts, default_predicates = openshift_release_fixture
  76. assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled)
  77. @pytest.fixture(params=TEST_VARS)
  78. def openshift_release_fixture(request, facts, release_mod):
  79. release, default_predicates = request.param
  80. facts['openshift_release'] = release_mod(release)
  81. return facts, default_predicates
  82. def test_short_version_kwarg(predicates_lookup, short_version_kwarg_fixture, regions_enabled):
  83. facts, short_version, default_predicates = short_version_kwarg_fixture
  84. assert_ok(
  85. predicates_lookup, default_predicates, variables=facts,
  86. regions_enabled=regions_enabled, short_version=short_version)
  87. @pytest.fixture(params=TEST_VARS)
  88. def short_version_kwarg_fixture(request, facts):
  89. short_version, default_predicates = request.param
  90. return facts, short_version, default_predicates