Skip to content

Commit

Permalink
Add test_stdout and test_stderr path/url for test-report.yml (#5001)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon authored Sep 9, 2024
1 parent da81d93 commit 8146ad2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ warn_return_any = true
warn_unused_configs = true
strict_optional = false
show_error_codes = true
ignore_missing_imports = true
ignore_missing_imports = true
8 changes: 8 additions & 0 deletions src/manifests/test_report_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class TestReportManifest(ComponentManifest['TestReportManifest', 'TestComponents
- name: with-security
status: the status of the test run with this config. e.g. pass/fail
yml: URL or local path to the component yml file
test_stdout: URL or local path to the test stdout log
test_stderr: URL or local path to the test stderr log
cluster_stdout:
- URL or local path to the OpenSearch cluster logs
cluster_stderr:
Expand Down Expand Up @@ -83,6 +85,8 @@ class TestReportManifest(ComponentManifest['TestReportManifest', 'TestComponents
"name": {"type": "string"},
"status": {"type": "string"},
"yml": {"type": "string"},
"test_stdout": {"type": "string"},
"test_stderr": {"type": "string"},
"cluster_stdout": {"type": "list"},
"cluster_stderr": {"type": "list"}
}
Expand Down Expand Up @@ -176,6 +180,8 @@ def __init__(self, data: dict) -> None:
self.name = data["name"]
self.status = data["status"]
self.yml = data["yml"]
self.test_stdout = data["test_stdout"]
self.test_stderr = data["test_stderr"]
self.cluster_stdout = data["cluster_stdout"]
self.cluster_stderr = data["cluster_stderr"]

Expand All @@ -184,6 +190,8 @@ def __to_dict__(self) -> dict:
"name": self.name,
"status": self.status,
"yml": self.yml,
"test_stdout": self.test_stdout,
"test_stderr": self.test_stderr,
"cluster_stdout": self.cluster_stdout,
"cluster_stderr": self.cluster_stderr
}
Expand Down
12 changes: 12 additions & 0 deletions src/report_workflow/test_report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def component_entry(self, component_name: str, ci_group: int = None) -> Any:
component_yml_ref = "URL not available"
config_dict["yml"] = component_yml_ref
config_dict["status"] = test_result
config_dict["test_stdout"] = get_test_logs(self.base_path, str(self.test_run_id), self.test_type, test_report_component_name, config, self.name)[0]
config_dict["test_stderr"] = get_test_logs(self.base_path, str(self.test_run_id), self.test_type, test_report_component_name, config, self.name)[1]
config_dict["cluster_stdout"] = get_os_cluster_logs(self.base_path, str(self.test_run_id), self.test_type, test_report_component_name, config, self.name)[0]
config_dict["cluster_stderr"] = get_os_cluster_logs(self.base_path, str(self.test_run_id), self.test_type, test_report_component_name, config, self.name)[1]
component["configs"].append(config_dict)
Expand Down Expand Up @@ -164,6 +166,16 @@ def generate_test_command(test_type: str, test_manifest_path: str, artifacts_pat
return command


def get_test_logs(base_path: str, test_number: str, test_type: str, component_name: str, config: str,
product_name: str) -> typing.List[str]:
if base_path.startswith("https://"):
return ["/".join([base_path.strip("/"), "test-results", test_number, test_type, component_name, config, "stdout.txt"]),
"/".join([base_path.strip("/"), "test-results", test_number, test_type, component_name, config, "stderr.txt"])]
else:
return [os.path.join(base_path, "test-results", test_number, test_type, component_name, config, "stdout.txt"),
os.path.join(base_path, "test-results", test_number, test_type, component_name, config, "stderr.txt")]


def get_os_cluster_logs(base_path: str, test_number: str, test_type: str, component_name: str, config: str,
product_name: str) -> typing.List[list]:
os_stdout: list = []
Expand Down
19 changes: 18 additions & 1 deletion tests/tests_report_workflow/test_test_report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,19 @@ def test_runner_component_entry_url(self, report_args_mock: MagicMock, validator
self.assertEqual(test_run_component_dict.get("configs")[0]["name"], "with-security")
self.assertEqual(test_run_component_dict.get("configs")[0]["yml"],
"https://ci.opensearch.org/ci/dbc/mock/test-results/123/integ-test/geospatial/with-security/geospatial.yml")
self.assertEqual(test_run_component_dict.get("configs")[0]["test_stdout"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["test_stderr"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/stderr.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/local-cluster-logs/id-0/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stderr"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/local-cluster-logs/id-0/stderr.txt")

self.assertEqual(test_run_component_dict.get("configs")[1]["name"], "without-security")
self.assertEqual(test_run_component_dict.get("configs")[1]["test_stdout"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/without-security/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["test_stderr"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/without-security/stderr.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/without-security/local-cluster-logs/id-1/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stderr"][0], "https://ci.opensearch.org/ci"
Expand Down Expand Up @@ -154,6 +161,8 @@ def test_runner_component_entry_local(self, report_args_mock: MagicMock, validat
"https://ci.opensearch.org/ci/dbc/mock/test-results/123/integ-test/geospatial/with-security/geospatial.yml")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/local-cluster-logs/id-0/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["test_stdout"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/stdout.txt")

@patch("yaml.safe_load")
@patch("validators.url")
Expand All @@ -172,6 +181,10 @@ def test_runner_component_entry_url_invalid(self, report_args_mock: MagicMock, v
self.assertEqual(test_run_component_dict.get("configs")[0]["status"], "Not Available")
self.assertEqual(test_run_component_dict.get("configs")[0]["name"], "with-security")
self.assertEqual(test_run_component_dict.get("configs")[0]["yml"], "URL not available")
self.assertEqual(test_run_component_dict.get("configs")[0]["test_stdout"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["test_stdout"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/without-security/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/local-cluster-logs/id-0/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
Expand Down Expand Up @@ -200,6 +213,10 @@ def test_runner_component_entry_local_invalid(self, report_args_mock: MagicMock,
self.assertEqual(test_run_component_dict.get("configs")[0]["status"], "Not Available")
self.assertEqual(test_run_component_dict.get("configs")[0]["name"], "with-security")
self.assertEqual(test_run_component_dict.get("configs")[0]["yml"], "URL not available")
self.assertEqual(test_run_component_dict.get("configs")[0]["test_stdout"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["test_stdout"], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/without-security/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/with-security/local-cluster-logs/id-0/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
Expand Down

0 comments on commit 8146ad2

Please sign in to comment.