From d1f437e21809ba673cd7c4ef0126a121b29b5b5c Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Mon, 7 Sep 2026 20:00:33 +0000 Subject: configquery: T8409: resolve op-mode config paths independent of edit level op_mode_config_dict() rewrote the absolute path passed in by the caller into one relative to VYATTA_EDIT_LEVEL. list_strip() returns an empty list as soon as a path component mismatches, so from e.g. [edit qos policy] the path "qos interface eth1" became the current edit level itself and cli-shell-api dumped an unrelated subtree: [edit qos policy] vyos@vyos# run show qos shaper interface eth1 WARNING: Specified configuration path is not valid QoS is not applied to eth1! Relative lookups are unreliable even when the edit level is a proper prefix of the path, as cli-shell-api validates the path against VYATTA_TEMPLATE_LEVEL and rejects a relative tag node value. Keep the absolute path and reset both level variables for the child process instead. --- python/vyos/configquery.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/vyos/configquery.py b/python/vyos/configquery.py index 3f385d97b..8ee819f19 100644 --- a/python/vyos/configquery.py +++ b/python/vyos/configquery.py @@ -39,7 +39,6 @@ from vyos.xml_ref import is_tag from vyos.base import Warning from vyos.utils.backend import vyconf_backend from vyos.configsource import ConfigSourceVyconfSession -from vyos.utils.list import list_strip config_file = os.path.join(directories['config'], 'config.boot') @@ -183,9 +182,9 @@ def verify_mangling(key_mangling): raise ValueError('key_mangling must be a tuple of two strings') -def op_mode_run(cmd): +def op_mode_run(cmd, env=None): """low-level to avoid overhead""" - p = subprocess.Popen(cmd, stdout=subprocess.PIPE) + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env) out = p.stdout.read() p.wait() return p.returncode, out.decode() @@ -203,15 +202,13 @@ def op_mode_config_dict( command = ['/bin/cli-shell-api', '--show-active-only', 'showConfig'] - edit_level = os.environ.get('VYATTA_EDIT_LEVEL', '') - if edit_level: - tmp = edit_level.split('/') - edit_path = [el for el in tmp if el] - relative_path = list_strip(path, edit_path) - else: - relative_path = path + # An op-mode script may be called from within a configuration session at + # an arbitrary edit level; cli-shell-api resolves the requested path + # relative to that level. Reset the level for the child process, so the + # absolute path passed by the caller is always used as is. + env = os.environ | {'VYATTA_EDIT_LEVEL': '/', 'VYATTA_TEMPLATE_LEVEL': '/'} - rc, out = op_mode_run(command + relative_path) + rc, out = op_mode_run(command + path, env=env) if rc == cli_shell_api_err.VYOS_EMPTY_CONFIG: out = '' -- cgit v1.2.3