MT#55944 Fix networking for plain Debian systems

When building our Debian boxes for buster, bullseye + bookworm (via
daily-build-matrix-debian-boxes Jenkins job), we get broken networking,
so e.g. `vagrant up debian-bookworm doesn't work.

This is caused by /etc/network/interfaces (using e.g. "neth0", being our
naming schema which we use in NGCP, as adjusted by the deployment
script) not matching the actual system network devices (like enp0s3).

TL;DR: no behavior change for NGCP systems, only when building non-NGCP
systems then enable net.ifnames=0 (via set_custom_grub_boot_options),
but do *not* generate /etc/udev/rules.d/70-persistent-net.rules (via
invoke generate_udev_network_rules) nor rename eth*->neth* in
/etc/network/interfaces.

More verbose version:

* rename the "eth*" networking interfaces into "neth*" in
  /etc/network/interfaces only when running in ngcp-installer mode
  (this is the behavior we rely on in NGCP, but it doesn't matter
  for plain Debian systems)

* generate /etc/udev/rules.d/70-persistent-net.rules only when running
  in ngcp-installer mode.  While our jenkins-configs.git's
  jobs/daily-build/scripts/vm_clean-fs.sh removes the file anyways (for
  the VM use case), between the initial deployment run and the next reboot
  the configuration inside the PVE VM still applies, so we end up with
  an existing /etc/udev/rules.d/70-persistent-net.rules, referring to
  neth0, while our /etc/network/interfaces configures eth0 instead.

* when *not* running in ngcp-installer mode, enable net.ifnames=0 usage
  in GRUB to disable persistent network interface naming. FTR, this
  change is *not* needed for NGCP, as on NGCP systems we use
  /etc/udev/rules.d/70-persistent-net.rules, generated by
  ngcp-system-tools' ngcp-initialize-udev-rules-net script also in VM
  use case

This is a fixup for a change in git commit a50903a30c (see also commit
message of git commit ab62171), that should have been adjusted for
ngcp-installer-only mode instead.

Change-Id: I6d0021dbdc2c1587127f0e115c6ff9844460a761
mr11.2.1
Michael Prokop 2 years ago
parent d44bcef4e6
commit ae7db13232

@ -1304,6 +1304,53 @@ puppet_install_from_puppet() {
return 0
}
set_custom_grub_boot_options() {
echo "Adjusting default GRUB boot options (enabling net.ifnames=0)"
sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 net.ifnames=0"/' "${TARGET}/etc/default/grub"
echo "Invoking update-grub"
grml-chroot "${TARGET}" update-grub
if [ -d "${TARGET}/etc/.git" ]; then
echo "Commit /etc/default/grub changes using etckeeper"
grml-chroot "${TARGET}" etckeeper commit "/etc/default/grub changes"
fi
}
generate_udev_network_rules() {
# get list of available network devices
# (excl. some known-to-be-irrelevant ones, also see MT#8297)
NETWORK_DEVICES="$(tail -n +3 /proc/net/dev | sed -r 's/^ *([0-9a-zA-Z]+):.*$/\1/g' | \
grep -ve '^vmnet' -ve '^vboxnet' -ve '^docker' -ve '^usb' -ve '^vlan' -ve '^bond' | sort -u)"
echo "Generating udev persistent net rules."
TARGET_UDEV_PERSISTENT_NET_RULES="${TARGET}/etc/udev/rules.d/70-persistent-net.rules"
echo "## Generated by Sipwise deployment script" > "${TARGET_UDEV_PERSISTENT_NET_RULES}"
for dev in ${NETWORK_DEVICES}; do
[[ "${dev}" =~ ^lo ]] && continue
pciid=$(ethtool -i "${dev}" | awk '/^bus-info: / {print $2}')
if [[ "${pciid}" =~ ^([0-9a-fA-F:.-])+$ ]]; then
dev_name_new="n${dev}"
echo "Adding device '${dev}' with PCIID '${pciid}', dev_name_new=${dev_name_new}"
cat >> "${TARGET_UDEV_PERSISTENT_NET_RULES}" <<EOL
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", KERNELS=="${pciid}", NAME="${dev_name_new}"
EOL
else
echo "WARNING: could not find valid PCIID '${pciid}' for device '${dev}'"
fi
unset pciid
done
echo "Content of resulting /etc/udev/rules.d/70-persistent-net.rules:"
cat "${TARGET_UDEV_PERSISTENT_NET_RULES}"
# Rename existing network devices at this time, to use the new names "neth*"
# when creating config_deploy.inc later
NETWORK_DEVICES="${NETWORK_DEVICES//eth/neth}"
}
# Main script
INSTALL_LOG='/tmp/deployment-installer-debug.log'
@ -2169,37 +2216,15 @@ ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
# get list of available network devices
# (excl. some known-to-be-irrelevant ones, also see MT#8297)
NETWORK_DEVICES="$(tail -n +3 /proc/net/dev | sed -r 's/^ *([0-9a-zA-Z]+):.*$/\1/g' | \
grep -ve '^vmnet' -ve '^vboxnet' -ve '^docker' -ve '^usb' -ve '^vlan' -ve '^bond' | sort -u)"
echo "Generating udev persistent net rules."
TARGET_UDEV_PERSISTENT_NET_RULES="${TARGET}/etc/udev/rules.d/70-persistent-net.rules"
echo "## Generated by Sipwise deployment script" > "${TARGET_UDEV_PERSISTENT_NET_RULES}"
for dev in ${NETWORK_DEVICES}; do
[[ "${dev}" =~ ^lo ]] && continue
pciid=$(ethtool -i "${dev}" | awk '/^bus-info: / {print $2}')
if [[ "${pciid}" =~ ^([0-9a-fA-F:.-])+$ ]]; then
dev_name_new="n${dev}"
echo "Adding device '${dev}' with PCIID '${pciid}', dev_name_new=${dev_name_new}"
cat >> "${TARGET_UDEV_PERSISTENT_NET_RULES}" <<EOL
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", KERNELS=="${pciid}", NAME="${dev_name_new}"
EOL
else
echo "WARNING: could not find valid PCIID '${pciid}' for device '${dev}'"
fi
unset pciid
done
# Rename existing network devices at this time, to use the new names "neth*"
# when creating config_deploy.inc later
NETWORK_DEVICES="${NETWORK_DEVICES//eth/neth}"
if ! "$NGCP_INSTALLER" ; then
set_custom_grub_boot_options
fi
if "$NGCP_INSTALLER" ; then
set_deploy_status "ngcp-installer"
generate_udev_network_rules
echo "Searching for proper ngcp-installer package ..."
get_installer_path
@ -2285,15 +2310,15 @@ EOT
if [ -r /tmp/grml-debootstrap.log ] ; then
cp /tmp/grml-debootstrap.log "${TARGET}"/var/log/
fi
fi
# network interfaces need to be renamed eth*->neth* with mr9.5 / Debian
# bullseye, and not left with grml-bootstrap defaults
echo "Renaming eth*->neth* in /etc/network/interfaces ..."
sed -i '/eth[0-9]/ s|eth|neth|g' "${TARGET}/etc/network/interfaces"
echo "Content of resulting /etc/network/interfaces:"
tail -v -n +0 "${TARGET}/etc/network/interfaces"
echo "========"
# network interfaces need to be renamed eth*->neth* with mr9.5 / Debian
# bullseye, and not left with grml-bootstrap defaults
echo "Renaming eth*->neth* in /etc/network/interfaces ..."
sed -i '/eth[0-9]/ s|eth|neth|g' "${TARGET}/etc/network/interfaces"
echo "Content of resulting /etc/network/interfaces:"
tail -v -n +0 "${TARGET}/etc/network/interfaces"
echo "========"
fi
if [[ -n "${MANAGEMENT_IP}" ]] && "${RETRIEVE_MGMT_CONFIG}" ; then
echo "Retrieving public key from management node"

Loading…
Cancel
Save