From 4dbbacc5ff721b6e704e937f5adc23c5b0c1af9b Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 31 May 2023 14:46:42 -0500 Subject: configtree: T5251: catch/raise error in delete and delete_value Configtree functions delete/delete_value do not check return value of libvyosconfig functions; raise error on non-zero return value. --- python/vyos/configtree.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index 19b9838d4..d0cd87464 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -201,7 +201,9 @@ class ConfigTree(object): check_path(path) path_str = " ".join(map(str, path)).encode() - self.__delete(self.__config, path_str) + res = self.__delete(self.__config, path_str) + if (res != 0): + raise ConfigTreeError(f"Path doesn't exist: {path}") if self.__migration: print(f"- op: delete path: {path}") @@ -210,7 +212,14 @@ class ConfigTree(object): check_path(path) path_str = " ".join(map(str, path)).encode() - self.__delete_value(self.__config, path_str, value.encode()) + res = self.__delete_value(self.__config, path_str, value.encode()) + if (res != 0): + if res == 1: + raise ConfigTreeError(f"Path doesn't exist: {path}") + elif res == 2: + raise ConfigTreeError(f"Value doesn't exist: '{value}'") + else: + raise ConfigTreeError() if self.__migration: print(f"- op: delete_value path: {path} value: {value}") -- cgit v1.2.3 From 362ece3add2771bf412131a306fd0c0cfa04c16c Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 31 May 2023 14:51:55 -0500 Subject: migration: T5251: fix incorrect logic in calling configtree.delete The node was already deleted in the 'if path exists' branch; attempt to delete in 'else' branch will now raise an error. --- src/migration-scripts/system/18-to-19 | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/migration-scripts/system/18-to-19 b/src/migration-scripts/system/18-to-19 index fd0e15d42..38479d222 100755 --- a/src/migration-scripts/system/18-to-19 +++ b/src/migration-scripts/system/18-to-19 @@ -92,9 +92,6 @@ else: for intf in dhcp_interfaces: config.set(base + ['name-servers-dhcp'], value=intf, replace=False) - # delete old node - config.delete(base + ['disable-dhcp-nameservers']) - try: with open(file_name, 'w') as f: f.write(config.to_string()) -- cgit v1.2.3