Skip to content

Commit

Permalink
Add component repository key value pair to report yml (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#5027)

Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon authored Sep 13, 2024
1 parent 63cdd26 commit 00b5d56
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/manifests/test_report_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TestReportManifest(ComponentManifest['TestReportManifest', 'TestComponents
components:
- name: sql
command: command to trigger the integ test for only sql component
repository: the repository url of the component
configs:
- name: with-security
status: the status of the test run with this config. e.g. pass/fail
Expand Down Expand Up @@ -77,6 +78,7 @@ class TestReportManifest(ComponentManifest['TestReportManifest', 'TestComponents
"schema": {
"name": {"required": True, "type": "string"},
"command": {"type": "string"},
"repository": {"type": "string"},
"configs": {
"type": "list",
"schema": {
Expand Down Expand Up @@ -157,12 +159,14 @@ class TestComponent(Component):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.command = data["command"]
self.repository = data["repository"]
self.configs = self.TestComponentConfigs(data.get("configs", None))

def __to_dict__(self) -> dict:
return {
"name": self.name,
"command": self.command,
"repository": self.repository,
"configs": self.configs.__to_list__()
}

Expand Down
3 changes: 2 additions & 1 deletion src/report_workflow/test_report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def __init__(self, args: ReportArgs, test_manifest: TestManifest) -> None:
self.dist_manifest = "/".join([self.args.artifact_paths[self.name], "dist", self.name, "manifest.yml"]) if self.args.artifact_paths[self.name].startswith("https://") \
else os.path.join(self.args.artifact_paths[self.name], "dist", self.name, "manifest.yml")
self.test_components = self.test_manifest.components
self.bundle_manifest = BundleManifest.from_urlpath(self.dist_manifest)

def update_data(self) -> dict:
self.test_report_data["name"] = self.product_name
self.bundle_manifest = BundleManifest.from_urlpath(self.dist_manifest)
self.test_report_data["version"] = self.bundle_manifest.build.version
self.test_report_data["platform"] = self.bundle_manifest.build.platform
self.test_report_data["architecture"] = self.bundle_manifest.build.architecture
Expand Down Expand Up @@ -90,6 +90,7 @@ def component_entry(self, component_name: str, ci_group: int = None) -> Any:
test_report_component_name = component_name if not ci_group else f"{component_name}-ci-group-{ci_group}"
component["name"] = test_report_component_name
component["command"] = generate_test_command(self.test_type, self.test_manifest_path, self.artifact_paths, component_name)
component["repository"] = self.bundle_manifest.components[component_name].repository

test_component = self.test_manifest.components[component_name]

Expand Down
27 changes: 19 additions & 8 deletions tests/tests_report_workflow/test_test_report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_runner_init(self, report_args_mock: MagicMock) -> None:
self.assertEqual(test_run_runner_data["distribution"], "tar")
self.assertEqual(test_run_runner_data["id"], "9992")
self.assertEqual(test_run_runner_data["rc"], "100")
self.assertEqual(test_run_runner_data["components"][3]["repository"], "https://github.com/opensearch-project/cross-cluster-replication.git")

@patch("report_workflow.report_args.ReportArgs")
def test_generate_file(self, report_args_mock: MagicMock) -> None:
Expand All @@ -64,22 +65,25 @@ def test_generate_file(self, report_args_mock: MagicMock) -> None:
def test_runner_update_test_run_data_local(self, report_args_mock: MagicMock,
test_manifest_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_PATH
report_args_mock.artifact_paths = {"opensearch": "foo/bar"}
report_args_mock.artifact_paths = {"opensearch": self.DATA_DIR}
report_args_mock.test_run_id = 123
report_args_mock.base_path = self.DATA_DIR
report_args_mock.test_type = "integ-test"

test_run_dict = TestReportRunner(report_args_mock, self.TEST_MANIFEST).update_test_run_data()
self.assertEqual(test_run_dict.get("Command"), " ".join(
["./test.sh", "integ-test", self.TEST_MANIFEST_PATH, "--paths", "opensearch=foo/bar"]))
["./test.sh", "integ-test", self.TEST_MANIFEST_PATH, "--paths", f"opensearch={self.DATA_DIR}"]))
self.assertEqual(test_run_dict.get("TestType"), "integ-test")
self.assertEqual(test_run_dict.get("TestManifest"), self.TEST_MANIFEST_PATH)
self.assertEqual(test_run_dict.get("DistributionManifest"),
os.path.join("foo/bar", "dist", "opensearch", "manifest.yml"))
os.path.join(self.DATA_DIR, "dist", "opensearch", "manifest.yml"))
self.assertEqual(test_run_dict.get("TestID"), "123")

@patch("manifests.bundle_manifest.BundleManifest.from_urlpath")
@patch("report_workflow.report_args.ReportArgs")
@patch("manifests.test_manifest.TestManifest")
def test_runner_update_test_run_data_url(self, report_args_mock: MagicMock, test_manifest_mock: MagicMock) -> None:
def test_runner_update_test_run_data_url(self, report_args_mock: MagicMock, test_manifest_mock: MagicMock,
bundle_manifest_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_PATH
report_args_mock.artifact_paths = {"opensearch": "https://foo/bar"}
report_args_mock.test_run_id = 123
Expand All @@ -94,12 +98,14 @@ def test_runner_update_test_run_data_url(self, report_args_mock: MagicMock, test
"/".join(["https://foo/bar", "dist", "opensearch", "manifest.yml"]))
self.assertEqual(test_run_dict.get("TestID"), "123")

@patch("manifests.bundle_manifest.BundleManifest.from_urlpath")
@patch("yaml.safe_load")
@patch("urllib.request.urlopen")
@patch("validators.url")
@patch("report_workflow.report_args.ReportArgs")
def test_runner_component_entry_url(self, report_args_mock: MagicMock, validators_mock: MagicMock,
urlopen_mock: MagicMock, yaml_safe_load_mock: MagicMock) -> None:
urlopen_mock: MagicMock, yaml_safe_load_mock: MagicMock,
bundle_manifest_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_PATH
report_args_mock.artifact_paths = {"opensearch": "foo/bar"}
report_args_mock.test_run_id = 123
Expand Down Expand Up @@ -135,12 +141,14 @@ def test_runner_component_entry_url(self, report_args_mock: MagicMock, validator
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stderr"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/geospatial/without-security/local-cluster-logs/id-1/stderr.txt")

@patch("manifests.bundle_manifest.BundleManifest.from_urlpath")
@patch("yaml.safe_load")
@patch("builtins.open", new_callable=mock_open)
@patch("validators.url")
@patch("report_workflow.report_args.ReportArgs")
def test_runner_component_entry_local(self, report_args_mock: MagicMock, validators_mock: MagicMock,
mock_open: MagicMock, yaml_safe_load_mock: MagicMock) -> None:
mock_open: MagicMock, yaml_safe_load_mock: MagicMock,
bundle_manifest_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_PATH
report_args_mock.artifact_paths = {"opensearch": "foo/bar"}
report_args_mock.test_run_id = 123
Expand All @@ -164,11 +172,12 @@ def test_runner_component_entry_local(self, report_args_mock: MagicMock, validat
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("manifests.bundle_manifest.BundleManifest.from_urlpath")
@patch("yaml.safe_load")
@patch("validators.url")
@patch("report_workflow.report_args.ReportArgs")
def test_runner_component_entry_url_invalid(self, report_args_mock: MagicMock, validators_mock: MagicMock,
yaml_safe_load_mock: MagicMock) -> None:
yaml_safe_load_mock: MagicMock, bundle_manifest_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_PATH
report_args_mock.artifact_paths = {"opensearch": "foo/bar"}
report_args_mock.test_run_id = 123
Expand All @@ -190,12 +199,14 @@ def test_runner_component_entry_url_invalid(self, report_args_mock: MagicMock, v
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")

@patch("manifests.bundle_manifest.BundleManifest.from_urlpath")
@patch("yaml.safe_load")
@patch("builtins.open", new_callable=mock_open)
@patch("validators.url")
@patch("report_workflow.report_args.ReportArgs")
def test_runner_component_entry_local_invalid(self, report_args_mock: MagicMock, validators_mock: MagicMock,
mock_open: MagicMock, yaml_safe_load_mock: MagicMock) -> None:
mock_open: MagicMock, yaml_safe_load_mock: MagicMock,
bundle_manifest_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_PATH
report_args_mock.artifact_paths = {"opensearch": "foo/bar"}
report_args_mock.test_run_id = 123
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_runner_dashboards_init(self, report_args_mock: MagicMock) -> None:
self.assertEqual(test_report_runner_data["distribution"], "tar")
self.assertEqual(test_report_runner_data["id"], "7791")
self.assertEqual(test_report_runner_data["rc"], "100")
self.assertEqual(test_report_runner_data["components"][3]["repository"], "https://github.com/opensearch-project/alerting-dashboards-plugin.git")

@patch("report_workflow.report_args.ReportArgs")
def test_generate_file(self, report_args_mock: MagicMock) -> None:
Expand Down Expand Up @@ -74,6 +75,7 @@ def test_ci_group(self, report_args_mock: MagicMock) -> None:
self.assertEqual(len(test_report_runner_data["components"]), 9)
for i in range(3):
self.assertEqual(test_report_runner_data["components"][i]["name"], f"OpenSearch-Dashboards-ci-group-{i + 1}")
self.assertEqual(test_report_runner_data["components"][i]["repository"], "https://github.com/opensearch-project/OpenSearch-Dashboards.git")

for i in range(len(self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS.components.__to_dict__())):
if self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS.components.__to_dict__()[i]["name"] == "OpenSearch-Dashboards":
Expand All @@ -82,12 +84,13 @@ def test_ci_group(self, report_args_mock: MagicMock) -> None:
self.assertEqual(self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS.components.__to_dict__()[i]["name"],
test_report_runner_data["components"][i + 2]["name"])

@patch("manifests.bundle_manifest.BundleManifest.from_urlpath")
@patch("yaml.safe_load")
@patch("urllib.request.urlopen")
@patch("validators.url")
@patch("report_workflow.report_args.ReportArgs")
def test_runner_component_entry_url(self, report_args_mock: MagicMock, validators_mock: MagicMock,
urlopen_mock: MagicMock, yaml_safe_load_mock: MagicMock) -> None:
urlopen_mock: MagicMock, yaml_safe_load_mock: MagicMock, bundle_manifest_mock: MagicMock) -> None:
report_args_mock.test_manifest_path = self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS_PATH
report_args_mock.artifact_paths = {"opensearch-dashboards": "foo/bar"}
report_args_mock.test_run_id = 123
Expand Down

0 comments on commit 00b5d56

Please sign in to comment.