Skip to content

Commit e869613

Browse files
Remove direct dependency on libyang
sonic-utilities should never call directly into libyang. All functionality it needs should be provided in sonic-yang-mgmt. This resolves issues when libyang changes API/ABI such as happened between libyang1 and libyang2, and again between libyang2 and libyang3. Depends on sonic-net/sonic-buildimage#24414
1 parent bd3de9d commit e869613

File tree

5 files changed

+10
-30
lines changed

5 files changed

+10
-30
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Currently, this list of dependencies is as follows:
3434
- libyang_1.0.73_amd64.deb
3535
- libyang-cpp_1.0.73_amd64.deb
3636
- python3-yang_1.0.73_amd64.deb
37+
- libyang3_3.*_amd64.deb
38+
- python3-libyang_3.*_amd64.deb
3739
- redis_dump_load-1.1-py3-none-any.whl
3840
- sonic_py_common-1.0-py3-none-any.whl
3941
- sonic_config_engine-1.0-py3-none-any.whl

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ stages:
8585
sudo dpkg -i libyang_1.0.73_amd64.deb
8686
sudo dpkg -i libyang-cpp_1.0.73_amd64.deb
8787
sudo dpkg -i python3-yang_1.0.73_amd64.deb
88+
sudo dpkg -i libyang3_3.*_amd64.deb
89+
sudo dpkg -i python3-libyang_3.*_amd64.deb
8890
workingDirectory: $(Pipeline.Workspace)/target/debs/bookworm/
8991
displayName: 'Install Debian dependencies'
9092

config/config_mgmt.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import shutil
99
import syslog
1010
import tempfile
11-
import yang as ly
1211
from json import load
1312
from sys import flags
1413
from time import sleep as tsleep
@@ -35,8 +34,7 @@ class ConfigMgmt():
3534
to verify config for the commands which are capable of change in config DB.
3635
'''
3736

38-
def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True,
39-
sonicYangOptions=0, configdb=None):
37+
def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True, configdb=None):
4038
'''
4139
Initialise the class, --read the config, --load in data tree.
4240
@@ -55,7 +53,6 @@ def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True,
5553
self.configdbJsonOut = None
5654
self.source = source
5755
self.allowTablesWithoutYang = allowTablesWithoutYang
58-
self.sonicYangOptions = sonicYangOptions
5956
self.configdb = configdb
6057

6158
# logging vars
@@ -71,7 +68,7 @@ def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True,
7168
return
7269

7370
def __init_sonic_yang(self):
74-
self.sy = sonic_yang.SonicYang(YANG_DIR, debug=self.DEBUG, sonic_yang_options=self.sonicYangOptions)
71+
self.sy = sonic_yang.SonicYang(YANG_DIR, debug=self.DEBUG)
7572
# load yang models
7673
self.sy.loadYangModel()
7774
# load jIn from config DB or from config DB json file.
@@ -291,8 +288,7 @@ def get_module_name(yang_module_str):
291288

292289
# Instantiate new context since parse_module_mem() loads the module into context.
293290
sy = sonic_yang.SonicYang(YANG_DIR)
294-
module = sy.ctx.parse_module_mem(yang_module_str, ly.LYS_IN_YANG)
295-
return module.name()
291+
return sy.load_module_str_name(yang_module_str);
296292

297293

298294
# End of Class ConfigMgmt

generic_config_updater/gu_common.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sonic_yang
66
import sonic_yang_ext
77
import subprocess
8-
import yang as ly
98
import copy
109
import re
1110
import os
@@ -539,10 +538,8 @@ def find_ref_paths(self, paths, config, reload_config: bool = True):
539538
# Iterate across all paths fetching references
540539
for path in paths:
541540
xpath = self.convert_path_to_xpath(path, config, sy)
542-
543-
leaf_xpaths = self._get_inner_leaf_xpaths(xpath, sy)
544-
for xpath in leaf_xpaths:
545-
ref_xpaths.extend(sy.find_data_dependencies(xpath))
541+
# NOTE: This will recursively find dependencies for all ancestors
542+
ref_xpaths.extend(sy.find_data_dependencies(xpath))
546543

547544
# For each xpath, convert to configdb path
548545
for ref_xpath in ref_xpaths:
@@ -554,22 +551,6 @@ def find_ref_paths(self, paths, config, reload_config: bool = True):
554551
ref_paths.sort()
555552
return ref_paths
556553

557-
def _get_inner_leaf_xpaths(self, xpath, sy):
558-
if xpath == "/": # Point to Root element which contains all xpaths
559-
nodes = sy.root.tree_for()
560-
else: # Otherwise get all nodes that match xpath
561-
nodes = sy.root.find_path(xpath).data()
562-
563-
for node in nodes:
564-
for inner_node in node.tree_dfs():
565-
# TODO: leaflist also can be used as the 'path' argument in 'leafref' so add support to leaflist
566-
if self._is_leaf_node(inner_node):
567-
yield inner_node.path()
568-
569-
def _is_leaf_node(self, node):
570-
schema = node.schema()
571-
return ly.LYS_LEAF == schema.nodetype()
572-
573554
def convert_path_to_xpath(self, path, config=None, sy=None):
574555
"""
575556
Converts the given JsonPatch path (i.e. JsonPointer) to XPATH.

sonic_package_manager/manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import pkgutil
77
import tempfile
8-
import yang as ly
98
from inspect import signature
109
from typing import Any, Iterable, List, Callable, Dict, Optional
1110

@@ -1299,7 +1298,7 @@ def get_manager() -> 'PackageManager':
12991298
docker_api = DockerApi(docker.from_env(), ProgressManager())
13001299
registry_resolver = RegistryResolver()
13011300
metadata_resolver = MetadataResolver(docker_api, registry_resolver)
1302-
cfg_mgmt = config_mgmt.ConfigMgmt(source=INIT_CFG_JSON, sonicYangOptions=ly.LY_CTX_DISABLE_SEARCHDIR_CWD)
1301+
cfg_mgmt = config_mgmt.ConfigMgmt(source=INIT_CFG_JSON)
13031302
cli_generator = CliGenerator(log)
13041303
feature_registry = FeatureRegistry(SonicDB)
13051304
service_creator = ServiceCreator(feature_registry,

0 commit comments

Comments
 (0)