1+ < << << << HEAD
12# Copyright 2024 IBM, Red Hat
3+ == == == =
4+ # Copyright 2022-2025 IBM, Red Hat
5+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
26#
37# Licensed under the Apache License, Version 2.0 (the "License");
48# you may not use this file except in compliance with the License.
1216# See the License for the specific language governing permissions and
1317# limitations under the License.
1418
19+ << < << << HEAD
1520import pytest
21+ == == == =
22+ >> > >> > > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
1623from codeflare_sdk .common .utils .validation import (
1724 extract_ray_version_from_image ,
1825 validate_ray_version_compatibility ,
@@ -105,6 +112,7 @@ class TestRayVersionValidation:
105112 def test_validate_compatible_versions (self ):
106113 """Test validation with compatible Ray versions."""
107114 # Exact match
115+ < << << << HEAD
108116 is_compatible , message = validate_ray_version_compatibility (
109117 f"ray:{ RAY_VERSION } "
110118 )
@@ -116,37 +124,81 @@ def test_validate_compatible_versions(self):
116124 f"quay.io/modh/ray:{ RAY_VERSION } -py311-cu121"
117125 )
118126 assert is_compatible is True
127+ == == == =
128+ is_compatible , is_warning , message = validate_ray_version_compatibility (
129+ f"ray:{ RAY_VERSION } "
130+ )
131+ assert is_compatible is True
132+ assert is_warning is False
133+ assert "Ray versions match" in message
134+
135+ # With registry and suffixes
136+ is_compatible , is_warning , message = validate_ray_version_compatibility (
137+ f"quay.io/modh/ray:{ RAY_VERSION } -py311-cu121"
138+ )
139+ assert is_compatible is True
140+ assert is_warning is False
141+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
119142 assert "Ray versions match" in message
120143
121144 def test_validate_incompatible_versions (self ):
122145 """Test validation with incompatible Ray versions."""
123146 # Different version
147+ << << << < HEAD
124148 is_compatible , message = validate_ray_version_compatibility ("ray:2.46.0" )
125149 assert is_compatible is False
150+ == == == =
151+ is_compatible , is_warning , message = validate_ray_version_compatibility (
152+ "ray:2.46.0"
153+ )
154+ assert is_compatible is False
155+ assert is_warning is False
156+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
126157 assert "Ray version mismatch detected" in message
127158 assert "CodeFlare SDK uses Ray" in message
128159 assert "runtime image uses Ray" in message
129160
130161 # Older version
162+ << << << < HEAD
131163 is_compatible , message = validate_ray_version_compatibility ("ray:1.13.0" )
132164 assert is_compatible is False
165+ == == == =
166+ is_compatible , is_warning , message = validate_ray_version_compatibility (
167+ "ray:1.13.0"
168+ )
169+ assert is_compatible is False
170+ assert is_warning is False
171+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
133172 assert "Ray version mismatch detected" in message
134173
135174 def test_validate_empty_image (self ):
136175 """Test validation with no custom image (should use default)."""
137176 # Empty string
177+ << << << < HEAD
138178 is_compatible , message = validate_ray_version_compatibility ("" )
139179 assert is_compatible is True
140180 assert "Using default Ray image compatible with SDK" in message
141181
142182 # None
143183 is_compatible , message = validate_ray_version_compatibility (None )
144184 assert is_compatible is True
185+ == == == =
186+ is_compatible , is_warning , message = validate_ray_version_compatibility ("" )
187+ assert is_compatible is True
188+ assert is_warning is False
189+ assert "Using default Ray image compatible with SDK" in message
190+
191+ # None
192+ is_compatible , is_warning , message = validate_ray_version_compatibility (None )
193+ assert is_compatible is True
194+ assert is_warning is False
195+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
145196 assert "Using default Ray image compatible with SDK" in message
146197
147198 def test_validate_unknown_version (self ):
148199 """Test validation when version cannot be determined."""
149200 # SHA-based image
201+ << << << < HEAD
150202 is_compatible , message = validate_ray_version_compatibility (
151203 "quay.io/modh/ray@sha256:6d076aeb38ab3c34a6a2ef0f58dc667089aa15826fa08a73273c629333e12f1e"
152204 )
@@ -159,10 +211,27 @@ def test_validate_unknown_version(self):
159211 )
160212 assert is_compatible is True
161213 assert "Warning: Cannot determine Ray version" in message
214+ == == == =
215+ is_compatible , is_warning , message = validate_ray_version_compatibility (
216+ "quay.io/modh/ray@sha256:6d076aeb38ab3c34a6a2ef0f58dc667089aa15826fa08a73273c629333e12f1e"
217+ )
218+ assert is_compatible is True
219+ assert is_warning is True
220+ assert "Cannot determine Ray version" in message
221+
222+ # Custom image without version
223+ is_compatible , is_warning , message = validate_ray_version_compatibility (
224+ "my-custom-ray:latest"
225+ )
226+ assert is_compatible is True
227+ assert is_warning is True
228+ assert "Cannot determine Ray version" in message
229+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
162230
163231 def test_validate_custom_sdk_version (self ):
164232 """Test validation with custom SDK version."""
165233 # Compatible with custom SDK version
234+ << << << < HEAD
166235 is_compatible , message = validate_ray_version_compatibility (
167236 "ray:2.46.0" , "2.46.0"
168237 )
@@ -174,15 +243,61 @@ def test_validate_custom_sdk_version(self):
174243 "ray:2.47.1" , "2.46.0"
175244 )
176245 assert is_compatible is False
246+ == == == =
247+ is_compatible , is_warning , message = validate_ray_version_compatibility (
248+ "ray:2.46.0" , "2.46.0"
249+ )
250+ assert is_compatible is True
251+ assert is_warning is False
252+ assert "Ray versions match" in message
253+
254+ # Incompatible with custom SDK version
255+ is_compatible , is_warning , message = validate_ray_version_compatibility (
256+ "ray:2.47.1" , "2.46.0"
257+ )
258+ assert is_compatible is False
259+ assert is_warning is False
260+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
177261 assert "CodeFlare SDK uses Ray 2.46.0" in message
178262 assert "runtime image uses Ray 2.47.1" in message
179263
180264 def test_validate_message_content (self ):
181265 """Test that validation messages contain expected guidance."""
182266 # Mismatch message should contain helpful guidance
267+ << << << < HEAD
183268 is_compatible , message = validate_ray_version_compatibility ("ray:2.46.0" )
184269 assert is_compatible is False
270+ == == == =
271+ is_compatible , is_warning , message = validate_ray_version_compatibility (
272+ "ray:2.46.0"
273+ )
274+ assert is_compatible is False
275+ assert is_warning is False
276+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
185277 assert "compatibility issues" in message .lower ()
186278 assert "unexpected behavior" in message .lower ()
187279 assert "please use a runtime image" in message .lower ()
188280 assert "update your sdk version" in message .lower ()
281+ << << << < HEAD
282+ == == == =
283+
284+ def test_semantic_version_comparison (self ):
285+ """Test that semantic version comparison works correctly."""
286+ # Test that 2.10.0 > 2.9.1 (would fail with string comparison)
287+ is_compatible , is_warning , message = validate_ray_version_compatibility (
288+ "ray:2.10.0" , "2.9.1"
289+ )
290+ assert is_compatible is False
291+ assert is_warning is False
292+ assert "CodeFlare SDK uses Ray 2.9.1" in message
293+ assert "runtime image uses Ray 2.10.0" in message
294+
295+ # Test that 2.9.1 < 2.10.0 (would fail with string comparison)
296+ is_compatible , is_warning , message = validate_ray_version_compatibility (
297+ "ray:2.9.1" , "2.10.0"
298+ )
299+ assert is_compatible is False
300+ assert is_warning is False
301+ assert "CodeFlare SDK uses Ray 2.10.0" in message
302+ assert "runtime image uses Ray 2.9.1" in message
303+ >> >> >> > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
0 commit comments