summaryrefslogtreecommitdiff
path: root/python/vyos/migrator.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/vyos/migrator.py')
-rw-r--r--python/vyos/migrator.py31
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):