summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-09-07 20:00:33 +0000
committerChristian Breunig <christian@breunig.cc>2026-09-07 20:00:33 +0000
commitd1f437e21809ba673cd7c4ef0126a121b29b5b5c (patch)
treedcc26c43b973c4dabbac7b3c30538d98d28227b3 /python
parentb0fb31d32f05691ed568b29a71d7963cb28aa053 (diff)
downloadvyos-1x-d1f437e21809ba673cd7c4ef0126a121b29b5b5c.tar.gz
vyos-1x-d1f437e21809ba673cd7c4ef0126a121b29b5b5c.zip
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.
Diffstat (limited to 'python')
-rw-r--r--python/vyos/configquery.py19
1 files changed, 8 insertions, 11 deletions
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 = ''