Skip to content

Commit

Permalink
ENH: lib/upgrade: pass version_history to functions
Browse files Browse the repository at this point in the history
this allows the upgrade functions to determine if this is a new
installation or an upgraded intelmq instance
  • Loading branch information
Sebastian Wagner committed Aug 20, 2021
1 parent 8f5dc4f commit 19215d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions intelmq/bin/intelmqctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion intelmq/tests/lib/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 19215d7

Please sign in to comment.