Skip to content

Commit 4516179

Browse files
authored
[yang] extend ConfigMgmt constructor to pass YANG options (#2118)
- What I did Pass YANG attribute that allow do not automatically search for schemas in current working directory, which is by default searched automatically (despite not recursively). - How I did it extend ConfigMgmt constructor - How to verify it Create some invalid link on switch : ln -s /usr/abc xxx run spm list --> There should not be these messages:
1 parent 2f53bd4 commit 4516179

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

config/config_mgmt.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ConfigMgmt():
3535
to verify config for the commands which are capable of change in config DB.
3636
'''
3737

38-
def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True):
38+
def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True, sonicYangOptions=0):
3939
'''
4040
Initialise the class, --read the config, --load in data tree.
4141
@@ -53,6 +53,7 @@ def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True):
5353
self.configdbJsonOut = None
5454
self.source = source
5555
self.allowTablesWithoutYang = allowTablesWithoutYang
56+
self.sonicYangOptions = sonicYangOptions
5657

5758
# logging vars
5859
self.SYSLOG_IDENTIFIER = "ConfigMgmt"
@@ -67,7 +68,7 @@ def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True):
6768
return
6869

6970
def __init_sonic_yang(self):
70-
self.sy = sonic_yang.SonicYang(YANG_DIR, debug=self.DEBUG)
71+
self.sy = sonic_yang.SonicYang(YANG_DIR, debug=self.DEBUG, sonic_yang_options=self.sonicYangOptions)
7172
# load yang models
7273
self.sy.loadYangModel()
7374
# load jIn from config DB or from config DB json file.
@@ -280,7 +281,7 @@ def get_module_name(yang_module_str):
280281
"""
281282

282283
# Instantiate new context since parse_module_mem() loads the module into context.
283-
sy = sonic_yang.SonicYang(YANG_DIR)
284+
sy = sonic_yang.SonicYang(YANG_DIR, sonic_yang_options=self.sonicYangOptions)
284285
module = sy.ctx.parse_module_mem(yang_module_str, ly.LYS_IN_YANG)
285286
return module.name()
286287

sonic_package_manager/manager.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import pkgutil
77
import tempfile
8+
import yang as ly
89
from inspect import signature
910
from typing import Any, Iterable, List, Callable, Dict, Optional
1011

@@ -1002,7 +1003,7 @@ def get_manager() -> 'PackageManager':
10021003
docker_api = DockerApi(docker.from_env(), ProgressManager())
10031004
registry_resolver = RegistryResolver()
10041005
metadata_resolver = MetadataResolver(docker_api, registry_resolver)
1005-
cfg_mgmt = config_mgmt.ConfigMgmt(source=INIT_CFG_JSON)
1006+
cfg_mgmt = config_mgmt.ConfigMgmt(source=INIT_CFG_JSON, sonicYangOptions=ly.LY_CTX_DISABLE_SEARCHDIR_CWD)
10061007
cli_generator = CliGenerator(log)
10071008
feature_registry = FeatureRegistry(SonicDB)
10081009
service_creator = ServiceCreator(feature_registry,

0 commit comments

Comments
 (0)