Skip to content

Commit

Permalink
Add local cluster logs recording to smoke tests framework
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed Feb 14, 2025
1 parent b1838a1 commit 5fc829a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/test_workflow/smoke_test/smoke_test_cluster_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(
) -> None:
self.args = args
self.work_dir = work_dir
self.test_recorder = test_recorder
self.process_handler = Process()
self.test_manifest = TestManifest.from_path(args.test_manifest_path)
self.product = self.test_manifest.name.lower().replace(" ", "-")
Expand All @@ -47,6 +46,8 @@ def __init__(
self.dist = self.bundle_manifest.build.distribution
self.distribution = Distributions.get_distribution(self.product, self.dist, self.version, work_dir)

self.test_recorder = test_recorder

def cluster_version(self) -> str:
return self.version

Expand Down Expand Up @@ -97,6 +98,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 5fc829a

Please sign in to comment.