diff --git a/dockers/docker-orchagent/swssconfig.sh b/dockers/docker-orchagent/swssconfig.sh index 4c8c1f8b4c..276132a7ef 100755 --- a/dockers/docker-orchagent/swssconfig.sh +++ b/dockers/docker-orchagent/swssconfig.sh @@ -39,7 +39,10 @@ rm -f /ready # Restore FDB and ARP table ASAP fast_reboot -HWSKU=`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['hwsku']"` +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + +HWSKU=${HWSKU:-`sonic-cfggen -d -v "DEVICE_METADATA['localhost']['hwsku']"`} # Don't load json config if system warm start or # swss docker warm start is enabled, the data already exists in appDB. diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index e5431ad62c..50df816258 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -168,7 +168,7 @@ start() { BOOT_TYPE=`getBootType` # Obtain our platform as we will mount directories with these names in each docker - PLATFORM=`$SONIC_CFGGEN -H -v DEVICE_METADATA.localhost.platform` + PLATFORM=${PLATFORM:-`$SONIC_CFGGEN -H -v DEVICE_METADATA.localhost.platform`} # Parse the device specific asic conf file, if it exists ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf @@ -181,7 +181,7 @@ start() { HWSKU="" {%- else %} # Obtain our HWSKU as we will mount directories with these names in each docker - HWSKU=`$SONIC_CFGGEN -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + HWSKU=${HWSKU:-`$SONIC_CFGGEN -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'`} {%- endif %} DOCKERCHECK=`docker inspect --type container {{docker_container_name}}$DEV 2>/dev/null` @@ -369,6 +369,9 @@ if [ "$DEV" ]; then SONIC_DB_CLI="sonic-db-cli" fi +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + case "$1" in start|wait|stop) $1 diff --git a/files/image_config/config-setup/config-setup b/files/image_config/config-setup/config-setup index 1f95a10bb0..d3860caf7c 100755 --- a/files/image_config/config-setup/config-setup +++ b/files/image_config/config-setup/config-setup @@ -208,7 +208,7 @@ load_config() generate_config() { # Collect all information needed to generate configuration - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} PRESET=(`head -n 1 /usr/share/sonic/device/$PLATFORM/default_sku`) HW_KEY=${PRESET[0]} DEFAULT_PRESET=${PRESET[1]} @@ -403,8 +403,11 @@ boot_config() fi } +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + ### Execution starts here ### -PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` +PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} # Parse the device specific asic conf file, if it exists ASIC_CONF=/usr/share/sonic/device/$PLATFORM/asic.conf if [[ -f "$ASIC_CONF" ]]; then diff --git a/files/image_config/platform/rc.local b/files/image_config/platform/rc.local index 2cf5056f04..e795ef8901 100755 --- a/files/image_config/platform/rc.local +++ b/files/image_config/platform/rc.local @@ -11,9 +11,17 @@ # # By default this script does nothing. -SONIC_VERSION=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version) +SONIC_VERSION=$(cat /etc/sonic/sonic_version.yml | grep "build_version" | sed -e "s/build_version: //g;s/'//g") FIRST_BOOT_FILE="/host/image-${SONIC_VERSION}/platform/firsttime" +# Move sonic-environment to /etc/sonic +SONIC_CONFIG_DIR="/host/image-${SONIC_VERSION}/sonic-config" +SONIC_ENV_FILE=${SONIC_CONFIG_DIR}/sonic-environment +if [ -d ${SONIC_CONFIG_DIR} -a -f ${SONIC_ENV_FILE} ]; then + echo "moving file ${SONIC_ENV_FILE} to /etc/sonic" 1>&2 + mv ${SONIC_ENV_FILE} /etc/sonic +fi + # In case the unit is migrating from another NOS, save the logs log_migration() { echo $1 >> /host/migration/migration.log diff --git a/files/image_config/topology/topology.sh b/files/image_config/topology/topology.sh index dde7da2474..aba7565c82 100755 --- a/files/image_config/topology/topology.sh +++ b/files/image_config/topology/topology.sh @@ -7,17 +7,20 @@ start() { TOPOLOGY_SCRIPT="topology.sh" - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` - HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} + HWSKU=${HWSKU:-`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'`} /usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT start } stop() { TOPOLOGY_SCRIPT="topology.sh" - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` - HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'` + PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} + HWSKU=${HWSKU:-`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'`} usr/share/sonic/device/$PLATFORM/$HWSKU/$TOPOLOGY_SCRIPT stop } +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + case "$1" in start|stop) $1 diff --git a/files/image_config/updategraph/updategraph b/files/image_config/updategraph/updategraph index 86ee8a800a..5c767b83d9 100755 --- a/files/image_config/updategraph/updategraph +++ b/files/image_config/updategraph/updategraph @@ -7,6 +7,9 @@ reload_minigraph() config save -y } +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + if [ ! -f /etc/sonic/updategraph.conf ]; then echo "No updategraph.conf found, generating a default one." echo "enabled=false" >/etc/sonic/updategraph.conf @@ -46,7 +49,7 @@ if [ "$src" = "dhcp" ]; then if [ "`cat /tmp/dhcp_graph_url`" = "N/A" ]; then echo "No graph_url option in DHCP response. Skipping graph update and generating an empty configuration." - PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform` + PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} if [ -f /etc/sonic/minigraph.xml ]; then sonic-cfggen -H -m /etc/sonic/minigraph.xml --preset empty > /tmp/device_meta.json else diff --git a/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/s6000_platform.sh b/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/s6000_platform.sh index 98fb13b152..f2e95f5130 100755 --- a/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/s6000_platform.sh +++ b/platform/broadcom/sonic-platform-modules-dell/s6000/scripts/s6000_platform.sh @@ -76,7 +76,7 @@ switch_board_qsfp_lpmode() { install_python_api_package() { device="/usr/share/sonic/device" - platform=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform) + platform=${PLATFORM:-`/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`} if [ -e $device/$platform/sonic_platform-1.0-py2-none-any.whl ]; then rv=$(pip install $device/$platform/sonic_platform-1.0-py2-none-any.whl) @@ -90,6 +90,9 @@ remove_python_api_package() { fi } +# read SONiC immutable variables +[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment + if [[ "$1" == "init" ]]; then depmod -a modprobe nvram