From 1ce9b85e3cc02b2461778a66fc7d83bed13510be Mon Sep 17 00:00:00 2001 From: lguohan Date: Mon, 6 Nov 2017 23:40:27 -0800 Subject: [PATCH] [init]: save the initial switch mac to config db (#1125) * [init]: save the initial switch mac to config db Save the initial switch mac to config db DEVICE_METADATA|localhost entry. * update sonic-swss submodule --- files/build_templates/swss.service.j2 | 1 + .../interfaces/interfaces-config.sh | 15 +------ files/image_config/platform/rc.local | 44 ++++++++++++++----- src/sonic-swss | 2 +- src/sonic-utilities | 2 +- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/files/build_templates/swss.service.j2 b/files/build_templates/swss.service.j2 index 74fafb0037..ad52f395d0 100644 --- a/files/build_templates/swss.service.j2 +++ b/files/build_templates/swss.service.j2 @@ -18,6 +18,7 @@ ExecStartPre=/usr/bin/docker exec database redis-cli -n 0 FLUSHDB ExecStartPre=/usr/bin/docker exec database redis-cli -n 1 FLUSHDB ExecStartPre=/usr/bin/docker exec database redis-cli -n 2 FLUSHDB ExecStartPre=/usr/bin/docker exec database redis-cli -n 5 FLUSHDB +ExecStartPre=/usr/bin/docker exec database redis-cli -n 6 FLUSHDB {% if sonic_asic_platform == 'mellanox' %} TimeoutStartSec=3min diff --git a/files/image_config/interfaces/interfaces-config.sh b/files/image_config/interfaces/interfaces-config.sh index 28396774bf..06174790f0 100755 --- a/files/image_config/interfaces/interfaces-config.sh +++ b/files/image_config/interfaces/interfaces-config.sh @@ -1,19 +1,6 @@ #!/bin/bash -SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) -SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') - -# Align last byte of MAC if necessary -if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then - last_byte=$(python -c "print '$SYSTEM_MAC_ADDRESS'[-2:]") - aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix - SYSTEM_MAC_ADDRESS=$(python -c "print '$SYSTEM_MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC -fi - -sonic-cfggen -d -a '{"hwaddr":"'$SYSTEM_MAC_ADDRESS'"}' -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces - -# Also store the system mac to configDB switch table. User configured switch_mac is not supported for now. -/usr/bin/docker exec database redis-cli -n 4 hset SWITCH\|SWITCH_ATTR switch_mac $SYSTEM_MAC_ADDRESS +sonic-cfggen -d -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces [ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid diff --git a/files/image_config/platform/rc.local b/files/image_config/platform/rc.local index d3ecba7d85..daeccfd524 100755 --- a/files/image_config/platform/rc.local +++ b/files/image_config/platform/rc.local @@ -43,6 +43,15 @@ firsttime_exit() exit 0 } +test_config() +{ + if [ -d /host/old_config ] && ( [ -f /host/old_config/minigraph.xml ] || [ -f /host/old_config/config_db.json ] ); then + return 0 + fi + + return 1 +} + # Given a string of tuples of the form field=value, extract the value for a field # In : $string, $field # Out: $value @@ -70,26 +79,39 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then firsttime_exit fi + # setup initial switch mac + SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) + SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') + + # Align last byte of MAC if necessary + if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then + last_byte=$(python -c "print '$SYSTEM_MAC_ADDRESS'[-2:]") + aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix + SYSTEM_MAC_ADDRESS=$(python -c "print '$SYSTEM_MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC + fi + + if [ -f /etc/sonic/init_cfg.json ]; then + sonic-cfggen -j /etc/sonic/init_cfg.json -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json + else + sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json + fi + # Try to take old configuration saved during installation - if [ -d /host/old_config ]; then + if test_config; then rm -f /host/old_config/sonic_version.yml mv -f /host/old_config/* /etc/sonic/ + if [ ! -f /etc/sonic/config_db.json ]; then + sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json + fi elif [ -f /host/minigraph.xml ]; then mv /host/minigraph.xml /etc/sonic/ # 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 - if [ -f /etc/sonic/init_cfg.json ]; then - sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json - else - sonic-cfggen -m --print-data > /etc/sonic/config_db.json - fi + sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json else + # Use default minigraph.xml cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/ - if [ -f /etc/sonic/init_cfg.json ]; then - sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json - else - sonic-cfggen -m --print-data > /etc/sonic/config_db.json - fi + sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json fi if [ -d /host/image-$sonic_version/platform/$platform ]; then diff --git a/src/sonic-swss b/src/sonic-swss index b641aeeac3..5da255c78c 160000 --- a/src/sonic-swss +++ b/src/sonic-swss @@ -1 +1 @@ -Subproject commit b641aeeac349462dd3e3e370bfc55f16602c937f +Subproject commit 5da255c78cb5d02a49b0a5299764c325ed0bdc32 diff --git a/src/sonic-utilities b/src/sonic-utilities index 1d37c9c199..0a720caa01 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 1d37c9c199b7934653f907095bf11e685889df23 +Subproject commit 0a720caa0101ebbd38309c97d4069e2545bc3259