Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GCU] Supressing YANG errors from libyang while sorting (sonic-net#1991)
#### What I did Fixes sonic-net#2025 Stopping SonicYang from printing errors during config validation or moves generation. If callers uses the `-v` option, they will see the SonicYang logs printed. Also made sure that SonicYang returned error are properly propagated, so the user can see the exact errors. #### How I did it Used the the option `print_log_enabled` while creating `SonicYang` ```python sy = sonic_yang.SonicYang(self.yang_dir, print_log_enabled=sonic_yang_print_log_enabled) ``` #### How to verify it Manually tested the change to the output, and added unit-tests to the gu_common functions that were modified. #### Previous command output (if the output of a command-line utility has changed) Given an invalid patch will remove PORT table, while the PORT table is used. ``` admin@vlab-01:~$ sudo config apply-patch remove_port.json-patch -i /FEATURE Patch Applier: Patch application starting. Patch Applier: Patch: [{"op": "remove", "path": "/PORT"}] Patch Applier: Getting current config db. Patch Applier: Simulating the target full config after applying the patch. Patch Applier: Validating target config does not have empty tables, since they do not show up in ConfigDb. Patch Applier: Sorting patch updates. sonic_yang(6):Note: Below table(s) have no YANG models: CONSOLE_SWITCH, DEVICE_NEIGHBOR_METADATA, DHCP_SERVER, KDUMP, RESTAPI, SNMP, SNMP_COMMUNITY, TELEMETRY libyang[0]: Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:name" of value "Ethernet112" points to a non-existing leaf. (path: /sonic-buffer-pg:sonic-buffer-pg/BUFFER_PG/BUFFER_PG_LIST[port='Ethernet112'][pg_num='0']/port) libyang[0]: Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:name" of value "Ethernet112" points to a non-existing leaf. (path: /sonic-buffer-pg:sonic-buffer-pg/BUFFER_PG/BUFFER_PG_LIST[port='Ethernet112'][pg_num='3-4']/port) libyang[0]: Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:name" of value "Ethernet116" points to a non-existing leaf. (path: /sonic-buffer-pg:sonic-buffer-pg/BUFFER_PG/BUFFER_PG_LIST[port='Ethernet116'][pg_num='0']/port) >>>> 10s of log lines libyang[0]: Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:name" of value "Ethernet96" points to a non-existing leaf. (path: /sonic-port-qos-map:sonic-port-qos-map/PORT_QOS_MAP/PORT_QOS_MAP_LIST[ifname='Ethernet96']/ifname) sonic_yang(3):Data Loading Failed:Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:name" of value "Ethernet96" points to a non-existing leaf. Failed to apply patch Usage: config apply-patch [OPTIONS] PATCH_FILE_PATH Try "config apply-patch -h" for help. Error: Given patch is not valid because it will result in an invalid config admin@vlab-01:~$ ``` #### New command output (if the output of a command-line utility has changed) ``` admin@vlab-01:~$ sudo config apply-patch remove_port.json-patch -i /FEATURE Patch Applier: Patch application starting. Patch Applier: Patch: [{"op": "remove", "path": "/PORT"}] Patch Applier: Getting current config db. Patch Applier: Simulating the target full config after applying the patch. Patch Applier: Validating target config does not have empty tables, since they do not show up in ConfigDb. Patch Applier: Sorting patch updates. Failed to apply patch Usage: config apply-patch [OPTIONS] PATCH_FILE_PATH Try "config apply-patch -h" for help. Error: Given patch will produce invalid config. Error: Data Loading Failed Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:name" of value "Ethernet96" points to a non-existing leaf. admin@vlab-01:~$ ```
- Loading branch information