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

[GCU] Supressing YANG errors from libyang while sorting #1991

Merged
merged 2 commits into from
Apr 29, 2022

Conversation

ghooo
Copy link
Contributor

@ghooo ghooo commented Dec 28, 2021

What I did

Fixes #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

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:~$ 

@ghooo ghooo force-pushed the dev/mghoneim/suppress_yang_errors branch from 36b165d to a44d002 Compare April 27, 2022 18:06
@ghooo ghooo marked this pull request as ready for review April 27, 2022 18:19
@ghooo ghooo requested review from qiluo-msft and wen587 April 28, 2022 23:10
@@ -562,7 +562,8 @@ def __init__(self, config_wrapper):

def validate(self, move, diff):
simulated_config = move.apply(diff.current_config)
return self.config_wrapper.validate_config_db_config(simulated_config)
is_valid, error = self.config_wrapper.validate_config_db_config(simulated_config)
Copy link
Contributor

Choose a reason for hiding this comment

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

error

Not a big issue, you can use _ if you intend not to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix it in a later PR as this is blocking #2145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GCU] Improve error msgs
3 participants