MTV-5530 | static IP preservation on RHEL 9/10+ after migration#6418
MTV-5530 | static IP preservation on RHEL 9/10+ after migration#6418Hazanel wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR adds a ChangesNetworkManager MAC Address Patching
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with 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.
Inline comments:
In `@pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh`:
- Around line 540-543: The code assumes NM_FILE from grep -El is a single path
but grep can return multiple files; update the logic around NM_FILE (the grep
-El call that searches NETWORK_CONNECTIONS_DIR for S_IP) to iterate over each
matching filename instead of treating the whole string as one quoted pathname.
Replace the single-use of NM_FILE with a loop (e.g., readarray/mapfile or while
read -r over the grep output) so each matching file is processed individually;
apply the same change to the other occurrence block referenced (the code around
lines handling NM_FILE from 548-561) to avoid failures when grep returns
multiple matches.
- Around line 553-557: The current [ethernet] patch only inserts mac-address
when missing, so update the logic in the [ethernet] handling around NM_FILE and
MAC_LOWER to always ensure the mac-address equals $MAC_LOWER: if a line matching
'^mac-address=' exists replace it with 'mac-address=$MAC_LOWER' (e.g. via sed -i
's/^mac-address=.*/mac-address='$MAC_LOWER'/' "$NM_FILE"), otherwise append the
mac-address after the '[ethernet]' header as before; apply the same
replace-or-append fix to the other similar block referenced (lines around
559-561) so any incorrect existing MAC is corrected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 64782048-41bd-47dc-98cf-7f43adf9088c
📒 Files selected for processing (8)
pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.shpkg/virt-v2v/customize/scripts/rhel/run/networkmanager-mac-patch-test.d/expected-nm/eth0.nmconnectionpkg/virt-v2v/customize/scripts/rhel/run/networkmanager-mac-patch-test.d/expected-nm/eth1.nmconnectionpkg/virt-v2v/customize/scripts/rhel/run/networkmanager-mac-patch-test.d/expected-udev.rulepkg/virt-v2v/customize/scripts/rhel/run/networkmanager-mac-patch-test.d/root/etc/NetworkManager/system-connections/eth0.nmconnectionpkg/virt-v2v/customize/scripts/rhel/run/networkmanager-mac-patch-test.d/root/etc/NetworkManager/system-connections/eth1.nmconnectionpkg/virt-v2v/customize/scripts/rhel/run/networkmanager-mac-patch-test.d/root/tmp/macToIPpkg/virt-v2v/customize/scripts/rhel/run/test-network_config_util.sh
d35e6d9 to
ba0b654
Compare
|
@coderabbitai - please check the fixes and in general go over and suggest whether you think there is a better approach |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 27235
✅ What's Good
🐛 Bugs1. Multi-file match —
|
| Scenario | Covered? |
|---|---|
No [ethernet] section (appends new section) |
✅ both fixture files |
[ethernet] section already present, no mac-address= |
❌ |
[ethernet] section already present with mac-address= (idempotency) |
❌ |
mac-address= present but wrong value (correction) |
❌ |
The sed -i "/^\[ethernet\]/a mac-address=..." code path (when [ethernet] already exists) is entirely untested. I'd recommend adding a networkmanager-mac-patch-with-ethernet-test.d fixture to cover it.
💡 Alternative Approach Consideration
The current approach (edit raw .nmconnection INI files with grep/sed) is pragmatic for a shell script context without NM running. An alternative worth considering:
Use nmcli in the post-migration firstboot phase (i.e., on first boot inside the migrated VM after NM is running), which would let you do:
nmcli connection modify eth0 802-3-ethernet.mac-address "$MAC" connection.interface-name ""However, this would require a systemd one-shot service that runs on first boot — significantly more complex than what you have. The direct file editing approach is simpler and more reliable for the virt-v2v context, so I'd keep the current approach and just address the bugs above.
Summary of Recommended Fixes
- Add
| head -1to thegrep -Elassignment inpatch_nm_connectionsto guard against multi-file matches. - Replace the
mac-address=check with an unconditionalsedsubstitution (or add an update branch) to handle stale/incorrect existing values. - Add a test fixture with a pre-existing
[ethernet]section to cover thesed -i "/^\[ethernet\]/a ..."branch. - (Optional) Add a log message for the missing-directory early return for consistency.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6418 +/- ##
==========================================
- Coverage 15.45% 10.44% -5.02%
==========================================
Files 112 521 +409
Lines 23377 61917 +38540
==========================================
+ Hits 3613 6466 +2853
- Misses 19479 54895 +35416
- Partials 285 556 +271
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ba0b654 to
661f375
Compare
|
Thanks @coderabbitai for the thorough review, please check the fixes. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 36443
✅ All Three Issues Fixed
The three-branch logic in
|
661f375 to
06c0c26
Compare
mnecas
left a comment
There was a problem hiding this comment.
@Hazanel editing the source config file can be bit complicated. I would rather lean to creating .link file for the NM. https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/configuring_and_managing_networking/implementing-consistent-network-interface-naming
wdyt @yaacov ?
my concern is that we are solving missing support for specific OSs in virt-v2v by adding ad-hock scripts.
yes, specifically for this issue, if a less intrusive fix work ( e.g. adding a separate named file ) my vote is not to edit an existing file, but to add a separate file with the correct priority. |
06c0c26 to
b00481e
Compare
b00481e to
dd62caf
Compare
d13f444 to
a084193
Compare
a084193 to
662dc93
Compare
1d5fb8a to
55a0382
Compare
7c2f28a to
ccdf9bd
Compare
On RHEL 9/10+, predictable naming (enp1s0) overrides udev NAME= rules. NM keyfiles that reference interface-name=eth0 never activate, so the VM loses its static IP. Add generate_link_files() which writes systemd .link files that rename interfaces by MAC before NM starts. The .link files are derived from NM connection profiles: creation is skipped when NM is absent, when the profile already has the correct mac-address=, or when no matching profile exists for the IP. Ref: https://redhat.atlassian.net/browse/MTV-5530 Resolves: MTV-5530 Signed-off-by: Elad Hazan <ehazan@redhat.com>
ccdf9bd to
de2a27a
Compare
|



On RHEL 9/10+, predictable network interface naming (e.g. enp1s0)
overrides udev NAME= rename rules to e.g eth0.
Since NM keyfiles reference interface-name=eth0, NetworkManager never activates the
connection and the VM loses its static IP.
Add generate_link_files() to network_config_util.sh which writes
systemd .link files into /etc/systemd/network/. A .link [Match]
by MAC with [Link] Name= tells systemd-udevd to rename
the interface before NetworkManager sees it, so existing NM
connections activate unchanged. The .link file is harmless on
older distros where the udev rule already works.
Ref: https://redhat.atlassian.net/browse/MTV-5530
Resolves: MTV-5530