From d5a64b987fb898eca839b35cda77afa1d8fb6581 Mon Sep 17 00:00:00 2001 From: Anton Patenko Date: Wed, 26 Oct 2016 17:55:16 +0300 Subject: [PATCH 1/3] Added port aliases testing. Ports aliases are being testes by comparing aliases from Redis to ones from port_config file. --- .../roles/test/files/helpers/test_aliases.sh | 93 +++++++++++++++++++ ansible/roles/test/tasks/config.yml | 5 + ansible/roles/test/tasks/sonic.yml | 8 +- 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 ansible/roles/test/files/helpers/test_aliases.sh create mode 100644 ansible/roles/test/tasks/config.yml diff --git a/ansible/roles/test/files/helpers/test_aliases.sh b/ansible/roles/test/files/helpers/test_aliases.sh new file mode 100644 index 00000000000..0b1c626d535 --- /dev/null +++ b/ansible/roles/test/files/helpers/test_aliases.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +let DEBUG=0 + +# --------------------------------- +# Read from configfile +function read_configfile_aliases +{ + readonly local port_config=`cat $CONFIGFILE` + + let local line_counter=2 + local port_config_entry + local ether_number + local port_alias + while [ $line_counter -le $LINESNUMBER ]; do + port_config_entry=`echo "${port_config}" | sed -n "$line_counter"p | sed -n "s/Ethernet//p" | sed -n "s/ [[:digit:]].* //p"` + ether_number=`echo $port_config_entry | cut -d" " -f1` + port_alias=`echo $port_config_entry | sed -n "s/[[:digit:]]* //p"` + + # Write into table + port_config_array[$ether_number]="$port_alias" + let line_counter="line_counter + 1" + + print_debug "-------------------------------" + print_debug "PORT_ENTRY = $port_config_entry\n" + print_debug "ETHER_NUMBER = $ether_number\n" + print_debug "PORT_ALIAS = $port_alias\n" + done +} + +# --------------------------------- +# Read alises from Redis-db and compare to ones from configfile +function read_redis_aliases_and_compare +{ + let local ether_counter=0 + local port_data_entry + local port_data_alias + + while [ $ether_counter -le $ETHERMAX ]; do + port_data_entry=`docker exec -ti database redis-cli hgetall "PORT_TABLE:Ethernet"$ether_counter""` + + # Grep next line after "alias"; remove numbering, quotes and + # everything else except of alias name. + port_data_alias=`echo "${port_data_entry}" | grep -A1 'alias' | grep -v 'alias' | sed -n 's/.* \"//p' | sed -n 's/\".*//p'` + + # Compare db-alias to alias from CONFIGFILE + print_debug "---------------------------------------------" + print_debug "comparing: configfile_alias='"${port_config_array[$ether_counter]}"'\n + Redis_alias="$port_data_alias"" + + # Check if aliases are same + if [[ "$port_data_alias" != "${port_config_array[$ether_counter]}" ]]; then + echo -e "\nERROR: port has got different aliases in port_config.ini and database." + echo -e "Port name: Ethernet$ether_counter" + echo -e "Alias in port_config.ini: ${port_config_array[$ether_counter]}" + echo -e "Alias in Redis DB: $port_data_alias\n" + exit 1 + fi + let ether_counter="ether_counter + 4" + done +} + +function print_debug +{ + if [[ $DEBUG -ne "0" ]]; then + echo -e "$1" + fi +} + +# ------------- START ------------- + +readonly CONFIGFILE="/etc/ssw/*/port_config.ini" +readonly LINESNUMBER=`wc -l < $CONFIGFILE` +if [ $LINESNUMBER -lt 2 ]; then + echo -e "ERROR: wrong port_config table. Please check port_config.ini\n" + exit 1 +fi +let readonly ETHERMAX="($LINESNUMBER - 2) * 4" + +# Array where each port alias will be stored +declare -a port_config_array + +# Read aliases from configfile +read_configfile_aliases + +# Read aliases from Redis-db +read_redis_aliases_and_compare + +echo "---------------------------------------------" +echo "Aliases tested successfully" +echo "---------------------------------------------" + +exit 0 diff --git a/ansible/roles/test/tasks/config.yml b/ansible/roles/test/tasks/config.yml new file mode 100644 index 00000000000..d929f06c3f1 --- /dev/null +++ b/ansible/roles/test/tasks/config.yml @@ -0,0 +1,5 @@ +- name: Test port aliases + script: roles/test/files/helpers/test_aliases.sh + register: test_port_aliases_config + failed_when: test_port_aliases_config.rc != 0 + changed_when: False diff --git a/ansible/roles/test/tasks/sonic.yml b/ansible/roles/test/tasks/sonic.yml index 5dfea64ae11..a0df2cd79e6 100644 --- a/ansible/roles/test/tasks/sonic.yml +++ b/ansible/roles/test/tasks/sonic.yml @@ -62,8 +62,12 @@ include: arpall.yml tags: arp -### When calling this basic_route, Chip is setup with proper parameters and -### SAI API used by syncd daemon are called. This test is mainly for validation purpose used by external vendors. +- name: Test hardware configuration + include: config.yml + tags: config + +## When calling this basic_route, Chip is setup with proper parameters and +## SAI API used by syncd daemon are called. This test is mainly for validation purpose used by external vendors. - name: Test basic_router include: basic_router.yml tags: basic_router From 7421a6c14f25424947e90a00fbe6ae305d48f8c7 Mon Sep 17 00:00:00 2001 From: Anton Patenko Date: Mon, 31 Oct 2016 15:25:05 +0200 Subject: [PATCH 2/3] Using port name as alias. - Port name shall be used as alias for port if no alias specified for that port in config-file. - Fixed bug when reading an empty alias --- .../roles/test/files/helpers/test_aliases.sh | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ansible/roles/test/files/helpers/test_aliases.sh b/ansible/roles/test/files/helpers/test_aliases.sh index 0b1c626d535..a097bf6884e 100644 --- a/ansible/roles/test/files/helpers/test_aliases.sh +++ b/ansible/roles/test/files/helpers/test_aliases.sh @@ -13,14 +13,19 @@ function read_configfile_aliases local ether_number local port_alias while [ $line_counter -le $LINESNUMBER ]; do - port_config_entry=`echo "${port_config}" | sed -n "$line_counter"p | sed -n "s/Ethernet//p" | sed -n "s/ [[:digit:]].* //p"` + # Read and parse data from port_config.ini + port_config_entry=`echo "${port_config}" | sed -n "$line_counter"p | sed -n "s/Ethernet//p" | sed -n "s/\([[:digit:]]*,[[:digit:]]*\)\+//p"` ether_number=`echo $port_config_entry | cut -d" " -f1` - port_alias=`echo $port_config_entry | sed -n "s/[[:digit:]]* //p"` + port_alias=`echo $port_config_entry | sed -n "s/[[:digit:]]*[[:space:]]//p"` - # Write into table + # If no alias, use port name + if [[ -z "$port_alias" ]]; then + port_alias="Ethernet"$ether_number"" + fi + + # Write into port_config_table port_config_array[$ether_number]="$port_alias" let line_counter="line_counter + 1" - print_debug "-------------------------------" print_debug "PORT_ENTRY = $port_config_entry\n" print_debug "ETHER_NUMBER = $ether_number\n" @@ -39,21 +44,24 @@ function read_redis_aliases_and_compare while [ $ether_counter -le $ETHERMAX ]; do port_data_entry=`docker exec -ti database redis-cli hgetall "PORT_TABLE:Ethernet"$ether_counter""` - # Grep next line after "alias"; remove numbering, quotes and - # everything else except of alias name. + # Grep next line after "alias"; remove numbering, + # quotes and everything else except of alias name. port_data_alias=`echo "${port_data_entry}" | grep -A1 'alias' | grep -v 'alias' | sed -n 's/.* \"//p' | sed -n 's/\".*//p'` # Compare db-alias to alias from CONFIGFILE print_debug "---------------------------------------------" - print_debug "comparing: configfile_alias='"${port_config_array[$ether_counter]}"'\n - Redis_alias="$port_data_alias"" + print_debug "comparing: configfile_alias="${port_config_array[$ether_counter]}"\n + Redis_alias="$port_data_alias"" - # Check if aliases are same + # Check if alias are the same if [[ "$port_data_alias" != "${port_config_array[$ether_counter]}" ]]; then - echo -e "\nERROR: port has got different aliases in port_config.ini and database." + echo -e "\n*** ERROR: port has got different aliases in port_config.ini and database." echo -e "Port name: Ethernet$ether_counter" echo -e "Alias in port_config.ini: ${port_config_array[$ether_counter]}" echo -e "Alias in Redis DB: $port_data_alias\n" + + print_debug "==============================" + print_debug "${port_config_array[*]}" exit 1 fi let ether_counter="ether_counter + 4" From 92aeb0c60d74a70453610d95cd31346c879ec29b Mon Sep 17 00:00:00 2001 From: Anton Patenko Date: Thu, 10 Nov 2016 16:17:34 +0200 Subject: [PATCH 3/3] port_aliases: renamed test playbook and test tag. --- ansible/roles/test/tasks/{config.yml => port-alias.yml} | 0 ansible/roles/test/tasks/sonic.yml | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename ansible/roles/test/tasks/{config.yml => port-alias.yml} (100%) diff --git a/ansible/roles/test/tasks/config.yml b/ansible/roles/test/tasks/port-alias.yml similarity index 100% rename from ansible/roles/test/tasks/config.yml rename to ansible/roles/test/tasks/port-alias.yml diff --git a/ansible/roles/test/tasks/sonic.yml b/ansible/roles/test/tasks/sonic.yml index a0df2cd79e6..0c917f5ee9a 100644 --- a/ansible/roles/test/tasks/sonic.yml +++ b/ansible/roles/test/tasks/sonic.yml @@ -62,9 +62,9 @@ include: arpall.yml tags: arp -- name: Test hardware configuration - include: config.yml - tags: config +- name: Test port aliases configuration + include: port-alias.yml + tags: port-alias ## When calling this basic_route, Chip is setup with proper parameters and ## SAI API used by syncd daemon are called. This test is mainly for validation purpose used by external vendors.