Skip to content

Leafref util functions #2352

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

Merged
merged 3 commits into from
Feb 18, 2025
Merged

Leafref util functions #2352

merged 3 commits into from
Feb 18, 2025

Conversation

michalvasko
Copy link
Member

Refs #2351

michalvasko and others added 2 commits February 17, 2025 16:09
Meaning all leafrefs that target a specific node.

Co-authored-by: Brad House <[email protected]>
@bradh352
Copy link
Contributor

thanks, at first glance this looks basically the same so it should work. I'll pull it into the SONiC PRs I've got so I can run the tests there to make sure all is good. I'll report back. Thanks!

bradh352 added a commit to bradh352/libyang-python that referenced this pull request Feb 17, 2025
bradh352 added a commit to bradh352/libyang-python that referenced this pull request Feb 17, 2025
In libyang v1 the schema nodes had a backlinks member to be able to
look up dependents of the node.  SONiC depends on this to provide
functionality it uses and it needs to be exposed via the python
module.

In theory, exposing the 'dfs' functions could make this work, but
it would likely be cost prohibitive since walking the tree would
be expensive to create a python node for evaluation in native
python.

Instead this PR depends on the this libyang PR:
CESNET/libyang#2352
And adds thin wrappers.

This implementation provides 2 python functions:
 * Context.find_backlinks_paths() - This function can
   take the path of the base node and find all dependents.  If
   no path is specified, then it will return all nodes that contain
   a leafref reference.
 * Context.find_leafref_path_target_paths() - This function takes
   an xpath, then returns all target nodes the xpath may reference.
   Typically only one will be returned, but multiples may be in the
   case of a union.

A user can build a cache by combining Context.find_backlinks_paths()
with no path set and building a reverse table using
Context.find_leafref_path_target_paths()

Signed-off-by: Brad House <[email protected]>
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 17, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
@bradh352
Copy link
Contributor

@michalvasko I can confirm this PR passes our test cases in SONiC. Thanks!

@michalvasko michalvasko merged commit 02126d7 into devel Feb 18, 2025
11 checks passed
@michalvasko michalvasko deleted the leafrefs branch February 18, 2025 07:32
@bradh352
Copy link
Contributor

I'm not familiar with your process, but it appears the libyang-python repo depends on commits in the libyang master branch only for running its tests. Any idea when this PR (as well as PR #2344) might get merged into master so the libyang-python PRs can be evaluated (CESNET/libyang-python#134 CESNET/libyang-python#132)?

@michalvasko
Copy link
Member Author

The last release is still fairly new so it will likely be at least a few months.

@bradh352
Copy link
Contributor

Ok, I'll need to try to push @rjarry I guess to make sure the changes will be acceptable or if there are any requested APi changes in libyang-python when using the new APIs as I'll need to pull in PRs into SONiC as patches before they are accepted.

bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 20, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 20, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 21, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 25, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 25, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 25, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Feb 28, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 1, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 4, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 5, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 5, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 6, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 8, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 11, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Mar 12, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Apr 3, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Apr 3, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Apr 20, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/libyang-python that referenced this pull request Apr 22, 2025
In libyang v1 the schema nodes had a backlinks member to be able to
look up dependents of the node.  SONiC depends on this to provide
functionality it uses and it needs to be exposed via the python
module.

In theory, exposing the 'dfs' functions could make this work, but
it would likely be cost prohibitive since walking the tree would
be expensive to create a python node for evaluation in native
python.

Instead this PR depends on the this libyang PR:
CESNET/libyang#2352
And adds thin wrappers.

This implementation provides 2 python functions:
 * Context.find_backlinks_paths() - This function can
   take the path of the base node and find all dependents.  If
   no path is specified, then it will return all nodes that contain
   a leafref reference.
 * Context.find_leafref_path_target_paths() - This function takes
   an xpath, then returns all target nodes the xpath may reference.
   Typically only one will be returned, but multiples may be in the
   case of a union.

A user can build a cache by combining Context.find_backlinks_paths()
with no path set and building a reverse table using
Context.find_leafref_path_target_paths()

Signed-off-by: Brad House <[email protected]>
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Apr 22, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Apr 23, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Apr 24, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/sonic-buildimage that referenced this pull request Jun 13, 2025
CESNET/libyang#2352

Backlinks were removed between libyang1 and libyang2, this adds
helper functions for enumerating backlinks.
bradh352 added a commit to bradh352/libyang-python that referenced this pull request Jun 13, 2025
In libyang v1 the schema nodes had a backlinks member to be able to
look up dependents of the node.  SONiC depends on this to provide
functionality it uses and it needs to be exposed via the python
module.

In theory, exposing the 'dfs' functions could make this work, but
it would likely be cost prohibitive since walking the tree would
be expensive to create a python node for evaluation in native
python.

Instead this PR depends on the this libyang PR:
CESNET/libyang#2352
And adds thin wrappers.

This implementation provides 2 python functions:
 * Context.find_backlinks_paths() - This function can
   take the path of the base node and find all dependents.  If
   no path is specified, then it will return all nodes that contain
   a leafref reference.
 * Context.find_leafref_path_target_paths() - This function takes
   an xpath, then returns all target nodes the xpath may reference.
   Typically only one will be returned, but multiples may be in the
   case of a union.

A user can build a cache by combining Context.find_backlinks_paths()
with no path set and building a reverse table using
Context.find_leafref_path_target_paths()

Signed-off-by: Brad House <[email protected]>
bradh352 added a commit to bradh352/libyang-python that referenced this pull request Jun 13, 2025
In libyang v1 the schema nodes had a backlinks member to be able to
look up dependents of the node.  SONiC depends on this to provide
functionality it uses and it needs to be exposed via the python
module.

In theory, exposing the 'dfs' functions could make this work, but
it would likely be cost prohibitive since walking the tree would
be expensive to create a python node for evaluation in native
python.

Instead this PR depends on the this libyang PR:
CESNET/libyang#2352
And adds thin wrappers.

This implementation provides 2 python functions:
 * Context.find_backlinks_paths() - This function can
   take the path of the base node and find all dependents.  If
   no path is specified, then it will return all nodes that contain
   a leafref reference.
 * Context.find_leafref_path_target_paths() - This function takes
   an xpath, then returns all target nodes the xpath may reference.
   Typically only one will be returned, but multiples may be in the
   case of a union.

A user can build a cache by combining Context.find_backlinks_paths()
with no path set and building a reverse table using
Context.find_leafref_path_target_paths()

Signed-off-by: Brad House <[email protected]>
bradh352 added a commit to bradh352/libyang-python that referenced this pull request Jun 13, 2025
In libyang v1 the schema nodes had a backlinks member to be able to
look up dependents of the node.  SONiC depends on this to provide
functionality it uses and it needs to be exposed via the python
module.

In theory, exposing the 'dfs' functions could make this work, but
it would likely be cost prohibitive since walking the tree would
be expensive to create a python node for evaluation in native
python.

Instead this PR depends on the this libyang PR:
CESNET/libyang#2352
And adds thin wrappers.

This implementation provides 2 python functions:
 * Context.find_backlinks_paths() - This function can
   take the path of the base node and find all dependents.  If
   no path is specified, then it will return all nodes that contain
   a leafref reference.
 * Context.find_leafref_path_target_paths() - This function takes
   an xpath, then returns all target nodes the xpath may reference.
   Typically only one will be returned, but multiples may be in the
   case of a union.

A user can build a cache by combining Context.find_backlinks_paths()
with no path set and building a reverse table using
Context.find_leafref_path_target_paths()

Signed-off-by: Brad House <[email protected]>
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.

2 participants