Page MenuHomeVyOS Platform

`vyos.config.exists()` does not work for nodes with multiple values
Closed, ResolvedPublicBUG

Description

The exists() function (https://github.com/vyos/vyos-1x/blob/0e02a8321f34069832ccd4266b5a82d48b82186a/python/vyos/config.py#L143-L170) uses only return_value, so it works only for nodes with a single value.
We have at least one confirmed issue because of this: https://phabricator.vyos.net/T4354

To make it compatible with nodes with multiple values, we should add also return_values. Basic proof-of-concept:

diff --git a/python/vyos/config.py b/python/vyos/config.py
index a5c1ad12..09c8fd03 100644
--- a/python/vyos/config.py
+++ b/python/vyos/config.py
@@ -164,7 +164,11 @@ class Config(object):
             path_str = " ".join(path_without_value)
             try:
                 value = self._session_config.return_value(self._make_path(path_str))
-                return (value == path[-1])
+                values = self._session_config.return_values(self._make_path(path_str))
+                if value and path[-1] == value:
+                    return True
+                if isinstance(values, list) and path[-1] in values:
+                    return True
             except vyos.configtree.ConfigTreeError:
                 # node doesn't exist at all
                 return False

Details

Version
1.4-rolling-202204130521, 1.3.1-S1
Is it a breaking change?
Perfectly compatible
Issue type
Bug (incorrect behavior)

Event Timeline

jestabro moved this task from Open to Finished on the VyOS 1.4 Sagitta board.
jestabro moved this task from Finished to In Progress on the VyOS 1.4 Sagitta board.

Re-open for revision/simplification in:
https://github.com/vyos/vyos-1x/pull/1295