Skip to content

Commit

Permalink
Refactor the naming
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed Aug 21, 2024
1 parent 6808fda commit d8e7eb5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
28 changes: 13 additions & 15 deletions src/report_workflow/test_report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class TestReportRunner:
test_manifest: TestManifest
tests_dir: str
test_report_manifest: TestReportManifest
test_run_data: dict
test_report_data: dict
bundle_manifest: BundleManifest

def __init__(self, args: ReportArgs, test_manifest: TestManifest) -> None:
self.args = args
self.base_path = args.base_path
self.test_manifest = test_manifest
self.release_candidate = self.args.release_candidate
self.test_run_data = self.test_report_manifest_data_template("manifest")
self.test_report_data = self.test_report_manifest_data_template("manifest")
self.product_name = test_manifest.__to_dict__().get("name")
self.name = self.product_name.replace(" ", "-").lower()
self.components = self.args.components
Expand All @@ -50,26 +50,24 @@ def __init__(self, args: ReportArgs, test_manifest: TestManifest) -> None:
self.test_components = self.test_manifest.components

def update_data(self) -> dict:
self.test_run_data["name"] = self.product_name
self.test_report_data["name"] = self.product_name
self.bundle_manifest = BundleManifest.from_urlpath(self.dist_manifest)
self.test_run_data["version"] = self.bundle_manifest.build.version
self.test_run_data["platform"] = self.bundle_manifest.build.platform
self.test_run_data["architecture"] = self.bundle_manifest.build.architecture
self.test_run_data["distribution"] = self.bundle_manifest.build.distribution
self.test_run_data["id"] = self.bundle_manifest.build.id
self.test_run_data["rc"] = self.release_candidate
self.test_run_data["test-run"] = self.update_test_run_data()
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
self.test_report_data["distribution"] = self.bundle_manifest.build.distribution
self.test_report_data["id"] = self.bundle_manifest.build.id
self.test_report_data["rc"] = self.release_candidate
self.test_report_data["test-run"] = self.update_test_run_data()
for component in self.test_components.select(focus=self.args.components):
if self.test_manifest.components[component.name].__to_dict__().get(self.test_type) is not None:
logging.info(f"component is {component.name}")
component_ci_group = getattr(component, self.test_type.replace("-", "_")).get("ci-groups", None)
if component_ci_group:
logging.info(f"ci-group is {component_ci_group}")
for i in range(component_ci_group):
self.test_run_data["components"].append(self.component_entry(component.name, i + 1))
self.test_report_data["components"].append(self.component_entry(component.name, i + 1))
else:
self.test_run_data["components"].append(self.component_entry(component.name))
return self.test_run_data
self.test_report_data["components"].append(self.component_entry(component.name))
return self.test_report_data

def update_test_run_data(self) -> dict:
test_run_data = {
Expand Down
64 changes: 32 additions & 32 deletions tests/tests_report_workflow/test_test_report_runner_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ def test_runner_dashboards_init(self, report_args_mock: MagicMock) -> None:
report_args_mock.test_type = "integ-test"
report_args_mock.release_candidate = "100"

test_run_runner = TestReportRunner(report_args_mock, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS)
test_run_runner_data = test_run_runner.update_data()
self.assertEqual(test_run_runner.name, "opensearch-dashboards")
self.assertEqual(test_run_runner.test_run_id, 123)
self.assertEqual(test_run_runner.test_type, "integ-test")
self.assertEqual(test_run_runner.test_manifest_path, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS_PATH)
self.assertEqual(test_run_runner_data["version"], "1.3.18")
self.assertEqual(test_run_runner_data["platform"], "linux")
self.assertEqual(test_run_runner_data["architecture"], "x64")
self.assertEqual(test_run_runner_data["distribution"], "tar")
self.assertEqual(test_run_runner_data["id"], "7791")
self.assertEqual(test_run_runner_data["rc"], "100")
test_report_runner = TestReportRunner(report_args_mock, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS)
test_report_runner_data = test_report_runner.update_data()
self.assertEqual(test_report_runner.name, "opensearch-dashboards")
self.assertEqual(test_report_runner.test_run_id, 123)
self.assertEqual(test_report_runner.test_type, "integ-test")
self.assertEqual(test_report_runner.test_manifest_path, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS_PATH)
self.assertEqual(test_report_runner_data["version"], "1.3.18")
self.assertEqual(test_report_runner_data["platform"], "linux")
self.assertEqual(test_report_runner_data["architecture"], "x64")
self.assertEqual(test_report_runner_data["distribution"], "tar")
self.assertEqual(test_report_runner_data["id"], "7791")
self.assertEqual(test_report_runner_data["rc"], "100")

@patch("report_workflow.report_args.ReportArgs")
def test_generate_file(self, report_args_mock: MagicMock) -> None:
Expand All @@ -51,12 +51,12 @@ def test_generate_file(self, report_args_mock: MagicMock) -> None:
report_args_mock.test_type = "integ-test"
report_args_mock.release_candidate = "100"

test_run_runner = TestReportRunner(report_args_mock, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS)
test_run_runner_data = test_run_runner.update_data()
test_report_runner = TestReportRunner(report_args_mock, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS)
test_report_runner_data = test_report_runner.update_data()

with TemporaryDirectory() as path:
output_path = os.path.join(path.name, "test-report.yml")
test_run_runner.generate_report(test_run_runner_data, path.name)
test_report_runner.generate_report(test_report_runner_data, path.name)
self.assertTrue(os.path.isfile(output_path))

@patch("report_workflow.report_args.ReportArgs")
Expand All @@ -68,11 +68,11 @@ def test_ci_group(self, report_args_mock: MagicMock) -> None:
report_args_mock.test_type = "integ-test"
report_args_mock.release_candidate = "100"

test_run_runner = TestReportRunner(report_args_mock, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS)
test_run_runner_data = test_run_runner.update_data()
test_report_runner = TestReportRunner(report_args_mock, self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS)
test_report_runner_data = test_report_runner.update_data()

self.assertEqual(len(test_run_runner_data["components"]), 9)
self.assertEqual(test_run_runner_data["components"][0]["name"], "OpenSearch-Dashboards-ci-group-1")
self.assertEqual(len(test_report_runner_data["components"]), 9)
self.assertEqual(test_report_runner_data["components"][0]["name"], "OpenSearch-Dashboards-ci-group-1")

@patch("yaml.safe_load")
@patch("urllib.request.urlopen")
Expand All @@ -90,30 +90,30 @@ def test_runner_component_entry_url(self, report_args_mock: MagicMock, validator
yaml_safe_load_mock.return_value = {"test_result": "PASS"}
urlopen_mock.return_value = MagicMock()

test_run_component_dict = TestReportRunner(report_args_mock,
test_report_component_dict = TestReportRunner(report_args_mock,
self.TEST_MANIFEST_OPENSEARCH_DASHBOARDS).component_entry(
"alertingDashboards")
urlopen_mock.assert_has_calls([call(
'https://ci.opensearch.org/ci/dbc/mock/test-results/123/integ-test/alertingDashboards/with-security/alertingDashboards.yml')])
self.assertEqual(test_run_component_dict.get("configs")[0]["status"], "PASS")
self.assertEqual(test_run_component_dict.get("configs")[0]["name"], "with-security")
self.assertEqual(test_run_component_dict.get("configs")[0]["yml"],
self.assertEqual(test_report_component_dict.get("configs")[0]["status"], "PASS")
self.assertEqual(test_report_component_dict.get("configs")[0]["name"], "with-security")
self.assertEqual(test_report_component_dict.get("configs")[0]["yml"],
"https://ci.opensearch.org/ci/dbc/mock/test-results/123/integ-test/alertingDashboards/with-security/alertingDashboards.yml")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[0]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/with-security/local-cluster-logs/id-0/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stdout"][1], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[0]["cluster_stdout"][1], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/with-security/local-cluster-logs/id-1/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stderr"][0], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[0]["cluster_stderr"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/with-security/local-cluster-logs/id-0/stderr.txt")
self.assertEqual(test_run_component_dict.get("configs")[0]["cluster_stderr"][1], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[0]["cluster_stderr"][1], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/with-security/local-cluster-logs/id-1/stderr.txt")

self.assertEqual(test_run_component_dict.get("configs")[1]["name"], "without-security")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[1]["name"], "without-security")
self.assertEqual(test_report_component_dict.get("configs")[1]["cluster_stdout"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/without-security/local-cluster-logs/id-2/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stdout"][1], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[1]["cluster_stdout"][1], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/without-security/local-cluster-logs/id-3/stdout.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stderr"][0], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[1]["cluster_stderr"][0], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/without-security/local-cluster-logs/id-2/stderr.txt")
self.assertEqual(test_run_component_dict.get("configs")[1]["cluster_stderr"][1], "https://ci.opensearch.org/ci"
self.assertEqual(test_report_component_dict.get("configs")[1]["cluster_stderr"][1], "https://ci.opensearch.org/ci"
"/dbc/mock/test-results/123/integ-test/alertingDashboards/without-security/local-cluster-logs/id-3/stderr.txt")

0 comments on commit d8e7eb5

Please sign in to comment.