summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-08-08 14:24:00 -0500
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-08-13 00:43:25 +0000
commita6362cc32135b39b4320221006f48fef78f40c24 (patch)
tree82a6fd7325f2b0314d2c8a411fc8520d7d587a55 /python
parente1d5cb8b56a6b103afa7326d94291e64bd2eba47 (diff)
downloadvyos-1x-a6362cc32135b39b4320221006f48fef78f40c24.tar.gz
vyos-1x-a6362cc32135b39b4320221006f48fef78f40c24.zip
configverify: T6642: verify_interface_exists requires config_dict argmergify/bp/sagitta/pr-3961
The function verify_interface_exists requires a reference to the ambient config_dict rather than creating an instance. As access is required to the 'interfaces' path, provide as attribute of class ConfigDict, so as not to confuse path searches of script-specific config_dict instances. (cherry picked from commit 5f23b7275564cfaa7c178d320868b5f5e86ae606)
Diffstat (limited to 'python')
-rw-r--r--python/vyos/config.py3
-rw-r--r--python/vyos/configverify.py6
2 files changed, 5 insertions, 4 deletions
diff --git a/python/vyos/config.py b/python/vyos/config.py
index b7ee606a9..1fab46761 100644
--- a/python/vyos/config.py
+++ b/python/vyos/config.py
@@ -344,6 +344,9 @@ class Config(object):
conf_dict['pki'] = pki_dict
+ interfaces_root = root_dict.get('interfaces', {})
+ setattr(conf_dict, 'interfaces_root', interfaces_root)
+
# save optional args for a call to get_config_defaults
setattr(conf_dict, '_dict_kwargs', kwargs)
diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py
index b49d66c36..59b67300d 100644
--- a/python/vyos/configverify.py
+++ b/python/vyos/configverify.py
@@ -237,7 +237,7 @@ def verify_bridge_delete(config):
raise ConfigError(f'Interface "{interface}" cannot be deleted as it '
f'is a member of bridge "{bridge_name}"!')
-def verify_interface_exists(ifname, state_required=False, warning_only=False):
+def verify_interface_exists(config, ifname, state_required=False, warning_only=False):
"""
Common helper function used by interface implementations to perform
recurring validation if an interface actually exists. We first probe
@@ -245,14 +245,12 @@ def verify_interface_exists(ifname, state_required=False, warning_only=False):
it exists at the OS level.
"""
from vyos.base import Warning
- from vyos.configquery import ConfigTreeQuery
from vyos.utils.dict import dict_search_recursive
from vyos.utils.network import interface_exists
if not state_required:
# Check if interface is present in CLI config
- config = ConfigTreeQuery()
- tmp = config.get_config_dict(['interfaces'], get_first_key=True)
+ tmp = getattr(config, 'interfaces_root', {})
if bool(list(dict_search_recursive(tmp, ifname))):
return True