From 19215d76d727ca9a36a1ad943034555e989b735c Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 20 Aug 2021 10:28:32 +0200 Subject: [PATCH] ENH: lib/upgrade: pass version_history to functions this allows the upgrade functions to determine if this is a new installation or an upgraded intelmq instance --- CHANGELOG.md | 1 + intelmq/bin/intelmqctl.py | 6 ++++-- intelmq/tests/lib/test_upgrades.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f737e4fba..19aef2076 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ CHANGELOG ### Core - `intelmq.lib.upgrades`: - Refactor upgrade functions global configuration handling removing the old-style defaults configuration (PR#2058 by Sebastian Wagner). + - Pass version history as parameter to upgrade functions (PR#2058 by Sebastian Wagner). ### Development diff --git a/intelmq/bin/intelmqctl.py b/intelmq/bin/intelmqctl.py index 56b1d31d0..c33d8ac31 100644 --- a/intelmq/bin/intelmqctl.py +++ b/intelmq/bin/intelmqctl.py @@ -1671,7 +1671,8 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None, return 1, 'error' try: retval, runtime_new, harmonization_new = getattr( - upgrades, function)(runtime, harmonization, dry_run) + upgrades, function)(runtime, harmonization, dry_run, + version_history=state['version_history']) # Handle changed configurations if retval is True and not dry_run: utils.write_configuration(RUNTIME_CONF_FILE, runtime_new, @@ -1777,7 +1778,8 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None, "time": datetime.datetime.now().isoformat() } try: - retval, runtime, harmonization = function(runtime, harmonization, dry_run) + retval, runtime, harmonization = function(runtime, harmonization, dry_run, + version_history=state['version_history']) except Exception: self.logger.exception('%s: Upgrade failed, please report this bug ' 'with the traceback.', docstring) diff --git a/intelmq/tests/lib/test_upgrades.py b/intelmq/tests/lib/test_upgrades.py index a4d78e7f8..c572f4061 100644 --- a/intelmq/tests/lib/test_upgrades.py +++ b/intelmq/tests/lib/test_upgrades.py @@ -525,7 +525,8 @@ def generate_function(function): def test_function(self): """ Test if no errors happen for upgrade function %s. """ % function.__name__ - function({'global': {}}, {}, dry_run=True) + function({'global': {}}, {}, dry_run=True, + version_history=()) return test_function