Skip to content

Commit dbd4a02

Browse files
committed
String template
1 parent 3d80ccd commit dbd4a02

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

src/codeflare_sdk/common/utils/unit_test_support.py

+28
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import string
16+
import sys
1517
from codeflare_sdk.ray.cluster.cluster import (
1618
Cluster,
1719
ClusterConfiguration,
@@ -255,6 +257,32 @@ def arg_check_del_effect(group, version, namespace, plural, name, *args):
255257
assert name == "ray-dashboard-unit-test-cluster-ray"
256258

257259

260+
def apply_template(yaml_file_path, variables):
261+
with open(yaml_file_path, "r") as file:
262+
yaml_content = file.read()
263+
264+
# Create a Template instance and substitute the variables
265+
template = string.Template(yaml_content)
266+
filled_yaml = template.substitute(variables)
267+
268+
# Now load the filled YAML into a Python object
269+
return yaml.load(filled_yaml, Loader=yaml.FullLoader)
270+
271+
272+
def get_expected_image():
273+
python_version = sys.version_info
274+
if python_version.major == 3 and python_version.minor == 9:
275+
return "quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06"
276+
else:
277+
return "quay.io/modh/ray@sha256:db667df1bc437a7b0965e8031e905d3ab04b86390d764d120e05ea5a5c18d1b4"
278+
279+
280+
def get_template_variables():
281+
return {
282+
"image": get_expected_image(),
283+
}
284+
285+
258286
def arg_check_apply_effect(group, version, namespace, plural, body, *args):
259287
assert namespace == "ns"
260288
assert args == tuple()

tests/test_cluster_yamls/kueue/aw_kueue.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ spec:
3838
template:
3939
spec:
4040
containers:
41-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
41+
- image: "${image}"
4242
imagePullPolicy: Always
4343
lifecycle:
4444
preStop:
@@ -103,7 +103,7 @@ spec:
103103
template:
104104
spec:
105105
containers:
106-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
106+
- image: "${image}"
107107
imagePullPolicy: Always
108108
lifecycle:
109109
preStop:

tests/test_cluster_yamls/kueue/ray_cluster_kueue.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ spec:
3838
template:
3939
spec:
4040
containers:
41-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
41+
- image: "${image}"
4242
imagePullPolicy: Always
4343
lifecycle:
4444
preStop:
@@ -103,7 +103,7 @@ spec:
103103
template:
104104
spec:
105105
containers:
106-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
106+
- image: "${image}"
107107
imagePullPolicy: Always
108108
lifecycle:
109109
preStop:

tests/test_cluster_yamls/ray/default-appwrapper.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ spec:
3636
template:
3737
spec:
3838
containers:
39-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
39+
- image: "${image}"
4040
imagePullPolicy: Always
4141
lifecycle:
4242
preStop:
@@ -101,7 +101,7 @@ spec:
101101
template:
102102
spec:
103103
containers:
104-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
104+
- image: "${image}"
105105
imagePullPolicy: Always
106106
lifecycle:
107107
preStop:

tests/test_cluster_yamls/ray/default-ray-cluster.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ spec:
2828
template:
2929
spec:
3030
containers:
31-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
31+
- image: "${image}"
3232
imagePullPolicy: Always
3333
lifecycle:
3434
preStop:
@@ -93,7 +93,7 @@ spec:
9393
template:
9494
spec:
9595
containers:
96-
- image: quay.io/modh/ray@sha256:0d715f92570a2997381b7cafc0e224cfa25323f18b9545acfd23bc2b71576d06
96+
- image: "${image}"
9797
imagePullPolicy: Always
9898
lifecycle:
9999
preStop:

0 commit comments

Comments
 (0)