-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support OS9 -> SONiC fast-reboot migration #1414
Changes from 1 commit
2a577b8
5a806b8
71572c5
68efae0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,18 @@ | |
|
||
set -e | ||
|
||
function fast_migration { | ||
if [[ -f /etc/sonic/migration/fdb.json ]]; | ||
then | ||
cp /etc/sonic/migration/fdb.json /fdb.json | ||
fi | ||
|
||
if [[ -f /etc/sonic/migration/arp.json ]]; | ||
then | ||
cp /etc/sonic/migration/arp.json /arp.json | ||
fi | ||
} | ||
|
||
function fast_reboot { | ||
case "$(cat /proc/cmdline)" in | ||
*fast-reboot*) | ||
|
@@ -29,6 +41,9 @@ function fast_reboot { | |
esac | ||
} | ||
|
||
# If we are migrating, import the dumps from the previous NOS | ||
fast_migration | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to change this file. See my comments below |
||
# Restore FDB and ARP table ASAP | ||
fast_reboot | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,16 @@ | |
# | ||
# By default this script does nothing. | ||
|
||
# In case the unit is migrating from another NOS, save the logs | ||
log_migration() { | ||
echo $1 >> /etc/migration.log | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to save it to /var/log? |
||
} | ||
|
||
# Import files from another NOS's partition onto SONiC | ||
nos_migration_import() { | ||
[ -f $1 ] && cp $1 $2 || log_migration "ERROR: $1 not found!" | ||
} | ||
|
||
# If the machine.conf is absent, it indicates that the unit booted | ||
# into SONiC from another NOS. Extract the machine.conf from ONIE. | ||
if [ ! -e /host/machine.conf ]; then | ||
|
@@ -20,7 +30,7 @@ if [ ! -e /host/machine.conf ]; then | |
onie_grub_cfg=/mnt/onie-boot/onie/grub/grub-machine.cfg | ||
|
||
if [ ! -e $onie_grub_cfg ]; then | ||
echo "$onie_grub_cfg not found" >> /etc/migration.log | ||
log_migration "$onie_grub_cfg not found" | ||
else | ||
. ./$onie_grub_cfg | ||
grep = $onie_grub_cfg | sed -e 's/onie_//' -e 's/=.*$//' | while read var ; do | ||
|
@@ -29,8 +39,60 @@ if [ ! -e /host/machine.conf ]; then | |
done | ||
fi | ||
|
||
# Extract the previous NOS's partition that contains the migration artifacts | ||
set -- $(cat /proc/cmdline) | ||
for x in "$@"; do | ||
case "$x" in | ||
nos-config-part=*) | ||
nos_val="${x#nos-config-part=}" | ||
;; | ||
esac | ||
done | ||
|
||
if [ -n "$nos_val" ]; then | ||
nos_dev=$(findfs $nos_val) | ||
if [ $? != 0 ]; then | ||
log_migration "ERROR: nos_dev not found. Check grub parameters" | ||
fi | ||
else | ||
log_migration "ERROR: nos_val not found. Check grub parameters" | ||
fi | ||
|
||
if [ -n "$nos_dev" ]; then | ||
# Mount the previous NOS's partition | ||
mkdir -p /mnt/nos_migration | ||
mount $nos_dev /mnt/nos_migration | ||
mkdir -p /etc/sonic/migration | ||
|
||
# Copy relevant files | ||
nos_migration_import /mnt/nos_migration/minigraph.xml /etc/sonic/migration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could import the entire bunch of files 1 shot - but this is just to ensure we know what we are importing. |
||
nos_migration_import /mnt/nos_migration/arp.json /etc/sonic/migration | ||
nos_migration_import /mnt/nos_migration/fdb.json /etc/sonic/migration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add support for default routes in default_routes.json. |
||
nos_migration_import /mnt/nos_migration/mgmt_interface.mac /etc/sonic/migration | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please put your files into /host/fast-reboot directory? In this case you don't need any changes in swssconfig.sh |
||
umount /mnt/nos_migration | ||
rmdir /mnt/nos_migration | ||
fi | ||
|
||
# Extract, validate and set the eth0's mac address | ||
if [ -f /etc/sonic/migration/mgmt_interface.mac ]; then | ||
eth0_mac=$(grep "macaddr" /etc/sonic/migration/mgmt_interface.mac | awk -F'=' '{print $2}') | ||
log_migration "Setting eth0 mac as $eth0_mac." | ||
if [ `echo $eth0_mac | egrep "^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"` ]; then | ||
ifconfig eth0 down | ||
ip link set eth0 address $eth0_mac | ||
ifconfig eth0 up | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use iptools2 commands |
||
rm /etc/sonic/migration/mgmt_interface.mac | ||
else | ||
log_migration "ERROR: $eth0_mac: invalid MAC!" | ||
fi | ||
fi | ||
|
||
migration="TRUE" | ||
umount /mnt/onie-boot | ||
else | ||
# this is a reboot post NOS migration : remove stale imported files that were used during migration. | ||
rm -fr /etc/sonic/migration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, we could remove the arp.json & fdb.json after checking that orchagent initialized but removing here localizes the migration changes to rc.local. |
||
fi | ||
|
||
. /host/machine.conf | ||
|
@@ -96,6 +158,10 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then | |
# Combine information in minigraph and init_cfg.json to form initiate config DB dump file. | ||
# TODO: After moving all information from minigraph to DB, sample config DB dump should be provide | ||
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json | ||
elif [ -n "$migration" ] && [ -f /etc/sonic/migration/minigraph.xml ]; then | ||
# Use the minigraph that was imported from the NOS | ||
mv /etc/sonic/migration/minigraph.xml /etc/sonic/ | ||
sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -H -m -j |
||
else | ||
# Use default minigraph.xml | ||
cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/ | ||
|
@@ -127,26 +193,26 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then | |
|
||
grub_bin=$(ls /host/image-$sonic_version/platform/x86_64-grub/grub-pc-bin*.deb 2> /dev/null) | ||
if [ -z "$grub_bin" ]; then | ||
echo "Unable to locate grub package !" >> /etc/migration.log | ||
log_migration "Unable to locate grub package !" | ||
firsttime_exit | ||
fi | ||
|
||
dpkg -i $grub_bin > /dev/null 2>&1 | ||
if [ $? != 0 ]; then | ||
echo "Unable to install grub package !" >> /etc/migration.log | ||
log_migration "Unable to install grub package !" | ||
firsttime_exit | ||
fi | ||
|
||
# Determine the block device to install grub | ||
sonic_dev=$(blkid | grep SONiC-OS | head -n 1 | awk '{print $1}' | sed -e 's/[0-9]:.*$//') | ||
if [ -z "$sonic_dev" ]; then | ||
echo "Unable to determine sonic partition !" >> /etc/migration.log | ||
log_migration "Unable to determine sonic partition !" | ||
firsttime_exit | ||
fi | ||
|
||
grub-install --boot-directory=/host --recheck $sonic_dev 2>/dev/null | ||
if [ $? != 0 ]; then | ||
echo "grub install failed !" >> /etc/migration.log | ||
log_migration "grub install failed !" | ||
firsttime_exit | ||
fi | ||
|
||
|
@@ -163,7 +229,7 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then | |
if [ ! -z "$console_port" ] && [ "$console_port" != "$CONSOLE_PORT" ]; then | ||
sed -i -e "s/\-\-port=$console_port/\-\-port=$CONSOLE_PORT/g" /host/grub.cfg | ||
fi | ||
echo "grub.cfg console port=$console_port & installer.conf CONSOLE_PORT=$CONSOLE_PORT" >> /etc/migration.log | ||
log_migration "grub.cfg console port=$console_port & installer.conf CONSOLE_PORT=$CONSOLE_PORT" | ||
fi | ||
|
||
if [ ! -z "$CONSOLE_DEV" ]; then | ||
|
@@ -175,7 +241,7 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then | |
if [ "$console_dev" != "$CONSOLE_DEV" ]; then | ||
sed -i -e "s/console=ttyS$console_dev/console=ttyS$CONSOLE_DEV/g" /host/grub.cfg | ||
fi | ||
echo "grub.cfg console dev=$console_dev & installer.conf CONSOLE_DEV=$CONSOLE_DEV" >> /etc/migration.log | ||
log_migration "grub.cfg console dev=$console_dev & installer.conf CONSOLE_DEV=$CONSOLE_DEV" | ||
fi | ||
|
||
if [ ! -z "$VAR_LOG_SIZE" ]; then | ||
|
@@ -186,7 +252,7 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then | |
if [ ! -z "$var_log_size" ] && [ "$var_log_size" != "$VAR_LOG_SIZE" ]; then | ||
sed -i -e "s/var_log_size=$var_log_size/var_log_size=$VAR_LOG_SIZE/g" /host/grub.cfg | ||
fi | ||
echo "grub.cfg var_log_size=$var_log_size & installer.conf VAR_LOG_SIZE=$VAR_LOG_SIZE" >> /etc/migration.log | ||
log_migration "grub.cfg var_log_size=$var_log_size & installer.conf VAR_LOG_SIZE=$VAR_LOG_SIZE" | ||
fi | ||
|
||
# Set the root based on the label | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we are not going to disable dhcp globally? the dhcp is disabled only from ftos to sonic fast-boot migration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the earlier thought. But I could not disable this during migration since squashfs is readonly... So, changed the approach. Note that with this change, though we disable dhcp globally during the build, if there is no IP configured in the minigraph, the interfaces-config.sh would override the startup /etc/network/interfaces with a config that is set to dhcp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you do not need to change squash fs, you can change the entry after you have mounted the union fs.