From fde48b4d303b471f8c56b81bc7fcef0a028bb60a Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Thu, 10 Mar 2022 09:34:00 -0600 Subject: Revert "load-config: T4295: use config_tree instead of legacy loadFile" This reverts commit 2a4b45ba7fa4dabf7e592f499cfb06a7ae38cdea. Revert while investigating failure in vyos-configtest. --- src/helpers/vyos-load-config.py | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/helpers/vyos-load-config.py b/src/helpers/vyos-load-config.py index 08f28b24e..e579e81b2 100755 --- a/src/helpers/vyos-load-config.py +++ b/src/helpers/vyos-load-config.py @@ -29,40 +29,15 @@ import gzip import tempfile import vyos.defaults import vyos.remote -from vyos.configsource import ConfigSourceSession -from vyos.configtree import ConfigTree, DiffTree +from vyos.configsource import ConfigSourceSession, VyOSError from vyos.migrator import Migrator, VirtualMigrator, MigratorError -from vyos.util import cmd, DEVNULL class LoadConfig(ConfigSourceSession): - """A subclass for loading a config file. + """A subclass for calling 'loadFile'. This does not belong in configsource.py, and only has a single caller. """ - def load_config(self, file_path): - try: - with open(file_path) as f: - config_file = f.read() - load_ct = ConfigTree(config_file) - except (OSError, ValueError) as e: - print(e) - return - - eff_ct, _ = self.get_configtree_tuple() - diff = DiffTree(eff_ct, load_ct) - commands = diff.to_commands() - # on an empty set of 'add' or 'delete' commands, to_commands - # returns '\n'; prune below - command_list = commands.splitlines() - command_list = [c for c in command_list if c] - - if not command_list: - return - for op in command_list: - try: - cmd(f'/opt/vyatta/sbin/my_{op}', shell=True, stderr=DEVNULL) - except OSError as e: - print(e) - return + def load_config(self, path): + return self._run(['/bin/cli-shell-api','loadFile',path]) file_name = sys.argv[1] if len(sys.argv) > 1 else 'config.boot' configdir = vyos.defaults.directories['config'] @@ -118,7 +93,10 @@ with tempfile.NamedTemporaryFile() as fp: except MigratorError as err: sys.exit('{}'.format(err)) - config.load_config(fp.name) + try: + config.load_config(fp.name) + except VyOSError as err: + sys.exit('{}'.format(err)) if config.session_changed(): print("Load complete. Use 'commit' to make changes effective.") -- cgit v1.2.3