From 00b5d563523976f842555373d090f11b21d40b47 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 13 Sep 2024 16:50:16 -0400 Subject: [PATCH] Add component repository key value pair to report yml (#5027) Signed-off-by: Peter Zhu --- src/manifests/test_report_manifest.py | 4 +++ src/report_workflow/test_report_runner.py | 3 ++- .../test_test_report_runner.py | 27 +++++++++++++------ .../test_test_report_runner_dashboards.py | 5 +++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/manifests/test_report_manifest.py b/src/manifests/test_report_manifest.py index 7fd6a64405..b90108efdf 100644 --- a/src/manifests/test_report_manifest.py +++ b/src/manifests/test_report_manifest.py @@ -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 @@ -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": { @@ -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__() } diff --git a/src/report_workflow/test_report_runner.py b/src/report_workflow/test_report_runner.py index d05498b65c..2c908c68b2 100644 --- a/src/report_workflow/test_report_runner.py +++ b/src/report_workflow/test_report_runner.py @@ -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 @@ -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] diff --git a/tests/tests_report_workflow/test_test_report_runner.py b/tests/tests_report_workflow/test_test_report_runner.py index 64aea0bc5e..5e0e402278 100644 --- a/tests/tests_report_workflow/test_test_report_runner.py +++ b/tests/tests_report_workflow/test_test_report_runner.py @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/tests_report_workflow/test_test_report_runner_dashboards.py b/tests/tests_report_workflow/test_test_report_runner_dashboards.py index 8c83bde7cb..3b969e7fb9 100644 --- a/tests/tests_report_workflow/test_test_report_runner_dashboards.py +++ b/tests/tests_report_workflow/test_test_report_runner_dashboards.py @@ -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: @@ -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": @@ -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