Skip to content

Commit

Permalink
Add more changes
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Madala <[email protected]>
  • Loading branch information
Divyaasm committed May 8, 2024
1 parent c48c44f commit cec74b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import yaml

from functools import partial
from retry.api import retry_call # type: ignore

from git.git_repository import GitRepository
Expand Down Expand Up @@ -39,24 +40,30 @@ def get_cluster_repo_url(self) -> str:
return "https://github.com/opensearch-project/opensearch-cluster-cdk.git"

def run_tests(self) -> None:
local_path = os.getcwd()
if self.args.cluster_endpoint:
cluster = BenchmarkTestCluster(self.args)
cluster.start()
benchmark_test_suite = BenchmarkTestSuite(cluster.endpoint_with_port, self.security, self.args, cluster.fetch_password())
try:
retry_call(benchmark_test_suite.execute, tries=3, delay=60, backoff=2)
execute_with_params = partial(benchmark_test_suite.execute, local_path)

retry_call(execute_with_params, tries=3, delay=60, backoff=2)
finally:
subprocess.check_call(f"docker rm docker-container-{self.args.stack_suffix}", cwd=os.getcwd(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
config = yaml.safe_load(self.args.config)

with TemporaryDirectory(keep=self.args.keep, chdir=True) as work_dir:

current_workspace = os.path.join(work_dir.name, "opensearch-cluster-cdk")
with GitRepository(self.get_cluster_repo_url(), self.get_git_ref(), current_workspace):
with WorkingDirectory(current_workspace):
with BenchmarkCreateCluster.create(self.args, self.test_manifest, config, current_workspace) as test_cluster:
benchmark_test_suite = BenchmarkTestSuite(test_cluster.endpoint_with_port, self.security, self.args, test_cluster.fetch_password())
try:
retry_call(benchmark_test_suite.execute, tries=3, delay=60, backoff=2)
execute_with_params = partial(benchmark_test_suite.execute, local_path)

retry_call(execute_with_params, tries=3, delay=60, backoff=2)
finally:
subprocess.check_call(f"docker rm docker-container-{self.args.stack_suffix}", cwd=os.getcwd(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
11 changes: 6 additions & 5 deletions src/test_workflow/benchmark_test/benchmark_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,22 @@ def __init__(
else:
self.command += ' --client-options="timeout:300"'

def execute(self) -> None:
def execute(self, path: str) -> None:
log_info = f"Executing {self.command.replace(self.endpoint, len(self.endpoint) * '*').replace(self.args.username, len(self.args.username) * '*')}"
logging.info(log_info.replace(self.password, len(self.password) * '*') if self.password else log_info)
subprocess.check_call(f"{self.command}", cwd=os.getcwd(), shell=True)
with TemporaryDirectory() as work_dir:
subprocess.check_call(f"docker cp docker-container-{self.args.stack_suffix}:opensearch-benchmark/. {str(work_dir.path)}", cwd=os.getcwd(), shell=True)
file_path = glob.glob(os.path.join(str(work_dir.path), "test_executions", "*", "test_execution.json"))
self.convert(file_path[0])
self.convert(file_path[0], path)

def convert(self, results: str) -> None:
def convert(self, results: str, path: str) -> None:
with open(results) as file:
data = json.load(file)
formatted_data = pd.json_normalize(data["results"]["op_metrics"])
formatted_data.to_csv(os.path.join(os.getcwd(), f"test_execution_{self.args.stack_suffix}.csv"), index=False)
df = pd.read_csv(os.path.join(os.getcwd(), f"test_execution_{self.args.stack_suffix}.csv"))
formatted_data.to_csv(os.path.join(path, f"test_execution_{self.args.stack_suffix}.csv"), index=False)
logging.info(os.getcwd())
df = pd.read_csv(os.path.join(path, f"test_execution_{self.args.stack_suffix}.csv"))
pd.set_option('display.width', int(2 * shutil.get_terminal_size().columns))
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
Expand Down

0 comments on commit cec74b9

Please sign in to comment.