-
Notifications
You must be signed in to change notification settings - Fork 219
wait_for_tests: cdash Refactor and restore commit/time upload #4922
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
Conversation
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.
Pull request overview
This PR refactors the wait_for_tests.py module to use temporary directories for CDash-related operations and restores commit/time information to CDash reports via notes files.
Changes:
- Refactored code to use
tempfile.TemporaryDirectoryfor temporary storage instead of creating directories in the current working directory - Moved git commit and timing information from XML attributes to a separate notes file that is uploaded to CDash
- Updated path handling to use
pathlib.Pathobjects throughout the refactored code
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CIME/wait_for_tests.py
Outdated
| prefixes = [None, first_result_case, os.getcwd()] | ||
| for prefix in prefixes: | ||
| try: | ||
| with tempfile.TemporaryDirectory(prefix=prefix) as tmpdir: |
Copilot
AI
Jan 29, 2026
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.
The parameter name is incorrect. tempfile.TemporaryDirectory accepts a dir parameter to specify the directory location, not prefix. The prefix parameter is used for the temporary directory name prefix (a string that will be prepended to the generated directory name), not for specifying where to create the directory. This should be tempfile.TemporaryDirectory(dir=prefix) instead of tempfile.TemporaryDirectory(prefix=prefix).
| with tempfile.TemporaryDirectory(prefix=prefix) as tmpdir: | |
| with tempfile.TemporaryDirectory(dir=prefix) as tmpdir: |
| # Make notes file | ||
| with notes_file.open(mode="w") as notes_fd: | ||
| notes_fd.write( | ||
| f"Commit {git_commit}\nTotal testing time {time_info} seconds\n" |
Copilot
AI
Jan 29, 2026
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.
When time_info is "unknown" (a string), the notes file will output "Total testing time unknown seconds" which is grammatically incorrect. Consider changing line 494 to handle this case more gracefully, for example: f"Commit {git_commit}\nTotal testing time: {time_info if isinstance(time_info, str) else f'{time_info} seconds'}\n" or set time_info as a string like "unknown" or "X seconds" consistently.
| f"Commit {git_commit}\nTotal testing time {time_info} seconds\n" | |
| f"Commit {git_commit}\n" | |
| f"Total testing time: " | |
| f"{time_info if isinstance(time_info, str) else f'{time_info} seconds'}\n" |
| hostname, | ||
| force_log_upload, | ||
| ) | ||
| stat, out, _ = run_cmd( |
Copilot
AI
Jan 29, 2026
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.
The function run_cmd is used here but it is not imported. The import statement at line 10 only imports run_cmd_no_fail, but not run_cmd. This will cause a NameError at runtime when this code path is executed. You need to add run_cmd to the imports from CIME.utils.
CIME/wait_for_tests.py
Outdated
| logging.info("Upload SUCCESS:\n{}".format(out)) | ||
| return | ||
| except Exception as e: | ||
| logging.info(f"Prexix '{prefix}' failed with error {e}") |
Copilot
AI
Jan 29, 2026
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.
There's a typo in the logging message: "Prexix" should be "Prefix".
| logging.info(f"Prexix '{prefix}' failed with error {e}") | |
| logging.info(f"Prefix '{prefix}' failed with error {e}") |
CIME/wait_for_tests.py
Outdated
| "./xmlquery {} --value".format(param), | ||
| from_dir=case_dir, | ||
| ) | ||
| except: |
Copilot
AI
Jan 29, 2026
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.
Using a bare except clause is a bad practice as it catches all exceptions including SystemExit and KeyboardInterrupt. Consider catching specific exceptions (e.g., CIMEError, subprocess errors) or at minimum use 'except Exception:' to avoid catching system-level exceptions.
| except: | |
| except Exception: |
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.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CIME/wait_for_tests.py
Outdated
|
|
||
| if cdash_build_name: | ||
| create_cdash_xml( | ||
| tmpdir = create_cdash_xml( |
Copilot
AI
Jan 30, 2026
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.
The create_cdash_xml function does not return a value, so this assignment will result in tmpdir = None. The variable tmpdir is not used afterward, so this assignment appears to be vestigial code. Consider removing the assignment and just call the function directly, or if the return value is intended for future use, update create_cdash_xml to return the temporary directory path.
| tmpdir = create_cdash_xml( | |
| create_cdash_xml( |
| notes_fd.write( | ||
| f"Commit {git_commit}\nTotal testing time {time_info} seconds\n" |
Copilot
AI
Jan 30, 2026
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.
When time_info is "unknown" (line 477), the notes file will contain "Total testing time unknown seconds" which is grammatically awkward. Consider formatting this as either "Total testing time: unknown" or "Total testing time: {time_info} seconds" with conditional formatting to handle the "unknown" case more gracefully.
| notes_fd.write( | |
| f"Commit {git_commit}\nTotal testing time {time_info} seconds\n" | |
| if time_info == "unknown": | |
| total_time_line = "Total testing time: unknown" | |
| else: | |
| total_time_line = f"Total testing time {time_info} seconds" | |
| notes_fd.write( | |
| f"Commit {git_commit}\n{total_time_line}\n" |
CIME/wait_for_tests.py
Outdated
| dart_config = """ | ||
| SourceDirectory: {0} | ||
| BuildDirectory: {0} | ||
|
|
||
| # Site is something like machine.domain, i.e. pragmatic.crd | ||
| Site: {1} | ||
|
|
||
| # Build name is osname-revision-compiler, i.e. Linux-2.4.2-2smp-c++ | ||
| BuildName: {2} | ||
|
|
||
| # Submission information | ||
| IsCDash: TRUE | ||
| CDashVersion: | ||
| QueryCDashVersion: | ||
| DropSite: my.cdash.org | ||
| DropLocation: /submit.php?project={3} | ||
| DropSiteUser: | ||
| DropSitePassword: | ||
| DropSiteMode: | ||
| DropMethod: {6} | ||
| TriggerSite: | ||
| ScpCommand: {4} | ||
|
|
||
| # Dashboard start time | ||
| NightlyStartTime: {5} UTC | ||
|
|
||
| UseLaunchers: | ||
| CurlOptions: CURLOPT_SSL_VERIFYPEER_OFF;CURLOPT_SSL_VERIFYHOST_OFF |
Copilot
AI
Jan 30, 2026
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.
The dart_config string now has 4 spaces of leading whitespace on each line (lines 533-559) compared to the original code. This indentation may cause issues if the DartConfiguration.tcl file parser does not handle leading whitespace correctly. Verify that the CDash/CTest configuration file format accepts this indentation, or remove the leading spaces from the string literal.
CIME/wait_for_tests.py
Outdated
| except Exception as e: | ||
| logging.info(f"Temp dir '{tmpdir}' failed with error {e}") |
Copilot
AI
Jan 30, 2026
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.
The exception handler catches all exceptions with a broad Exception clause and only logs an info-level message. This could hide critical errors during CDash submission. Consider logging at warning or error level, and potentially re-raising unexpected exceptions while only catching specific expected exceptions (like PermissionError or OSError for temp directory issues).
| except Exception as e: | |
| logging.info(f"Temp dir '{tmpdir}' failed with error {e}") | |
| except (OSError, PermissionError) as e: | |
| logging.warning(f"Temp dir '{tmpdir}' failed with error {e}", exc_info=True) |
CIME/wait_for_tests.py
Outdated
| return | ||
|
|
||
| except Exception as e: | ||
| logging.info(f"Temp dir '{tmpdir}' failed with error {e}") |
Copilot
AI
Jan 30, 2026
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.
The variable tmpdir is used in the exception handler but is only defined within the with statement context. If an exception occurs before tmpdir is assigned or during the context manager setup, this will raise a NameError. Consider defining tmpdir = tmproot before the try block or using tmproot in the error message instead.
| logging.info(f"Temp dir '{tmpdir}' failed with error {e}") | |
| logging.info(f"Temp dir operation failed with error {e}") |
Description
Two main things. First, refactor the code to use tempfile temp dirs. These will be removed once wait_for_tests is done and will live in /tmp if possible instead of polluting pwd. Second, with recent cdash updates, we were no longer able to see commit and test time. This restores that info by putting it in notes.
Checklist