From bd6f3f6534a93f8a8c64e06967c24d4c3827c517 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 12 Jun 2019 12:45:00 -0500 Subject: T1397: check for path argument in both effective and merge config The merge config script restores the ability to restrict changes to a specified path. In the initial implementation, the path was checked for validity only with respect to the effective config; fix to allow valid paths from merge config as well. --- src/helpers/vyos-merge-config.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/helpers/vyos-merge-config.py') diff --git a/src/helpers/vyos-merge-config.py b/src/helpers/vyos-merge-config.py index e97a1c08d..e9a14ae98 100755 --- a/src/helpers/vyos-merge-config.py +++ b/src/helpers/vyos-merge-config.py @@ -57,10 +57,6 @@ else: print(err) sys.exit(1) -path = None -if (len(sys.argv) > 2): - path = " ".join(sys.argv[2:]) - with tempfile.NamedTemporaryFile() as file_to_migrate: with open(file_to_migrate.name, 'w') as fd: fd.write(config_file) @@ -91,12 +87,19 @@ merge_cmd_list = merge_cmds.splitlines() effective_cmd_set = set(effective_cmd_list) add_cmds = [ cmd for cmd in merge_cmd_list if cmd not in effective_cmd_set ] -if path: - if not effective_config.exists(path): - print("path {} does not exist in running config; will use " - "root.".format(path)) +path = None +if (len(sys.argv) > 2): + path = sys.argv[2:] + if (not effective_config_tree.exists(path) and not + merge_config_tree.exists(path)): + print("path {} does not exist in either effective or merge" + " config; will use root.".format(path)) + path = None else: - add_cmds = [ cmd for cmd in add_cmds if path in cmd ] + path = " ".join(path) + +if path: + add_cmds = [ cmd for cmd in add_cmds if path in cmd ] for cmd in add_cmds: cmd = "/opt/vyatta/sbin/my_" + cmd -- cgit v1.2.3