Skip to content

Commit 7060812

Browse files
authored
Fix validation of the post-training, notebook DAGs (GoogleCloudPlatform#1185)
Before this fix, the validation always passes because grep will find the source code that contains the success message but we want the actual success message in the output.
1 parent 6bfe294 commit 7060812

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

dags/post_training/util/notebook_util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,15 @@ def build_notebook_execution_command(
234234
f"{export_prefix}papermill {output_nb} {output_nb} --log-output"
235235
)
236236

237+
# Verify the success message exists in the notebook's output.
238+
# We 'grep -v "print("' to ignore the Python source code line
239+
# and ensure we are matching an actual execution result.
240+
expected_completed_message = "Training Completed Successfully!"
237241
verification_script = textwrap.dedent(
238242
f"""
239-
if ! grep -q "Training Completed Successfully!" {output_nb}; then
240-
echo "Error: Notebook did not report successful completion."
243+
set -o pipefail
244+
if ! grep "{expected_completed_message}" {output_nb} | grep -vq "print("; then
245+
echo "Error: Notebook did not report '{expected_completed_message}'."
241246
exit 1
242247
fi
243248
"""

0 commit comments

Comments
 (0)