-
Notifications
You must be signed in to change notification settings - Fork 8
For non-interactive mode, upload to GCS even if Resultstore client call fails #45
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,7 +165,8 @@ def _parse_args(argv: list[str] | None) -> argparse.Namespace: | |
| '--duration', type=int, help=argparse.SUPPRESS | ||
| ) | ||
| parser.add_argument( | ||
| '--abort_if_no_creds', action='store_true', help=argparse.SUPPRESS | ||
| '--no_interactive', '--abort_if_no_creds', action='store_true', | ||
| help=argparse.SUPPRESS | ||
| ) | ||
| return parser.parse_args(args=argv or sys.argv[1:]) | ||
|
|
||
|
|
@@ -488,7 +489,7 @@ def _create_resultstore_invocation( | |
|
|
||
|
|
||
| def _add_resultstore_target( | ||
| client: resultstore_client.ResultstoreClient, | ||
| client: resultstore_client.ResultstoreClient | None, | ||
| gcs_bucket: str, | ||
| gcs_dir: str, | ||
| file_paths: list[str], | ||
|
|
@@ -497,6 +498,8 @@ def _add_resultstore_target( | |
| assign_undeclared_outputs: bool = False, | ||
| ) -> None: | ||
| """Calls the Resultstore Upload API to create and populate a new target.""" | ||
| if not client: | ||
| return | ||
| client.create_target(target_id) | ||
| client.create_configured_target() | ||
| client.create_action(gcs_bucket, gcs_dir, file_paths, assign_undeclared_outputs) | ||
|
|
@@ -507,11 +510,13 @@ def _add_resultstore_target( | |
|
|
||
|
|
||
| def _finalize_resultstore_invocation( | ||
| client: resultstore_client.ResultstoreClient, | ||
| client: resultstore_client.ResultstoreClient | None, | ||
| status: _Status, | ||
| labels: list[str], | ||
| ): | ||
| """Updates the final status of the invocation and completes the upload.""" | ||
| if not client: | ||
| return | ||
| client.merge_invocation(status, labels) | ||
| client.finalize_invocation() | ||
|
|
||
|
|
@@ -557,9 +562,9 @@ def main(argv: list[str] | None = None) -> None: | |
| try: | ||
| creds, project_id = google.auth.default() | ||
| except google.auth.exceptions.DefaultCredentialsError: | ||
| if args.abort_if_no_creds: | ||
| if args.no_interactive: | ||
| logging.error( | ||
| 'No local credentials found (and abort_if_no_creds==True); ' | ||
| 'No local credentials found (and no_interactive==True); ' | ||
| 'aborting upload. Please run gcloud_setup.py to login first.' | ||
| ) | ||
| exit(1) | ||
|
|
@@ -586,15 +591,22 @@ def main(argv: list[str] | None = None) -> None: | |
| test_timing = None | ||
| if args.start_time: | ||
| test_timing = resultstore_client.Timing(args.start_time, args.duration) | ||
| _create_resultstore_invocation(rs_client, test_timing) | ||
| try: | ||
| _create_resultstore_invocation(rs_client, test_timing) | ||
| except Exception as e: | ||
| if args.no_interactive: | ||
| logging.warning('Resultstore API error. Continuing with GCS upload only. Error: %s', e) | ||
| rs_client = None | ||
| else: | ||
| raise | ||
|
|
||
| # Upload CTS console log as invocation log | ||
| if cts_console_log_dir: | ||
| gcs_files = _upload_dir_to_gcs( | ||
| cts_console_log_dir, gcs_bucket, gcs_base_dir.as_posix(), | ||
| args.gcs_upload_timeout | ||
| ) | ||
| if gcs_files: | ||
| if gcs_files and rs_client: | ||
| rs_client.add_invocation_log(gcs_bucket, gcs_files[0]) | ||
|
Comment on lines
+609
to
610
Contributor
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. This call to if gcs_files and rs_client:
try:
rs_client.add_invocation_log(gcs_bucket, gcs_files[0])
except Exception as e:
if args.no_interactive:
logging.warning('Resultstore API error. Continuing with GCS upload only. Error: %s', e)
rs_client = None
else:
raise |
||
|
|
||
| target_statuses = [] | ||
|
|
@@ -652,7 +664,8 @@ def main(argv: list[str] | None = None) -> None: | |
| ) | ||
| target_statuses.append(test_result_info.status) | ||
| finally: | ||
| logging.info('Generating final Resultstore link...') | ||
| if rs_client: | ||
| logging.info('Generating final Resultstore link...') | ||
| invocation_status = _aggregate_subtest_results(target_statuses) | ||
| labels = args.label | ||
| if args.label_on_pass_only: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While catching a broad
Exceptionensures resilience, this block only protects the initial invocation creation. Ifrs_clientis successfully created but a subsequent call fails (e.g.,add_invocation_logat line 610 or_add_resultstore_targetin the main loop), the script will crash and skip remaining GCS uploads. To fully achieve the goal of "Continuing with GCS upload only", all Resultstore-related calls should be guarded. Additionally, the initialization ofrs_clientat line 582 (outside this diff) should also be protected to handle cases where the client cannot be initialized at all.