summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-05-26 21:14:25 +0200
committerChristian Breunig <christian@breunig.cc>2023-05-26 21:14:25 +0200
commit93d2e99c74af391fe5dcad8be7cf023ffaf06428 (patch)
treecc7d16851faa9699604aafc131c9b2fefc3648e4
parenta8c0a7e25bfff9f05b90c51d6ff6463325098487 (diff)
parentbec69832ef2d6eef4c13635cb50d19b4d850f659 (diff)
downloadvyos-1x-93d2e99c74af391fe5dcad8be7cf023ffaf06428.tar.gz
vyos-1x-93d2e99c74af391fe5dcad8be7cf023ffaf06428.zip
Merge branch 'cli-defined' of https://github.com/jestabro/vyos-1x into t5242-smoketest-dynamic
* 'cli-defined' of https://github.com/jestabro/vyos-1x: T5242: example use of cli_defined xml: T5242: add cli_defined boolean test for node existing under path
-rw-r--r--python/vyos/xml_ref/__init__.py3
-rw-r--r--python/vyos/xml_ref/definition.py25
-rw-r--r--smoketest/scripts/cli/base_interfaces_test.py6
3 files changed, 34 insertions, 0 deletions
diff --git a/python/vyos/xml_ref/__init__.py b/python/vyos/xml_ref/__init__.py
index ae5184746..2e144ef10 100644
--- a/python/vyos/xml_ref/__init__.py
+++ b/python/vyos/xml_ref/__init__.py
@@ -45,6 +45,9 @@ def is_valueless(path: list) -> bool:
def is_leaf(path: list) -> bool:
return load_reference().is_leaf(path)
+def cli_defined(path: list, node: str, non_local=False) -> bool:
+ return load_reference().cli_defined(path, node, non_local=non_local)
+
def component_version() -> dict:
return load_reference().component_version()
diff --git a/python/vyos/xml_ref/definition.py b/python/vyos/xml_ref/definition.py
index 429331577..95ecc01a6 100644
--- a/python/vyos/xml_ref/definition.py
+++ b/python/vyos/xml_ref/definition.py
@@ -92,6 +92,31 @@ class Xml:
d = self._get_ref_path(path)
return self._is_leaf_node(d)
+ @staticmethod
+ def _dict_get(d: dict, path: list) -> dict:
+ for i in path:
+ d = d.get(i, {})
+ if not isinstance(d, dict):
+ return {}
+ if not d:
+ break
+ return d
+
+ def _dict_find(self, d: dict, key: str, non_local=False) -> bool:
+ for k in list(d):
+ if k in ('node_data', 'component_version'):
+ continue
+ if k == key:
+ return True
+ if non_local and isinstance(d[k], dict):
+ if self._dict_find(d[k], key):
+ return True
+ return False
+
+ def cli_defined(self, path: list, node: str, non_local=False) -> bool:
+ d = self._dict_get(self.ref, path)
+ return self._dict_find(d, node, non_local=non_local)
+
def component_version(self) -> dict:
d = {}
for k, v in self.ref['component_version']:
diff --git a/smoketest/scripts/cli/base_interfaces_test.py b/smoketest/scripts/cli/base_interfaces_test.py
index 2f730abfb..aa9c15b65 100644
--- a/smoketest/scripts/cli/base_interfaces_test.py
+++ b/smoketest/scripts/cli/base_interfaces_test.py
@@ -35,6 +35,7 @@ from vyos.util import process_named_running
from vyos.util import get_interface_config
from vyos.validate import is_intf_addr_assigned
from vyos.validate import is_ipv6_link_local
+from vyos.xml_ref import cli_defined
def is_mirrored_to(interface, mirror_if, qdisc):
"""
@@ -82,6 +83,11 @@ class BasicInterfaceTest:
def setUpClass(cls):
super(BasicInterfaceTest.TestCase, cls).setUpClass()
+ # XXX the case of test_vif_8021q_mtu_limits, below, shows that
+ # we should extend cli_defined to support more complex queries
+ cls._test_vlan = cli_defined(cls._base_path, 'vif')
+ cls._test_qinq = cli_defined(cls._base_path, 'vif-s')
+
# Setup mirror interfaces for SPAN (Switch Port Analyzer)
for span in cls._mirror_interfaces:
section = Section.section(span)