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 a6cd3cf commit 4b2d7a7
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import logging
import os
import subprocess
from typing import Union

import yaml
Expand Down Expand Up @@ -43,10 +42,7 @@ def run_tests(self) -> None:
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)
finally:
subprocess.check_call(f"docker rm docker-container-{self.args.stack_suffix}", cwd=os.getcwd(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retry_call(benchmark_test_suite.execute, tries=3, delay=60, backoff=2)
else:
config = yaml.safe_load(self.args.config)

Expand All @@ -56,7 +52,4 @@ def run_tests(self) -> None:
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)
finally:
subprocess.check_call(f"docker rm docker-container-{self.args.stack_suffix}", cwd=os.getcwd(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retry_call(benchmark_test_suite.execute, tries=3, delay=60, backoff=2)
33 changes: 20 additions & 13 deletions src/test_workflow/benchmark_test/benchmark_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,26 @@ def __init__(
def execute(self) -> 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)
try:
subprocess.check_call(f"{self.command}", cwd=os.getcwd(), shell=True)
if self.args.cluster_endpoint:
self.convert()
finally:
self.cleanup()

def convert(self) -> None:
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])

def convert(self, results: 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"))
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)
logging.info(f"\n{df}")
with open(file_path[0]) 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"))
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)
logging.info(f"\n{df}")

def cleanup(self) -> None:
subprocess.check_call(f"docker rm docker-container-{self.args.stack_suffix}", cwd=os.getcwd(), shell=True)
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ class TestBenchmarkTestRunnerOpenSearch(unittest.TestCase):
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.GitRepository")
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.BenchmarkCreateCluster.create")
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.BenchmarkTestSuite")
@patch('test_workflow.benchmark_test.benchmark_test_suite.subprocess.check_call')
def test_run(self, mock_check_call: Mock, mock_suite: Mock, mock_cluster: Mock, mock_git: Mock, mock_temp_directory: Mock,
def test_run(self, mock_suite: Mock, mock_cluster: Mock, mock_git: Mock, mock_temp_directory: Mock,
*mocks: Any) -> None:
mock_check_call.return_value = 0
mock_temp_directory.return_value.__enter__.return_value.name = tempfile.gettempdir()
mock_cluster.return_value.__enter__.return_value = mock_cluster

Expand Down Expand Up @@ -61,11 +59,9 @@ def test_run(self, mock_check_call: Mock, mock_suite: Mock, mock_cluster: Mock,
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.GitRepository")
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.BenchmarkCreateCluster.create")
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.BenchmarkTestSuite")
@patch('test_workflow.benchmark_test.benchmark_test_suite.subprocess.check_call')
def test_run_with_dist_url_and_version(self, mock_check_call: Mock, mock_suite: Mock, mock_cluster: Mock, mock_git: Mock,
def test_run_with_dist_url_and_version(self, mock_suite: Mock, mock_cluster: Mock, mock_git: Mock,
mock_temp_directory: Mock,
*mocks: Any) -> None:
mock_check_call.return_value = 0
mock_temp_directory.return_value.__enter__.return_value.name = tempfile.gettempdir()
mock_cluster.return_value.__enter__.return_value = mock_cluster

Expand All @@ -82,9 +78,7 @@ def test_run_with_dist_url_and_version(self, mock_check_call: Mock, mock_suite:
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.BenchmarkTestCluster.start")
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.BenchmarkTestSuite")
@patch('test_workflow.benchmark_test.benchmark_test_runner_opensearch.retry_call')
@patch('test_workflow.benchmark_test.benchmark_test_suite.subprocess.check_call')
def test_run_with_cluster_endpoint(self, mock_check_call: Mock, mock_retry_call: Mock, mock_suite: Mock, mock_benchmark_test_cluster: Mock) -> None:
mock_check_call.return_value = 0
def test_run_with_cluster_endpoint(self, mock_retry_call: Mock, mock_suite: Mock, mock_benchmark_test_cluster: Mock) -> None:
args = MagicMock(cluster_endpoint=True)
mock_cluster = MagicMock()

Expand All @@ -98,12 +92,10 @@ def test_run_with_cluster_endpoint(self, mock_check_call: Mock, mock_retry_call:
@patch('test_workflow.benchmark_test.benchmark_test_cluster.BenchmarkTestCluster.wait_for_processing')
@patch("test_workflow.benchmark_test.benchmark_test_runner_opensearch.BenchmarkTestSuite")
@patch('test_workflow.benchmark_test.benchmark_test_runner_opensearch.retry_call')
@patch('test_workflow.benchmark_test.benchmark_test_suite.subprocess.check_call')
@patch("subprocess.run")
@patch("requests.get")
def test_run_with_cluster_endpoint_with_arguments(self, mock_requests_get: Mock, mock_subprocess_run: Mock, mock_check_call: Mock,
def test_run_with_cluster_endpoint_with_arguments(self, mock_requests_get: Mock, mock_subprocess_run: Mock,
mock_retry_call: Mock, mock_suite: Mock, mock_wait_for_processing: Optional[Mock]) -> None:
mock_check_call.return_value = 0
args = MagicMock(cluster_endpoint=True)
mock_wait_for_processing.return_value = None
mock_result = MagicMock()
Expand Down
Loading

0 comments on commit 4b2d7a7

Please sign in to comment.