-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new base-path parameter to enhance the component yml from test workflow #3497
Changes from 5 commits
1e9019e
eb265eb
2f3984b
5991ed9
1b5b85f
98a2d14
9aa1926
c86a90d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ class TestRecorder: | |
remote_cluster_logs: Any | ||
test_results_logs: Any | ||
|
||
def __init__(self, test_run_id: str, test_type: str, tests_dir: str) -> None: | ||
def __init__(self, test_run_id: str, test_type: str, tests_dir: str, base_path: str = None) -> None: | ||
self.test_run_id = test_run_id | ||
self.test_type = test_type | ||
self.location = os.path.join(tests_dir, str(self.test_run_id), self.test_type) | ||
|
@@ -33,6 +33,14 @@ def __init__(self, test_run_id: str, test_type: str, tests_dir: str) -> None: | |
self.local_cluster_logs = LocalClusterLogs(self) | ||
self.remote_cluster_logs = RemoteClusterLogs(self) | ||
self.test_results_logs = TestResultsLogs(self) | ||
self.base_path = base_path | ||
|
||
def _get_file_path(self, base_path: str, component_name: str, component_test_config: str) -> str: | ||
if base_path.startswith("https://"): | ||
file_path = "/".join([base_path.strip("/"), "test-results", str(self.test_run_id), self.test_type, component_name, component_test_config]) | ||
else: | ||
file_path = self._create_base_folder_structure(component_name, component_test_config) | ||
return file_path | ||
|
||
def _create_base_folder_structure(self, component_name: str, component_test_config: str) -> str: | ||
dest_directory = os.path.join(self.location, component_name, component_test_config) | ||
|
@@ -46,17 +54,45 @@ def _generate_std_files(self, stdout: str, stderr: str, output_path: str) -> Non | |
stderr_file.write(stderr) | ||
|
||
def _generate_yml(self, test_result_data: TestResultData, output_path: str) -> str: | ||
base_file_path = self._get_file_path(self.base_path, test_result_data.component_name, test_result_data.component_test_config) | ||
|
||
components_files = self._get_list_files(output_path) | ||
components_files = self._update_absolute_file_paths(components_files, base_file_path, "") | ||
|
||
local_cluster_logs_path = os.path.join(output_path, "local-cluster-logs") | ||
local_cluster_logs = self._get_list_files(local_cluster_logs_path) | ||
local_cluster_logs = self._update_absolute_file_paths(local_cluster_logs, base_file_path, "local-cluster-logs") | ||
|
||
opensearch_service_logs_path = os.path.join(local_cluster_logs_path, "opensearch-service-logs") | ||
opensearch_service_logs = self._get_list_files(opensearch_service_logs_path) | ||
opensearch_service_logs = self._update_absolute_file_paths(opensearch_service_logs, base_file_path, os.path.join("local-cluster-logs", "opensearch-service-logs")) | ||
|
||
test_result_file = components_files + [ | ||
{ | ||
"local-cluster-logs": | ||
local_cluster_logs + opensearch_service_logs | ||
} | ||
] | ||
|
||
outcome = { | ||
"test_type": self.test_type, | ||
"test_run_id": self.test_run_id, | ||
"run_id": self.test_run_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the rename? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want this key to be written above the |
||
"component_name": test_result_data.component_name, | ||
"test_config": test_result_data.component_test_config, | ||
"exit_code": test_result_data.exit_code, | ||
"test_result": "PASS" if (test_result_data.exit_code == 0) else "FAIL", | ||
"test_result_files": test_result_file | ||
} | ||
with open(os.path.join(output_path, "%s.yml" % test_result_data.component_name), "w") as file: | ||
yaml.dump(outcome, file) | ||
return os.path.realpath("%s.yml" % test_result_data.component_name) | ||
|
||
def _update_absolute_file_paths(self, files: list, base_path: str, relative_path: str) -> list: | ||
return [os.path.join(base_path, relative_path, file) for file in files] | ||
|
||
# get a list of files within directory without folders. | ||
def _get_list_files(self, dir: str) -> list: | ||
return [f for f in os.listdir(dir) if os.path.isfile(dir + '/' + f)] | ||
|
||
def _copy_log_files(self, log_files: dict, dest_directory: str) -> None: | ||
if log_files: | ||
for log_dest_dir_name, source_log_dir in log_files.items(): | ||
|
@@ -106,15 +142,14 @@ def save_test_result_data(self, test_result_data: TestResultData) -> None: | |
|
||
|
||
class TestResultsLogs(LogRecorder): | ||
__test__ = False # type:ignore | ||
parent_class: TestRecorder | ||
|
||
def __init__(self, parent_class: TestRecorder) -> None: | ||
self.parent_class = parent_class | ||
|
||
def save_test_result_data(self, test_result_data: TestResultData) -> None: | ||
base = self.parent_class._create_base_folder_structure(test_result_data.component_name, test_result_data.component_test_config) | ||
dest_directory = os.path.join(base, "test-results") | ||
os.makedirs(dest_directory, exist_ok=False) | ||
dest_directory = self.parent_class._create_base_folder_structure(test_result_data.component_name, test_result_data.component_test_config) | ||
logging.info(f"Recording component test results for {test_result_data.component_name} at " f"{os.path.realpath(dest_directory)}") | ||
self.parent_class._generate_std_files(test_result_data.stdout, test_result_data.stderr, dest_directory) | ||
self.parent_class._copy_log_files(test_result_data.log_files, dest_directory) | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want this to be generic so that any log files can be written under here. Did you check how this behavior affects dashboards integ-test? Since this just seems to be related to opensearch logs and test_recorder is generic to all tests plus OS and OSD. Should this be part of
LocalClusterLogs
class?https://github.com/opensearch-project/opensearch-build/pull/3497/files#diff-d8e45f5fe0a4500dc4bb059941f629bcc07c6cff714a4a6ee1711dc1fdc7c08aR104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaiksaya
For integ test on dashboards, the behavior here are the same. The component yml file (
functionalTestDashboards.yml
) would list out thestdout&stderr
for component and local cluster logs since it doesn't containopensearch_service
. The only things it wouldn't include are those cypress folders (e.g. cypress-screenshots/cypress-videos/cypress-report). I don't think it necessary to keep track of them in the scope of this PR as they are relatively too much to list them all. We could anyway track those videos/reports from the OSD team website I believe.I don't think we should have this be part of the
LocalClusterLogs
as that class is mainly for recording and generating those files. Here we basically just list them out in the component yml file.