summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2020-06-15 10:14:34 -0500
committerJohn Estabrook <jestabro@vyos.io>2020-06-16 10:52:35 -0500
commit3891799d970f10a111f0a690537e1aa7e28c5deb (patch)
tree90af7397050424df85372b07819a9232c6a5edea
parent796a815c6014429e2430d9b5d7f68f5127d1c938 (diff)
downloadvyos-1x-3891799d970f10a111f0a690537e1aa7e28c5deb.tar.gz
vyos-1x-3891799d970f10a111f0a690537e1aa7e28c5deb.zip
config: T2568: add missing error checking
-rw-r--r--python/vyos/config.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/python/vyos/config.py b/python/vyos/config.py
index 54cb518c3..f94293e2d 100644
--- a/python/vyos/config.py
+++ b/python/vyos/config.py
@@ -100,23 +100,33 @@ class Config(object):
# once the config system is initialized during boot;
# before initialization, set to empty string
if os.path.isfile('/tmp/vyos-config-status'):
- running_config_text = self._run([self._cli_shell_api, '--show-active-only', '--show-show-defaults', '--show-ignore-edit', 'showConfig'])
+ try:
+ running_config_text = self._run([self._cli_shell_api, '--show-active-only', '--show-show-defaults', '--show-ignore-edit', 'showConfig'])
+ except VyOSError:
+ running_config_text = ''
else:
running_config_text = ''
# Session config ("active") only exists in conf mode.
# In op mode, we'll just use the same running config for both active and session configs.
if self.in_session():
- session_config_text = self._run([self._cli_shell_api, '--show-working-only', '--show-show-defaults', '--show-ignore-edit', 'showConfig'])
+ try:
+ session_config_text = self._run([self._cli_shell_api, '--show-working-only', '--show-show-defaults', '--show-ignore-edit', 'showConfig'])
+ except VyOSError:
+ session_config_text = ''
else:
session_config_text = running_config_text
- self._session_config = vyos.configtree.ConfigTree(session_config_text)
if running_config_text:
self._running_config = vyos.configtree.ConfigTree(running_config_text)
else:
self._running_config = None
+ if session_config_text:
+ self._session_config = vyos.configtree.ConfigTree(session_config_text)
+ else:
+ self._session_config = None
+
def _make_command(self, op, path):
args = path.split()
cmd = [self._cli_shell_api, op] + args
@@ -193,6 +203,8 @@ class Config(object):
This function cannot be used outside a configuration sessions.
In operational mode scripts, use ``exists_effective``.
"""
+ if not self._session_config:
+ return False
if self._session_config.exists(self._make_path(path)):
return True
else:
@@ -362,9 +374,12 @@ class Config(object):
This function cannot be used outside a configuration session.
In operational mode scripts, use ``return_effective_value``.
"""
- try:
- value = self._session_config.return_value(self._make_path(path))
- except vyos.configtree.ConfigTreeError:
+ if self._session_config:
+ try:
+ value = self._session_config.return_value(self._make_path(path))
+ except vyos.configtree.ConfigTreeError:
+ value = None
+ else:
value = None
if not value:
@@ -387,9 +402,12 @@ class Config(object):
This function cannot be used outside a configuration session.
In operational mode scripts, use ``return_effective_values``.
"""
- try:
- values = self._session_config.return_values(self._make_path(path))
- except vyos.configtree.ConfigTreeError:
+ if self._session_config:
+ try:
+ values = self._session_config.return_values(self._make_path(path))
+ except vyos.configtree.ConfigTreeError:
+ values = []
+ else:
values = []
if not values:
@@ -408,9 +426,12 @@ class Config(object):
string list: child node names
"""
- try:
- nodes = self._session_config.list_nodes(self._make_path(path))
- except vyos.configtree.ConfigTreeError:
+ if self._session_config:
+ try:
+ nodes = self._session_config.list_nodes(self._make_path(path))
+ except vyos.configtree.ConfigTreeError:
+ nodes = []
+ else:
nodes = []
if not nodes: