Skip to content
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

modify syncd init script for supporting yml #1474

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions syncd/scripts/brcm_common_config_ut.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash
###BRCM Common config UT####
HWSKU_DIR=/usr/share/sonic/hwsku
PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common
PLT_SAI_PROFILE=$(find $HWSKU_DIR -name 'sai.profile')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geans-pin same sai.profile location issue for ut test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply the same change in the new commit for UT script

readline=$(grep SAI_INIT_CONFIG_FILE $PLT_SAI_PROFILE)
PLATFORM_DIR=/usr/share/sonic/platform
PLT_CONFIG_BCM=""
PLT_CONFIG_YML=""

if [ ${readline: -3} == "bcm" ]; then
PLT_CONFIG_BCM=${readline#*=}
elif [ ${readline: -3} == "yml" ]; then
PLT_CONFIG_YML=${readline#*=}
fi

if [ ! -z "$PLT_CONFIG_BCM" ] && [ -f $PLATFORM_DIR/common_config_support ] ; then
CONFIG_BCM=$(find /tmp -name '*.bcm')

#Get first three characters of chip id
readline=$(grep '0x14e4' /proc/linux-kernel-bde)
chip_id=${readline#*0x14e4:0x}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')
check_override=false
check_pass=false

#Check if common config does apply to config bcm correctly
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo "Skip checking line starting with #"
elif [ "$line" == "[High Inheritance Precedence]" ];then
echo "Checking High Inheritance property..."
check_override=true
elif [ "$line" == "[Low Inheritance Precedence]" ];then
echo "Checking Low Inheritance property..."
check_override=false
else
if $check_override ;then
if grep -q "$line" $CONFIG_BCM ;then
check_pass=true
else
echo "Fail: Checking overwite properties not existing.."
return
fi
else
sedline=${line%=*}
if grep -q $sedline $CONFIG_BCM ;then
check_pass=true
else
echo "Fail: Checking properties not existing.."
return
fi
fi
fi
fi
done < $COMMON_CONFIG_BCM
if $check_pass ;then
echo "PASS: Checking Common config merged Success"
fi
fi

if [ ! -z "$PLT_CONFIG_YML" ] && [ -f $PLATFORM_DIR/common_config_support ]; then
CONFIG_YML=$(find /tmp -name '*.yml')

#Get first three characters of chip id
readline=$(grep '0:14e4' /proc/linux_ngbde)
chip_id=${readline#*0:14e4:}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')
check_override=false
check_pass=false

#Check if common config does apply to config bcm correctly
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo "Skip checking line starting with #"
elif [ "$line" == "[High Inheritance Precedence]" ];then
echo "Checking High Inheritance property..."
check_override=true
elif [ "$line" == "[Low Inheritance Precedence]" ];then
echo "Checking Low Inheritance property..."
check_override=false
else
if $check_override ;then
if grep -q "$line" $CONFIG_YML ;then
check_pass=true
else
echo "Fail: Checking overwite properties not existing.."
check_pass=false
return
fi
else
sedline=${line%:*}
if grep -q $sedline $CONFIG_YML ;then
check_pass=true
else
echo "Fail: Checking properties not existing.."
check_pass=false
return
fi
fi
fi
fi
done < $COMMON_CONFIG_BCM

if $check_pass ;then
echo "PASS: Checking Common config merged Success"
fi

fi
237 changes: 175 additions & 62 deletions syncd/scripts/syncd_init_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,74 +122,188 @@ config_syncd_cisco_8000()
fi
}

config_syncd_bcm()
function merge_config_bcm_files()
{
to_file=$1
from_file=$2
message=$3
override=false
echo "" >> $to_file
echo "# Start of $message" >> $to_file
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo $line >> $to_file
elif [ "$line" == "[Low Inheritance Precedence]" ];then
override=false
echo "# $line" >> $to_file
elif [ "$line" == "[High Inheritance Precedence]" ];then
override=true
echo "# $line" >> $to_file
echo "Merge properties with override $override"
else
sedline=${line%=*}
if grep -q $sedline $to_file ;then
if $override ;then
echo "Override the config $(grep $sedline $to_file) with $line in $to_file"
prop=${line:0:`expr index $line =`}
sed -i "/$prop/d" $to_file
echo $line >> $to_file
else
grepline=$(grep $sedline $to_file)
if [ "${grepline::1}" == '#' ];then
echo $line >> $to_file
else
echo "Keep the config $(grep $sedline $to_file) in $to_file"
fi
fi
else
echo $line >> $to_file
fi
fi
fi
done < $from_file
echo "# End of $message" >> $to_file
echo "Merged $from_file to $to_file"
}

if [ -f $PLATFORM_DIR/common_config_support ];then

PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common

cp -f $HWSKU_DIR/*.config.bcm /tmp
cp -f /etc/sai.d/sai.profile /tmp
CONFIG_BCM=$(find /tmp -name '*.bcm')
PLT_CONFIG_BCM=$(find $HWSKU_DIR -name '*.bcm')
SAI_PROFILE=$(find /tmp -name 'sai.profile')
sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE

#Get first three characters of chip id
readline=$(grep '0x14e4' /proc/linux-kernel-bde)
chip_id=${readline#*0x14e4:0x}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -name '*.bcm')

if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then
for file in $CONFIG_BCM; do
echo "" >> $file
echo "# Start of chip common properties" >> $file
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo $line >> $file
function merge_config_yml_files()
{
to_file=$1
from_file=$2
message=$3
override=false
merged_cnt=0
echo "" >> $to_file
echo "# Start of $message" >> $to_file
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo " $line" >> $to_file
elif [ "$line" == "[Low Inheritance Precedence]" ];then
override=false
echo " # $line" >> $to_file
elif [ "$line" == "[High Inheritance Precedence]" ];then
override=true
echo " # $line" >> $to_file
echo "Merge properties with override $override"
else
sedline=${line%:*}
if grep -q $sedline $to_file ;then
if $override ;then
echo "Override the config $(grep $sedline $to_file) with $line in $to_file"
prop=${line:0:`expr index "$line" :`}
sed -i "/$prop/d" $to_file
echo " $line" >> $to_file
merged_cnt+=1
else
sedline=${line%=*}
if grep -q $sedline $file ;then
echo "Keep the config $(grep $sedline $file) in $file"
else
echo $line >> $file
fi
grepline=$(grep $sedline $to_file)
grepline="${grepline#"${grepline%%[![:space:]]*}"}"
if [ "${grepline::1}" == '#' ];then
echo " $line" >> $to_file
merged_cnt+=1
else
echo "Keep the config $(grep $sedline $to_file) in $to_file"
fi
fi
fi
done < $COMMON_CONFIG_BCM
echo "# End of chip common properties" >> $file
done
echo "Merging $PLT_CONFIG_BCM with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_BCM"
fi

#sync the file system
sync

# copy the final config.bcm and sai.profile to the shared folder for 'show tech'
cp -f /tmp/sai.profile /var/run/sswsyncd/
cp -f /tmp/*.bcm /var/run/sswsyncd/

if [ -f "/tmp/sai.profile" ]; then
CMD_ARGS+=" -p /tmp/sai.profile"
elif [ -f "/etc/sai.d/sai.profile" ]; then
CMD_ARGS+=" -p /etc/sai.d/sai.profile"
else
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
fi
else
echo " $line" >> $to_file
merged_cnt+=1
fi
fi
fi
done < $from_file

else
if [ $merged_cnt -gt 0 ]; then
sed -i "/# Start of/a \ global:" $to_file
sed -i "/# Start of/a \ 0:" $to_file
sed -i "/# Start of/a \bcm_device:" $to_file
sed -i "/# Start of/a \---" $to_file
fi
echo "# End of $message" >> $to_file
if [ $merged_cnt -gt 0 ]; then
sed -i "/# End of/i \..." $to_file
fi
echo "Merged $from_file to $to_file"
}

if [ -f "/etc/sai.d/sai.profile" ]; then
CMD_ARGS+=" -p /etc/sai.d/sai.profile"
else
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
fi
config_syncd_bcm()
{
PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common
PLT_CONFIG_BCM=""
PLT_CONFIG_YML=""
PLT_SAI_PROFILE=$(find $HWSKU_DIR -name 'sai.profile')
geans-pin marked this conversation as resolved.
Show resolved Hide resolved
readline=$(grep SAI_INIT_CONFIG_FILE $PLT_SAI_PROFILE)
if [ ${readline: -3} == "bcm" ]; then
PLT_CONFIG_BCM=${readline#*=}
elif [ ${readline: -3} == "yml" ]; then
PLT_CONFIG_YML=${readline#*=}
fi

if [ ! -z "$PLT_CONFIG_BCM" ] && [ -f $PLATFORM_DIR/common_config_support ] ; then
cp -f $PLT_CONFIG_BCM /tmp
cp -f /etc/sai.d/sai.profile /tmp
CONFIG_BCM=$(find /tmp -name '*.bcm')
SAI_PROFILE=$(find /tmp -name 'sai.profile')
sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE

#Get first three characters of chip id
readline=$(grep '0x14e4' /proc/linux-kernel-bde)
chip_id=${readline#*0x14e4:0x}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')

if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then
for file in $CONFIG_BCM; do
merge_config_bcm_files $file $COMMON_CONFIG_BCM "chip common properties"
done
echo "Merging $PLT_CONFIG_BCM with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_BCM"
fi
#sync the file system
sync

# copy the final config.bcm and sai.profile to the shared folder for 'show tech'
cp -f /tmp/sai.profile /var/run/sswsyncd/
cp -f /tmp/*.bcm /var/run/sswsyncd/
fi

if [ ! -z "$PLT_CONFIG_YML" ] && [ -f $PLATFORM_DIR/common_config_support ]; then
cp -f $PLT_CONFIG_YML /tmp
cp -f /etc/sai.d/sai.profile /tmp
CONFIG_YML=$(find /tmp -name '*.yml')
SAI_PROFILE=$(find /tmp -name 'sai.profile')
sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE

#Get first three characters of chip id
readline=$(grep '0:14e4' /proc/linux_ngbde)
chip_id=${readline#*0:14e4:}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')

if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then
for file in $CONFIG_YML; do
merge_config_yml_files $file $COMMON_CONFIG_BCM "chip common properties"
done
echo "Merging $PLT_CONFIG_YML with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_YML "
fi
#sync the file system
sync

# copy the final config.bcm and sai.profile to the shared folder for 'show tech'
cp -f /tmp/sai.profile /var/run/sswsyncd/
cp -f /tmp/*.yml /var/run/sswsyncd/
fi

if [ -f "/tmp/sai.profile" ]; then
CMD_ARGS+=" -p /tmp/sai.profile"
elif [ -f "/etc/sai.d/sai.profile" ]; then
CMD_ARGS+=" -p /etc/sai.d/sai.profile"
else
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
fi

if [ -f "$HWSKU_DIR/context_config.json" ]; then
Expand Down Expand Up @@ -517,4 +631,3 @@ config_syncd()

[ -r $PLATFORM_DIR/syncd.conf ] && . $PLATFORM_DIR/syncd.conf
}

Loading