Merge "Add ostree_repo pull and setup networking for bootstrap"

This commit is contained in:
Zuul 2022-08-10 16:09:52 +00:00 committed by Gerrit Code Review
commit cd0c3171b5
1 changed files with 166 additions and 170 deletions

View File

@ -538,6 +538,119 @@ function get_std_controller_provisioning_sizes()
}
#########################################################################
# Name : setup_ip_addr
# Purpose : Setup IP addressing for two cases:
# 1) initial boot and 2) persistent across reboot
# Parameter: operation: one of 'initial' or 'persistent'
# Return : Nothing
#########################################################################
function setup_ip_addr()
{
local operation=\$1
ilog "Setting Network address: \$operation"
# Pull out the ip= line from /proc/cmdline:
local ipstring
for arg in \$(cat /proc/cmdline); do
case "\$arg" in
ip=*)
ipstring=\${arg:3}
ilog "Using ip=\$ipstring"
break
;;
esac
done
local ip_version=
local ipadd=
local gw=
local prefixlen=
local bootif=
local ipver=
local route_options=
local metric=
local dns=
# Now we have a string like:
# <client-ip>,,<gw-ip>,<prefixlen>,<hostname>,<device>,off,<dns0-ip>,<dns1-ip>
# 1 2 3 4 5 6 7 8 9
# identify if ipv4 or ipv6, and get the ip address
#
# 10.10.10.22,,10.10.10.1,23,subcloud2,enp2s1,none (for ipv4)
# [2620:10a:a001:d41::212],,,64,subcloud3,ens1f0.401,none (for ipv6)
ipadd=\$(echo \$ipstring | awk -F',' '{print \$1}' | tr -d '\[\]')
gw=\$(echo \$ipstring | awk -F',' '{print \$3}')
prefixlen=\$(echo \$ipstring | awk -F',' '{print \$4}')
hostname=\$(echo \$ipstring | awk -F',' '{print \$5}')
bootif=\$(echo \$ipstring | awk -F',' '{print \$6}')
# Do not setup DNS for now - we use IP addresses during boot:
# dns=\$(echo \$ipstring | awk -F',' '{print \$8}')
case "\$ipstring" in
*'['*)
# if has [ ] then it is ipv6:
ip_version="ipv6"
ipver="-6"
metric="metric 1"
;;
*)
ip_version="ipv4"
route_options="via \$gw"
;;
esac
ilog "Using IP values: ip_version:\$ip_version ip:\$ipadd /\$prefixlen, gw:\$gw"
if [ "\$operation" = "initial" ]; then
if [ "\$ip_version" = "ipv4" ]; then
echo ip \${ipver} address add \${ipadd}/\${prefixlen} dev \${bootif}
ip \${ipver} address add \${ipadd}/\${prefixlen} dev \${bootif}
else
echo ip \${ipver} address add \${ipadd} dev \${bootif}
ip \${ipver} address add \${ipadd} dev \${bootif}
fi
sleep 15
echo ip \${ipver} link set dev \${bootif} up
ip \${ipver} link set dev \${bootif} up
echo ip \${ipver} route add default \${route_options} dev \${bootif} \${metric}
ip \${ipver} route add default \${route_options} dev \${bootif} \${metric}
ilog "ip addr:"
ip addr show
ilog "ip route:"
ip \${ipver} route show
# get the nameserver
local dns="none"
for e in \${dns}; do
echo "nameserver \${e}" > /etc/resolv.conf
done
elif [ "\$operation" = "persistent" ]; then
ilog "Creating /etc/network/interfaces.d/ifcfg-\$bootif"
if [ "\$ip_version" == "ipv4" ]; then
cat <<FUNC_EOF > /etc/network/interfaces.d/ifcfg-\$bootif
auto \$bootif
iface \$bootif inet static
address \$ipadd
netmask 255.255.255.0
gateway \$gw
mtu 1500
FUNC_EOF
else
cat <<FUNC_EOF > /etc/network/interfaces.d/ifcfg-\$bootif
auto \$bootif
iface \$bootif inet6 static
address \$ipadd
netmask \$prefixlen
FUNC_EOF
fi
ilog "Contents of /etc/network/interfaces.d/ifcfg-\$bootif"
cat "/etc/network/interfaces.d/ifcfg-\$bootif"
fi
}
##########################################################################
# Global Kickstart Constants #
##########################################################################
@ -706,26 +819,6 @@ function check_execs()
return ${missing_exec}
}
# TODO: Remove this function. LAT should be setting the IP address.
#
function set_nw_add_ipv4()
{
ilog "Setting Network IPV4 address"
set -- `cat /proc/cmdline`
ipstring=$(echo $* | xargs -n 1 | awk '/ip/ {print}' | awk -F'=' '{print $2}')
ipadd=$(echo ${ipstring} | awk -F':' '{print $1}')
gw=$(echo ${ipstring} | awk -F':' '{print $3}')
bootif=$(echo ${ipstring} | awk -F':' '{print $6}')
dlog "IPSTRING IS ${ipstring}"
dlog "IP=${ipadd} gw=${gw} bootif=${bootif}"
ip address add ${ipadd}/24 dev ${bootif}
ip link set dev ${bootif} up
ip route add default via ${gw} dev ${bootif}
echo "nameserver 128.244.144.130" > /etc/resolv.conf
ip route show
sleep 15
}
# Log Traits
[ "${controller}" = true ] && ilog "Controller Function"
[ "${storage}" = true ] && ilog "Storage Function"
@ -761,7 +854,6 @@ HOOK_LABEL="pre-part"
#####################################################
# From pre_disk_setup_common.cfg
#####################################################
set_nw_add_ipv4
if [ -n "$INSTDEV" ] ; then
instdev_by_path=$(get_by_path $INSTDEV)
@ -1387,6 +1479,20 @@ pvscan --cache 2>/dev/null
true
%end
#####################################################################
%pre-part --interpreter=/bin/bash
HOOK_LABEL="pre-part"
. /tmp/lat/ks_functions.sh
ilog "****************************************************"
ilog "**** Pre-part - provision IP address (initial) **"
ilog "****************************************************"
setup_ip_addr initial
true
%end
###########################################################################
%post --interpreter=/bin/bash
@ -1521,6 +1627,14 @@ true
%post --interpreter=/bin/bash
HOOK_LABEL="post"
. /tmp/lat/ks_functions.sh
ilog "****************************************************"
ilog "*** Post - Persistent Interface Setup ***"
ilog "****************************************************"
ilog "Setting up /etc/network/interfaces"
setup_ip_addr persistent
ilog "****************************************************"
ilog "*** Post - Set Kernel Args ****"
ilog "****************************************************"
@ -1766,162 +1880,41 @@ true
###########################################################################
%post --interpreter=/bin/bash
HOOK_LABEL="post"
%post --interpreter=/bin/bash --nochroot
HOOK_LABEL="post_nochroot"
. /tmp/lat/ks_functions.sh
ilog "****************************************************"
ilog "*** Post - Interface Setup ***"
ilog "****************************************************"
###########################################################
# From post_pxeboot_controller
# From post_net_common.cfg
# From post_miniboot_controller.cfg
###########################################################
# TODO: Not needed on a USB install.
# TODO: Need to adjust fault handling or condition on USB install.
ilog "Local Install Check"
# Obtain the boot interface from the PXE boot
BOOTIF=$(cat /proc/cmdline |xargs -n1 echo |grep BOOTIF=)
BOOTIF=${BOOTIF#BOOTIF=}
mgmt_dev=lo
mgmt_vlan=0
if [ -n "$BOOTIF" ] ; then
BOOTIF=$(echo $BOOTIF | sed -r -e 's/.*(..-..-..-..-..-..)$/\1/' -e 's/-/:/g')
ndev=`ip link show |grep -B 1 $BOOTIF |head -1 |awk '{print $2}' |sed -e 's/://'`
if [ -n "$ndev" ] ; then
# convert to predictive name
mgmt_dev=$(get_iface_from_ethname $ndev)
if [ "${mgmt_dev}" == "" ] ; then
elog "failed to get predictive altname from ${ndev}"
mgmt_dev=${ndev}
# TODO: this is a second pull, which should be avoided.
# Remove this second pull and look at a single solution
# where the archive is stored first and then installed.
#
if [ "${controller}" = true ] ; then
# Note: this is updated by the build:
sw_release="xxxPLATFORM_RELEASExxx"
feed="${IMAGE_ROOTFS}/var/www/pages/feed/rel-${sw_release}"
repo="${feed}/ostree_repo"
if [ ! -d "$repo" ]; then
mkdir -p "${repo}"
# get vlan info for system node installs
system_node=$(is_system_node_install)
if [ "${system_node}" = true ] ; then
# Retrieve the management VLAN from sysinv if it exists
ilog "Querying system inventory for management vlan id"
mgmt_vlan=`curl -sf http://pxecontroller:6385/v1/isystems/mgmtvlan`
if [ ${?} -ne 0 ] ; then
# TODO: uncomment to force install failure for product
# report_failure_with_msg "Unable to communicate with System Inventory REST API. Aborting installation."
wlog "ERROR: Unable to communicate with System Inventory REST API."
fi
fi
ilog "Initializing ostree repo at: $repo"
# get the remote installation details
ostree --repo=${repo} init --mode=archive
if [ "${insturl}" = "file://NOT_SET" ] ; then
ostree --repo=${repo} remote add ${instbr} file:///instboot/ostree_repo
else
ilog "Management Interface: ${ndev} -> ${mgmt_dev}"
ostree --repo=${repo} remote add ${instbr} ${insturl}
fi
else
elog "ERROR:POST: Unable to determine mgmt interface from BOOTIF=$BOOTIF."
# TODO: MAKE Default - Should not get here without BOOTIF set ; LAT guarantees that.
# report_failure_with_msg "Unable to determine mgmt interface from BOOTIF=$BOOTIF."
ilog "Populating: ostree --repo=${repo} pull --mirror ${instbr}:${instbr}"
ostree --repo=${repo} pull --mirror ${instbr}:${instbr}
fi
else
elog "ERROR:POST: BOOTIF is not set. Unable to determine mgmt interface."
# TODO: MAKE Default - Should not get here without BOOTIF set ; LAT guarantees that.
fi
if [ ! -e "/etc/network/interfaces" ] ; then
cat << EOF >> /etc/network/interfaces
# This file describes the network interfaces available on the system
# and how to activate them. For more information , see interfaces(5)
source /etc/network/interfaces.d/*
EOF
fi
if [ ! -d "/etc/network/interfaces.d" ] ; then
mkdir -p -m 0775 /etc/network/interfaces.d
fi
# Build networking scripts, starting with the localhost interface
cat << EOF >> /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
EOF
if [ $mgmt_dev != "lo" ]; then
cat << EOF >> /etc/network/interfaces
# management network interface
allow-hotplug $mgmt_dev
auto $mgmt_dev
iface $mgmt_dev inet dhcp
EOF
fi
ilog "Setup network scripts"
if [ $mgmt_vlan -eq 0 ] ; then
# Persist the boot device to the platform configuration. This will get
# overwritten later if the management_interface is on a bonded interface.
update_platform_conf "management_interface=$mgmt_dev"
# Build networking scripts
cat << EOF > /etc/network/interfaces.d/ifcfg-lo
auto lo
iface lo inet static
address 127.0.0.1
netmask 255.0.0.0
post-up echo 0 > /proc/sys/net/ipv6/conf/lo/autoconf; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_redirects
EOF
cat << EOF > /etc/network/interfaces.d/ifcfg-$mgmt_dev
auto $mgmt_dev
iface $mgmt_dev inet manual
pre-up sleep 20
post-up echo 0 > /proc/sys/net/ipv6/conf/lo/autoconf; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_redirects
EOF
else
# Check whether to use inet or inet6
ipv6_addr=$(dig +short AAAA controller)
if [[ -n "$ipv6_addr" ]]
then
mgmt_address_family=inet6
ipv6init=yes
dhcpv6c=yes
dhclientargs=-1
else
mgmt_address_family=inet
ipv6init=no
dhcpv6c=no
dhclientargs=
fi
# Persist the boot device to the platform configuration. This will get
# overwritten later if the management_interface is on a bonded interface.
update_platform_conf "management_interface=vlan$mgmt_vlan"
# Build networking scripts
cat << EOF > /etc/network/interfaces.d/ifcfg-lo
auto lo
iface lo $mgmt_address_family static
address 127.0.0.1
netmask 255.0.0.0
post-up echo 0 > /proc/sys/net/ipv6/conf/lo/autoconf; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_redirects
EOF
cat << EOF > /etc/network/interfaces.d/ifcfg-$mgmt_dev
auto $mgmt_dev
iface $mgmt_dev $mgmt_address_family manual
pre-up sleep 20
post-up echo 0 > /proc/sys/net/ipv6/conf/lo/autoconf; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_redirects
EOF
cat << EOF > /etc/network/interfaces.d/ifcfg-vlan$mgmt_vlan
auto vlan$mgmt_vlan
iface vlan$mgmt_vlan $mgmt_address_family dhcp
vlan-raw-device $mgmt_dev
pre-up sleep 20
post-up echo 0 > /proc/sys/net/ipv6/conf/lo/autoconf; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_redirects
EOF
fi
true
@ -1945,12 +1938,15 @@ ilog "Add install uuid to feed and platform.conf"
if [ -e "${LAT_DIR}/INSTALL_UUID" ]; then
INSTALL_UUID=$(< "${LAT_DIR}/INSTALL_UUID")
else
INSTALL_UUID=`uuidgen`
INSTALL_UUID=$(uuidgen)
echo "${INSTALL_UUID}" > ${LAT_DIR}/INSTALL_UUID
fi
[ ! -d "/var/www/pages/feed/rel-22.06" ] && mkdir -p -m 0755 /var/www/pages/feed/rel-22.06
echo ${INSTALL_UUID} > /var/www/pages/feed/rel-22.06/install_uuid
# Note: this is updated by the build:
sw_release="xxxPLATFORM_RELEASExxx"
www_release_dir="/var/www/pages/feed/rel-${sw_release}"
[ -d "$www_release_dir" ] || mkdir -p -m 0755 "$www_release_dir"
echo "${INSTALL_UUID}" > "${www_release_dir}/install_uuid"
update_platform_conf "INSTALL_UUID=${INSTALL_UUID}"
true