From 0a6bb3f6f0c6ce70d0643a9adc2d8276c7f80e11 Mon Sep 17 00:00:00 2001 From: Andriy Yurkiv <70649192+ayurkiv-nvda@users.noreply.github.com> Date: Mon, 2 May 2022 19:51:30 +0300 Subject: [PATCH] [yang] add yang options for Context object (#10359) #### Why I did it Need to pass LY_CTX_DISABLE_SEARCHDIR_CWD to Context in order to disable automatically searching for schemas in current working directory (which is by default searched automatically) #### How I did it add additional attribute into YANG context #### How to verify it Create some invalid link on switch : 1) **ln -s /usr/abc xxx** 2) run **spm list** --> There should not be these messages: ``` libyang[1]: Unable to get information about "xxx" file in "/tmp" when searching for (sub)modules (No such file or directory) libyang[1]: Unable to get information about "xxx" file in "/tmp" when searching for (sub)modules (No such file or directory) libyang[1]: Unable to get information about "xxx" file in "/tmp" when searching for (sub)modules (No such file or directory) libyang[1]: Unable to get information about "xxx" file in "/tmp" when searching for (sub)modules (No such file or directory) ``` --- src/sonic-yang-mgmt/sonic_yang.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-yang-mgmt/sonic_yang.py b/src/sonic-yang-mgmt/sonic_yang.py index 16aeb8a9ff..6bf590fced 100644 --- a/src/sonic-yang-mgmt/sonic_yang.py +++ b/src/sonic-yang-mgmt/sonic_yang.py @@ -12,7 +12,7 @@ i.e. it is mixin not parent class. """ class SonicYang(SonicYangExtMixin): - def __init__(self, yang_dir, debug=False, print_log_enabled=True): + def __init__(self, yang_dir, debug=False, print_log_enabled=True, sonic_yang_options=0): self.yang_dir = yang_dir self.ctx = None self.module = None @@ -46,7 +46,7 @@ class SonicYang(SonicYangExtMixin): self.preProcessedYang = dict() try: - self.ctx = ly.Context(yang_dir) + self.ctx = ly.Context(yang_dir, sonic_yang_options) except Exception as e: self.fail(e)