1
+ < << << << HEAD
1
2
# 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 )
2
6
#
3
7
# Licensed under the Apache License, Version 2.0 (the "License");
4
8
# you may not use this file except in compliance with the License.
12
16
# See the License for the specific language governing permissions and
13
17
# limitations under the License.
14
18
19
+ << < << << HEAD
15
20
import pytest
21
+ == == == =
22
+ >> > >> > > 7327753 (feat (RHOAIENG - 29330 ):Deny RayCluster creation with Ray Version mismatches fixed )
16
23
from codeflare_sdk .common .utils .validation import (
17
24
extract_ray_version_from_image ,
18
25
validate_ray_version_compatibility ,
@@ -105,6 +112,7 @@ class TestRayVersionValidation:
105
112
def test_validate_compatible_versions (self ):
106
113
"""Test validation with compatible Ray versions."""
107
114
# Exact match
115
+ < << << << HEAD
108
116
is_compatible , message = validate_ray_version_compatibility (
109
117
f"ray:{ RAY_VERSION } "
110
118
)
@@ -116,37 +124,81 @@ def test_validate_compatible_versions(self):
116
124
f"quay.io/modh/ray:{ RAY_VERSION } -py311-cu121"
117
125
)
118
126
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 )
119
142
assert "Ray versions match" in message
120
143
121
144
def test_validate_incompatible_versions (self ):
122
145
"""Test validation with incompatible Ray versions."""
123
146
# Different version
147
+ << << << < HEAD
124
148
is_compatible , message = validate_ray_version_compatibility ("ray:2.46.0" )
125
149
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 )
126
157
assert "Ray version mismatch detected" in message
127
158
assert "CodeFlare SDK uses Ray" in message
128
159
assert "runtime image uses Ray" in message
129
160
130
161
# Older version
162
+ << << << < HEAD
131
163
is_compatible , message = validate_ray_version_compatibility ("ray:1.13.0" )
132
164
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 )
133
172
assert "Ray version mismatch detected" in message
134
173
135
174
def test_validate_empty_image (self ):
136
175
"""Test validation with no custom image (should use default)."""
137
176
# Empty string
177
+ << << << < HEAD
138
178
is_compatible , message = validate_ray_version_compatibility ("" )
139
179
assert is_compatible is True
140
180
assert "Using default Ray image compatible with SDK" in message
141
181
142
182
# None
143
183
is_compatible , message = validate_ray_version_compatibility (None )
144
184
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 )
145
196
assert "Using default Ray image compatible with SDK" in message
146
197
147
198
def test_validate_unknown_version (self ):
148
199
"""Test validation when version cannot be determined."""
149
200
# SHA-based image
201
+ << << << < HEAD
150
202
is_compatible , message = validate_ray_version_compatibility (
151
203
"quay.io/modh/ray@sha256:6d076aeb38ab3c34a6a2ef0f58dc667089aa15826fa08a73273c629333e12f1e"
152
204
)
@@ -159,10 +211,27 @@ def test_validate_unknown_version(self):
159
211
)
160
212
assert is_compatible is True
161
213
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 )
162
230
163
231
def test_validate_custom_sdk_version (self ):
164
232
"""Test validation with custom SDK version."""
165
233
# Compatible with custom SDK version
234
+ << << << < HEAD
166
235
is_compatible , message = validate_ray_version_compatibility (
167
236
"ray:2.46.0" , "2.46.0"
168
237
)
@@ -174,15 +243,61 @@ def test_validate_custom_sdk_version(self):
174
243
"ray:2.47.1" , "2.46.0"
175
244
)
176
245
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 )
177
261
assert "CodeFlare SDK uses Ray 2.46.0" in message
178
262
assert "runtime image uses Ray 2.47.1" in message
179
263
180
264
def test_validate_message_content (self ):
181
265
"""Test that validation messages contain expected guidance."""
182
266
# Mismatch message should contain helpful guidance
267
+ << << << < HEAD
183
268
is_compatible , message = validate_ray_version_compatibility ("ray:2.46.0" )
184
269
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 )
185
277
assert "compatibility issues" in message .lower ()
186
278
assert "unexpected behavior" in message .lower ()
187
279
assert "please use a runtime image" in message .lower ()
188
280
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