Skip to content

Commit

Permalink
MTV-2025
Browse files Browse the repository at this point in the history
Issue:
When migrating VMs with multiple NICs when mapping the order must match that of the source VM

Fix:
Create a temp udev.rule file with temporarly NICs names with precedence over the "org"  udev rule file - that will overcome the BOOT collisions.
After udev applies the temp names  and omitting the collisions issue it'll apply the desired names.

Ref: https://issues.redhat.com/browse/MTV-2025
Signed-off-by: ehazan <ehazan@redhat.com>
  • Loading branch information
Hazanel committed Feb 19, 2025
1 parent 666c625 commit 5d22f4b
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="temp_eth0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="eth0"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="temp_eth0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="eth0"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="00:50:56:a0:e3:ff",NAME="temp_ens224"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="00:50:56:a0:e3:ff",NAME="ens224"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="temp_eth0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="eth0"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="temp_eth0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="eth0"
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fe",NAME="temp_eth1"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fd",NAME="temp_enp3s0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fe",NAME="eth1"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fd",NAME="enp3s0"
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="temp_ens192"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fe",NAME="temp_eth0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="ens192"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fe",NAME="eth0"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="temp_ens192"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:ff",NAME="ens192"
25 changes: 18 additions & 7 deletions pkg/virt-v2v/customize/scripts/rhel/run/network_config_util.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ udev_from_ifcfg() {
continue
fi

echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"$(remove_quotes "$DEVICE")\""
echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"temp_$(remove_quotes "$DEVICE")\""
done
}

Expand Down Expand Up @@ -147,7 +147,7 @@ udev_from_nm() {
continue
fi

echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"$(remove_quotes "$DEVICE")\""
echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"temp_$(remove_quotes "$DEVICE")\""
done
}

Expand Down Expand Up @@ -223,7 +223,7 @@ udev_from_netplan() {
fi

# Create the udev rule based on the extracted MAC address and interface name
echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"$(remove_quotes "$interface_name")\""
echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"temp_$(remove_quotes "$interface_name")\""
done
}

Expand Down Expand Up @@ -274,10 +274,21 @@ udev_from_ifquery() {
fi

# Create the udev rule based on the extracted MAC address and interface name
echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"$(remove_quotes "$interface_name")\""
echo "SUBSYSTEM==\"net\",ACTION==\"add\",ATTR{address}==\"$(remove_quotes "$S_HW")\",NAME=\"temp_$(remove_quotes "$interface_name")\""
done
}


# Create final udev rules based on the temporary udev rules
# When generating udev rules, there might be conflicts if multiple interfaces
# are being processed simultaneously. By separating the generation of temporary rules
# and the assignment of final names, the script ensures that the final udev rules are consistent and free of conflicts.
udev_final_from_temp_rules() {
input=$(cat)
echo "$input"
echo "$input" | sed "s/temp_//"
}

# Write to udev config
# ----------------------------------------

Expand All @@ -304,9 +315,9 @@ main() {
udev_from_nm
udev_from_netplan
udev_from_ifquery
} | check_dupe_hws > "$UDEV_RULES_FILE" 2>/dev/null
echo "New udev rule:"
} | check_dupe_hws | udev_final_from_temp_rules > "$UDEV_RULES_FILE" 2>/dev/null

echo "New udev rules:"
cat $UDEV_RULES_FILE
}

main
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fe",NAME="temp_eth3"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fe",NAME="eth3"
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fd",NAME="temp_ens160"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="aa:bb:cc:dd:ee:fd",NAME="ens160"

0 comments on commit 5d22f4b

Please sign in to comment.