Skip to content

Commit ca41b1b

Browse files
authored
Add local cluster logs recording to smoke tests framework (#5321)
Signed-off-by: Zelin Hao <zelinhao@amazon.com>
1 parent 56c4c62 commit ca41b1b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/test_workflow/smoke_test/smoke_test_cluster_opensearch.py

+14
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ def __check_cluster_ready__(self) -> bool:
9797
logging.info(f"Cluster check fails: {e}")
9898
return False
9999

100+
def __save_local_cluster_logs__(self) -> None:
101+
dest_directory = os.path.join(self.test_recorder.location, "local-cluster-logs")
102+
os.makedirs(dest_directory, exist_ok=True)
103+
logging.info(
104+
f"Recording local cluster logs for at {dest_directory}"
105+
)
106+
107+
self.test_recorder._generate_std_files(
108+
self.process_handler.stdout_data,
109+
self.process_handler.stderr_data,
110+
dest_directory,
111+
)
112+
100113
def __uninstall__(self) -> None:
101114
self.process_handler.terminate()
115+
self.__save_local_cluster_logs__()
102116
logging.info("Cluster is terminated.")

tests/tests_test_workflow/test_smoke_workflow/smoke_test/test_smoke_test_cluster_opensearch.py

+25
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,28 @@ def test_uninstall(self, mock_process: Mock, mock_test_manifest: Mock,
181181

182182
# Verify termination
183183
mock_process_handler.terminate.assert_called_once()
184+
185+
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.Distributions.get_distribution")
186+
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.BundleManifest.from_urlpath")
187+
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.BuildManifest.from_urlpath")
188+
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.TestManifest.from_path")
189+
@patch("test_workflow.smoke_test.smoke_test_cluster_opensearch.Process")
190+
def test_save_local_cluster_logs(self, mock_process: Mock, mock_test_manifest: Mock,
191+
mock_build_manifest: Mock, mock_bundle_manifest: Mock,
192+
mock_distribution: Mock) -> None:
193+
args = MagicMock()
194+
test_recorder = MagicMock()
195+
mock_process_handler = mock_process.return_value
196+
197+
# Simulate process handler outputs
198+
mock_process_handler.stdout_data = "mock_stdout_data"
199+
mock_process_handler.stderr_data = "mock_stderr_data"
200+
201+
cluster = SmokeTestClusterOpenSearch(args, "/mock/work_dir", test_recorder)
202+
cluster.__save_local_cluster_logs__()
203+
204+
test_recorder._generate_std_files.assert_called_once_with(
205+
"mock_stdout_data",
206+
"mock_stderr_data",
207+
os.path.join(test_recorder.location, "local-cluster-logs")
208+
)

0 commit comments

Comments
 (0)