diff options
author | John Estabrook <jestabro@sentrium.io> | 2019-11-18 11:11:02 -0600 |
---|---|---|
committer | John Estabrook <jestabro@sentrium.io> | 2019-11-21 14:33:00 -0600 |
commit | 7f0e880400df72d103efb02263658da576a56b80 (patch) | |
tree | 66d483ec774af96aa2ea90a3f69aced8a2fb88c2 /python | |
parent | a7051558ec185f020d3ccb3b01f124e52871aa1c (diff) | |
download | vyos-1x-7f0e880400df72d103efb02263658da576a56b80.tar.gz vyos-1x-7f0e880400df72d103efb02263658da576a56b80.zip |
T1814: Add log of migration scripts run during config migration
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/migrator.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/python/vyos/migrator.py b/python/vyos/migrator.py index 59d68f0f7..06db5a6df 100644 --- a/python/vyos/migrator.py +++ b/python/vyos/migrator.py @@ -30,6 +30,7 @@ class Migrator(object): self._force = force self._set_vintage = set_vintage self._config_file_vintage = None + self._log_file = None self._changed = False def read_config_file_versions(self): @@ -71,11 +72,30 @@ class Migrator(object): else: return True + def open_log_file(self): + """ + Open log file for migration, catching any error. + Note that, on boot, migration takes place before the canonical log + directory is created, hence write to the config file directory. + """ + self._log_file = os.path.join(vyos.defaults.directories['config'], + 'vyos-migrate.log') + try: + log = open('{0}'.format(self._log_file), 'w') + log.write("List of executed migration scripts:\n") + except Exception as e: + print("Logging error: {0}".format(e)) + return None + + return log + def run_migration_scripts(self, config_file_versions, system_versions): """ Run migration scripts iteratively, until config file version equals system component version. """ + log = self.open_log_file() + cfg_versions = config_file_versions sys_versions = system_versions @@ -101,7 +121,7 @@ class Migrator(object): '{}-to-{}'.format(cfg_ver, next_ver)) try: - subprocess.check_output([migrate_script, + subprocess.check_call([migrate_script, self._config_file]) except FileNotFoundError: pass @@ -109,10 +129,19 @@ class Migrator(object): print("Called process error: {}.".format(err)) sys.exit(1) + if log: + try: + log.write('{0}\n'.format(migrate_script)) + except Exception as e: + print("Error writing log: {0}".format(e)) + cfg_ver = next_ver rev_versions[key] = cfg_ver + if log: + log.close() + return rev_versions def write_config_file_versions(self, cfg_versions): |