Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin85421 committed Apr 17, 2024
1 parent 973c45d commit 0d87faa
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tests/framework/prototype.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Configuration test framework for KubeRay"""
import json
import jsonpatch
from typing import Dict, List, Optional
import unittest
import datetime
import time
import unittest
from typing import Dict, List, Optional
import jsonpatch

from framework.utils import (
create_custom_object,
Expand Down Expand Up @@ -287,9 +288,10 @@ def trigger_condition(self, custom_resource=None) -> bool:
class CurlServiceRule(Rule):
"""Using curl to access the deployed application(s) on RayService"""
CURL_CMD_FMT = (
"kubectl exec curl -n {namespace} -- "
"curl -X POST -H 'Content-Type: application/json' "
"{name}-serve-svc.{namespace}.svc.cluster.local:8000{path}/ -d '{json}'"
"kubectl exec curl -n {namespace} -- sh -c "
"\"curl -X POST -H 'Content-Type: application/json' "
"{name}-serve-svc.{namespace}.svc.cluster.local:8000{path}/ -d '{json}' "
"> /{filename}.output 2>&1\""
)

def __init__(self, queries: List[Dict[str, str]], start_in_background: bool = False):
Expand All @@ -302,14 +304,18 @@ def assert_rule(self, custom_resource, cr_namespace):
start_curl_pod("curl", cr_namespace, timeout_s=30)

for query in self.queries:
now = datetime.datetime.now()
filename = now.strftime("%Y-%m-%d_%H-%M-%S.%f")

cmd = self.CURL_CMD_FMT.format(
name=custom_resource["metadata"]["name"],
namespace=cr_namespace,
path=query.get("path").rstrip("/"),
json=json.dumps(query["json_args"]),
)
filename=filename)

if self.start_in_background:
shell_subprocess_run(f"{cmd} &", hide_output=True)
shell_subprocess_run(f"{cmd} &", hide_output=False)

else:
output = shell_subprocess_check_output(cmd)
Expand Down

0 comments on commit 0d87faa

Please sign in to comment.