summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-09-12 08:16:59 +0200
committerGitHub <noreply@github.com>2026-09-12 08:16:59 +0200
commitf559ade725be1a2585d73e4bc878283e1f0abf85 (patch)
tree856f5df9b5c2037ef658bc73b16a2a67684337f0 /python
parentc93510a0d6706ad42bb7de102ae4665768b78020 (diff)
parentd1f437e21809ba673cd7c4ef0126a121b29b5b5c (diff)
downloadvyos-1x-f559ade725be1a2585d73e4bc878283e1f0abf85.tar.gz
vyos-1x-f559ade725be1a2585d73e4bc878283e1f0abf85.zip
Merge pull request #5451 from c-po/T8409
configquery: T8409: resolve op-mode config paths independent of edit level
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 = ''