Skip to content

Commit

Permalink
Add local cluster logs recording to smoke tests framework (#5321)
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh authored Feb 15, 2025
1 parent 56c4c62 commit ca41b1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test_workflow/smoke_test/smoke_test_cluster_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ def __check_cluster_ready__(self) -> bool:
logging.info(f"Cluster check fails: {e}")
return False

def __save_local_cluster_logs__(self) -> None:
dest_directory = os.path.join(self.test_recorder.location, "local-cluster-logs")
os.makedirs(dest_directory, exist_ok=True)
logging.info(
f"Recording local cluster logs for at {dest_directory}"
)

self.test_recorder._generate_std_files(
self.process_handler.stdout_data,
self.process_handler.stderr_data,
dest_directory,
)

def __uninstall__(self) -> None:
self.process_handler.terminate()
self.__save_local_cluster_logs__()
logging.info("Cluster is terminated.")
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,28 @@ def test_uninstall(self, mock_process: Mock, mock_test_manifest: Mock,

# Verify termination
mock_process_handler.terminate.assert_called_once()

@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.Distributions.get_distribution")
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.BundleManifest.from_urlpath")
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.BuildManifest.from_urlpath")
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.TestManifest.from_path")
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.Process")
def test_save_local_cluster_logs(self, mock_process: Mock, mock_test_manifest: Mock,
mock_build_manifest: Mock, mock_bundle_manifest: Mock,
mock_distribution: Mock) -> None:
args = MagicMock()
test_recorder = MagicMock()
mock_process_handler = mock_process.return_value

# Simulate process handler outputs
mock_process_handler.stdout_data = "mock_stdout_data"
mock_process_handler.stderr_data = "mock_stderr_data"

cluster = SmokeTestClusterOpenSearch(args, "/mock/work_dir", test_recorder)
cluster.__save_local_cluster_logs__()

test_recorder._generate_std_files.assert_called_once_with(
"mock_stdout_data",
"mock_stderr_data",
os.path.join(test_recorder.location, "local-cluster-logs")
)

0 comments on commit ca41b1b

Please sign in to comment.