Page MenuHomeVyOS Platform

vyos.util.leaf_node_changed() dos not honor valueLess nodes
Closed, ResolvedPublicBUG

Description

If a valueLess node is added or removed from the CLI, a call to leaf_node_changed() will not detect it.

Reason is:

def leaf_node_changed(conf, path):
    """
    Check if a leaf node was altered. If it has been altered - values has been
    changed, or it was added/removed, we will return a list containing the old
    value(s). If nothing has been changed, None is returned.
    NOTE: path must use the real CLI node name (e.g. with a hyphen!)
    """
    from vyos.configdiff import get_config_diff
    D = get_config_diff(conf, key_mangling=('-', '_'))
    D.set_level(conf.get_level())
    (new, old) = D.get_value_diff(path)

    # if node is valueLess, on change old or new (depending on addition or deletion) will be {} and is treated as None

    if new != old:
        if old is None:
            return []
        if isinstance(old, str):
            return [old]
        if isinstance(old, list):
            if isinstance(new, str):
                new = [new]
            elif isinstance(new, type(None)):
                new = []
            return list_diff(old, new)
    return None

Not a blocker for 1.3 as this functionality is not (yet) used. Nevertheless this functionality is required for T4264

Details

Difficulty level
Easy (less than an hour)
Version
1.3.0 & 1.4
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Perfectly compatible
Issue type
Bug (incorrect behavior)

Event Timeline

c-po changed the task status from Open to In progress.Feb 22 2022, 9:28 AM
c-po claimed this task.
c-po triaged this task as Normal priority.
c-po changed the task status from In progress to Needs testing.Feb 22 2022, 9:33 AM
c-po moved this task from Need Triage to Finished on the VyOS 1.4 Sagitta board.
c-po moved this task from Need Triage to Backport Candidates on the VyOS 1.3 Equuleus ( 1.3.1) board.