From d41b9e56058c50117e70c7d2639ebbead466da27 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 30 Mar 2020 15:12:06 -0500 Subject: migration: T2029: set default vintage; remove target from virtual The VirtualMigrator updates the syntax of the component version string. Remove the default target, allowing downgrade to old syntax. --- src/helpers/run-config-migration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helpers') diff --git a/src/helpers/run-config-migration.py b/src/helpers/run-config-migration.py index a57a19cdf..6ffd038f3 100755 --- a/src/helpers/run-config-migration.py +++ b/src/helpers/run-config-migration.py @@ -72,7 +72,7 @@ def main(): migration = Migrator(config_file_name, force=force_on, set_vintage=vintage) else: - migration = VirtualMigrator(config_file_name) + migration = VirtualMigrator(config_file_name, set_vintage=vintage) migration.run() -- cgit v1.2.3 From 10b2b9d9bd9e8da76247651c996627a7921a04c3 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 30 Mar 2020 15:13:48 -0500 Subject: migration: T2029: run virtual migration before migration Update syntax of component version string, before passing config file to configtree in migration scripts. --- python/vyos/migrator.py | 3 +-- src/helpers/run-config-migration.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/helpers') diff --git a/python/vyos/migrator.py b/python/vyos/migrator.py index e60d862ff..7d77e6bac 100644 --- a/python/vyos/migrator.py +++ b/python/vyos/migrator.py @@ -209,8 +209,7 @@ class VirtualMigrator(Migrator): cfg_versions = self.read_config_file_versions() if not cfg_versions: - raise MigratorError("Config file has no version information;" - " virtual migration not possible.") + return if self.update_vintage(): self._changed = True diff --git a/src/helpers/run-config-migration.py b/src/helpers/run-config-migration.py index 6ffd038f3..3c06e38f8 100755 --- a/src/helpers/run-config-migration.py +++ b/src/helpers/run-config-migration.py @@ -69,15 +69,22 @@ def main(): sys.exit(1) if not virtual: - migration = Migrator(config_file_name, force=force_on, - set_vintage=vintage) + virtual_migration = VirtualMigrator(config_file_name) + virtual_migration.run() + + migration = Migrator(config_file_name, force=force_on) + migration.run() + + if not migration.config_changed(): + os.remove(backup_file_name) else: - migration = VirtualMigrator(config_file_name, set_vintage=vintage) + virtual_migration = VirtualMigrator(config_file_name, + set_vintage=vintage) - migration.run() + virtual_migration.run() - if not migration._changed: - os.remove(backup_file_name) + if not virtual_migration.config_changed(): + os.remove(backup_file_name) if __name__ == '__main__': main() -- cgit v1.2.3 From b8ff6641837c164b056324e9eca5f266023472d7 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 30 Mar 2020 15:17:59 -0500 Subject: config merge: T2052: update for version string syntax change --- src/helpers/vyos-merge-config.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/helpers') diff --git a/src/helpers/vyos-merge-config.py b/src/helpers/vyos-merge-config.py index c5216daa6..10a5ea4bc 100755 --- a/src/helpers/vyos-merge-config.py +++ b/src/helpers/vyos-merge-config.py @@ -21,9 +21,9 @@ import subprocess import tempfile import vyos.defaults import vyos.remote -import vyos.migrator from vyos.config import Config from vyos.configtree import ConfigTree +from vyos.migrator import Migrator, VirtualMigrator if (len(sys.argv) < 2): @@ -61,9 +61,13 @@ with tempfile.NamedTemporaryFile() as file_to_migrate: with open(file_to_migrate.name, 'w') as fd: fd.write(config_file) - migration = vyos.migrator.Migrator(file_to_migrate.name) + virtual_migration = VirtualMigrator(file_to_migrate.name) + virtual_migration.run() + + migration = Migrator(file_to_migrate.name) migration.run() - if migration.config_changed(): + + if virtual_migration.config_changed() or migration.config_changed(): with open(file_to_migrate.name, 'r') as fd: config_file = fd.read() -- cgit v1.2.3 From 1c74d7ec8a239427c8f7e9f6d864c5085372b0e6 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 30 Mar 2020 16:32:14 -0500 Subject: config load: T2053: update for version string syntax change --- src/helpers/vyos-load-config.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/helpers') diff --git a/src/helpers/vyos-load-config.py b/src/helpers/vyos-load-config.py index 4e6d67efa..693529c23 100755 --- a/src/helpers/vyos-load-config.py +++ b/src/helpers/vyos-load-config.py @@ -28,7 +28,7 @@ import tempfile import vyos.defaults import vyos.remote from vyos.config import Config, VyOSError -from vyos.migrator import Migrator, MigratorError +from vyos.migrator import Migrator, VirtualMigrator, MigratorError system_config_file = 'config.boot' @@ -73,6 +73,12 @@ with tempfile.NamedTemporaryFile() as fp: with open(fp.name, 'w') as fd: fd.write(config_file) + virtual_migration = VirtualMigrator(fp.name) + try: + virtual_migration.run() + except MigratorError as err: + sys.exit('{}'.format(err)) + migration = Migrator(fp.name) try: migration.run() -- cgit v1.2.3