summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-10-19 12:10:43 +0200
committerChristian Poessinger <christian@poessinger.com>2020-10-19 13:06:16 +0200
commit8598a765e8ac9904cacc4abe858873d8a801ef95 (patch)
tree81b3786fa9ba5d50a71c87c159a48d50f9d0e61c /python/vyos
parentd1592875cadcda61b04cb479a5becebbae08d0d4 (diff)
downloadvyos-1x-8598a765e8ac9904cacc4abe858873d8a801ef95.tar.gz
vyos-1x-8598a765e8ac9904cacc4abe858873d8a801ef95.zip
unittests: T2995: vyos_dict_search() must return None on non-existing keys
The current wversion unfortunately will raise a KeyError: >>> data = {} >>> vyos_dict_search('foo', data) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3/dist-packages/vyos/util.py", line 685, in vyos_dict_search return dict[path] KeyError: 'foo'
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/util.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 79e11a86d..b5f0ea36e 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -682,6 +682,8 @@ def vyos_dict_search(path, dict):
parts = path.split('.')
inside = parts[:-1]
if not inside:
+ if path not in dict:
+ return None
return dict[path]
c = dict
for p in parts[:-1]: