Skip to content

Commit

Permalink
Ensure all temp files are deleted after the compatibility test (ray-p…
Browse files Browse the repository at this point in the history
…roject#886)

This PR ensures all temp files are removed after the compatibility tests are completed. In the current implementation, some temporary files will not be deleted after the process exits.
  • Loading branch information
Yicheng-Lu-llll authored Jan 30, 2023
1 parent 7b1b45b commit 75197ec
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions tests/kuberay_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def create_ray_cluster(template_name, ray_version, ray_image):
yamlfile = template.substitute(
{'ray_image': ray_image, 'ray_version': ray_version}
)
with tempfile.NamedTemporaryFile('w', delete=False) as ray_cluster_yaml:
ray_cluster_yaml.write(yamlfile)
context['filepath'] = ray_cluster_yaml.name
with tempfile.NamedTemporaryFile('w', suffix = '_ray_cluster_yaml') as ray_cluster_yaml:
ray_cluster_yaml.write(yamlfile)
ray_cluster_yaml.flush()
context['filepath'] = ray_cluster_yaml.name

for k8s_object in yaml.safe_load_all(yamlfile):
if k8s_object['kind'] == 'RayCluster':
context['cr'] = k8s_object
break
for k8s_object in yaml.safe_load_all(yamlfile):
if k8s_object['kind'] == 'RayCluster':
context['cr'] = k8s_object
break

try:
# Create a RayCluster
ray_cluster_add_event = RayClusterAddCREvent(
custom_resource_object = context['cr'],
Expand All @@ -61,9 +61,6 @@ def create_ray_cluster(template_name, ray_version, ray_image):
)
ray_cluster_add_event.trigger()
return ray_cluster_add_event
except Exception as ex:
logger.error(f"RayClusterAddCREvent fails to converge: {str(ex)}")
raise Exception("create_ray_cluster fails")

def create_ray_service(template_name, ray_version, ray_image):
"""Create a RayService without a NodePort service."""
Expand All @@ -73,16 +70,16 @@ def create_ray_service(template_name, ray_version, ray_image):
yamlfile = template.substitute(
{'ray_image': ray_image, 'ray_version': ray_version}
)
with tempfile.NamedTemporaryFile('w', delete=False) as ray_service_yaml:
ray_service_yaml.write(yamlfile)
context['filepath'] = ray_service_yaml.name
with tempfile.NamedTemporaryFile('w', suffix = '_ray_service_yaml') as ray_service_yaml:
ray_service_yaml.write(yamlfile)
ray_service_yaml.flush()
context['filepath'] = ray_service_yaml.name

for k8s_object in yaml.safe_load_all(yamlfile):
if k8s_object['kind'] == 'RayService':
context['cr'] = k8s_object
break
for k8s_object in yaml.safe_load_all(yamlfile):
if k8s_object['kind'] == 'RayService':
context['cr'] = k8s_object
break

try:
# Create a RayService
ray_service_add_event = RayServiceAddCREvent(
custom_resource_object = context['cr'],
Expand All @@ -93,9 +90,6 @@ def create_ray_service(template_name, ray_version, ray_image):
)
ray_service_add_event.trigger()
return ray_service_add_event
except Exception as ex:
logger.error(f"RayServiceAddCREvent fails to converge: {str(ex)}")
raise Exception("create_ray_service fails")

def wait_for_condition(
condition_predictor, timeout=10, retry_interval_ms=100, **kwargs
Expand Down

0 comments on commit 75197ec

Please sign in to comment.