diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-05-27 08:16:34 -0500 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2026-05-28 08:31:32 -0500 |
| commit | 9ff29049d42dbd40ede1c4507bc6598e0403ce46 (patch) | |
| tree | 5b67172159b86443680e20b8a4aeccb80eafe838 /python | |
| parent | 8036eaf0a2adaca5609d32fcfef75d11344df7fd (diff) | |
| download | vyos-1x-9ff29049d42dbd40ede1c4507bc6598e0403ce46.tar.gz vyos-1x-9ff29049d42dbd40ede1c4507bc6598e0403ce46.zip | |
T8916: allow passing ReferenceTree instance to subtree_from_partial
For use in nosetests or other, allow passing ReferenceTree from an
internal cache in a non-standard location.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/derivedtree.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/python/vyos/derivedtree.py b/python/vyos/derivedtree.py index 0a57921b2..dc46b8eb3 100644 --- a/python/vyos/derivedtree.py +++ b/python/vyos/derivedtree.py @@ -25,7 +25,10 @@ class DerivedTreeError(Exception): def subtree_from_list_of_partial_paths( - ctree: ConfigTree, paths: list[list[str]], accumulator: ConfigTree = None + ctree: ConfigTree, + paths: list[list[str]], + accumulator: ConfigTree = None, + reference_tree: ReferenceTree = None, ): """Return the union of subtrees of the ConfigTree argument matching each of the 'partial' paths. A partial path is one that may or may not @@ -33,19 +36,23 @@ def subtree_from_list_of_partial_paths( values that apply. An existing subtree may be passed as the initial value of accumulator. + + For testing or use outside of the canonical environment, an instance of + the ReferenceTree may be passed from an alternative cache location. """ - if accumulator: + if reference_tree is None: + reference_tree = ReferenceTree() + + if accumulator is not None: if not isinstance(accumulator, ConfigTree): raise TypeError("Argument 'accumulator' must be an instance of ConfigTree") else: accumulator = ConfigTree('') - rtree = ReferenceTree() - errors = [] for path in paths: try: - accumulator = subtree_from_partial(ctree, path, rtree, accumulator) + accumulator = subtree_from_partial(ctree, path, reference_tree, accumulator) except ConfigTreeError as e: errors.append(str(e)) continue |
