Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions templates/common/_base/files/nmstate-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ contents:

cp "$src_path/$config_file" /etc/nmstate
cp "$src_path/$config_file" "$src_path/applied"

# Write a formatted copy of nmpolicy configurations for easier adoption on day 2
nmstatectl format "$src_path/$config_file" > "$src_path/formatted"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make formatted-output generation best-effort and atomic.

This command can fail the whole bootstrap due to set -e, and direct > can leave a truncated/empty "$src_path/formatted" on failure. Since this is a day-2 convenience artifact, write to a temp file and atomically move only on success; otherwise log and continue.

Suggested patch
-    nmstatectl format "$src_path/$config_file" > "$src_path/formatted"
+    tmp_formatted="$(mktemp "$src_path/formatted.XXXXXX")"
+    if nmstatectl format "$src_path/$config_file" > "$tmp_formatted"; then
+      mv -f "$tmp_formatted" "$src_path/formatted"
+    else
+      rm -f "$tmp_formatted"
+      echo "Warning: failed to generate formatted nmstate config; continuing"
+    fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
nmstatectl format "$src_path/$config_file" > "$src_path/formatted"
tmp_formatted="$(mktemp "$src_path/formatted.XXXXXX")"
if nmstatectl format "$src_path/$config_file" > "$tmp_formatted"; then
mv -f "$tmp_formatted" "$src_path/formatted"
else
rm -f "$tmp_formatted"
echo "Warning: failed to generate formatted nmstate config; continuing"
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/common/_base/files/nmstate-configuration.yaml` at line 48, The
nmstatectl format command is directly redirecting output which can fail and
leave a truncated file, and any failure will stop the entire bootstrap due to
set -e. Refactor the nmstatectl format line to first write the output to a
temporary file (using mktemp), then on successful completion atomically move
that temp file to the final location at "$src_path/formatted" using mv. Wrap
this in a conditional or error handling that logs a message if the formatting
fails but allows the script to continue, since this is just a day-2 convenience
feature and should not block the bootstrap process.