sonic-net/sonic-swss

Add VS Test to catch newlines in REDIS values

arista-nwolfe opened this issue · 0 comments

In #3052 there were two new fields added last_up_time and last_down_time.
But both were added with a new line character at the end.
This caused messy output generated from sonic-db-cli:

> sonic-db-cli APPL_DB hgetall PORT_TABLE:Ethernet8
{'admin_status': 'up', 'alias': 'Ethernet3/1', 'asic_port_name': 'Eth8', 'coreId': '0', 'corePortId': '3', 'description': 'Ethernet8-connected-to-@Ethernet5/4/1', 'fec': 'rs', 'index': '3', 'lanes': '4,5', 'mtu': '9100', 'numVoq': '8', 'pfc_asym': 'off', 'role': 'Ext', 'speed': '100000', 'tpid': '0x8100', 'oper_status': 'up', 'flap_count': '1', 'last_up_time': 'Wed Apr 10 00:18:44 2024
', 'system_oper_status': 'up', 'line_oper_status': 'up'}

> config interface shutdown Ethernet8
> sonic-db-cli APPL_DB hgetall PORT_TABLE:Ethernet8
{'admin_status': 'down', 'alias': 'Ethernet3/1', 'asic_port_name': 'Eth8', 'coreId': '0', 'corePortId': '3', 'description': 'Ethernet8-connected-to-@Ethernet5/4/1', 'fec': 'rs', 'index': '3', 'lanes': '4,5', 'mtu': '9100', 'numVoq': '8', 'pfc_asym': 'off', 'role': 'Ext', 'speed': '100000', 'tpid': '0x8100', 'oper_status': 'down', 'flap_count': '2', 'last_up_time': 'Wed Apr 10 00:18:44 2024
', 'system_oper_status': 'down', 'line_oper_status': 'down', 'last_down_time': 'Wed Apr 10 16:35:11 2024
'}

>  config interface startup Ethernet8
> sonic-db-cli APPL_DB hgetall PORT_TABLE:Ethernet8
{'admin_status': 'up', 'alias': 'Ethernet3/1', 'asic_port_name': 'Eth8', 'coreId': '0', 'corePortId': '3', 'description': 'Ethernet8-connected-to-@Ethernet5/4/1', 'fec': 'rs', 'index': '3', 'lanes': '4,5', 'mtu': '9100', 'numVoq': '8', 'pfc_asym': 'off', 'role': 'Ext', 'speed': '100000', 'tpid': '0x8100', 'oper_status': 'up', 'flap_count': '3', 'last_up_time': 'Wed Apr 10 16:35:34 2024
', 'system_oper_status': 'up', 'line_oper_status': 'up', 'last_down_time': 'Wed Apr 10 16:35:11 2024
'}

It also caused issues like SyntaxError: EOL while scanning string literal for some tools.

This is particular issue is being fixed by #3111 but we should add a test to catch newline characters being added to REDIS strings.