Skip to content

Commit

Permalink
ENH: small refactor of upgrade functions
Browse files Browse the repository at this point in the history
merge defaults and runtime configuration, only using the new format with
the global parameters
add **kwargs to the upgrade functions to allow adding more paramters
without breaking the old functions
handle the global parameters in all functions and update the tests
accordingly

Independent of this change, config-upgrade issues may appear in regards
to the defaults config file if intelmq versions are skipped.
  • Loading branch information
Sebastian Wagner committed Aug 20, 2021
1 parent e489bee commit 8f5dc4f
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 179 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CHANGELOG
### Configuration

### Core
- `intelmq.lib.upgrades`:
- Refactor upgrade functions global configuration handling removing the old-style defaults configuration (PR#2058 by Sebastian Wagner).

### Development

Expand Down
17 changes: 5 additions & 12 deletions intelmq/bin/intelmqctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,13 +1649,8 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None,
self.logger.info('Successfully wrote initial state file.')

runtime = utils.load_configuration(RUNTIME_CONF_FILE)
try:
# remove global defaults, handled by 'defaults'
del runtime['global']
except KeyError:
# no global parameters is ok
pass
defaults = utils.get_global_settings()
if 'global' not in runtime:
runtime['global'] = {}
harmonization = utils.load_configuration(HARMONIZATION_CONF_FILE)
if dry_run:
self.logger.info('Doing a dry run, not writing anything now.')
Expand All @@ -1675,11 +1670,10 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None,
', '.join(upgrades.__all__))
return 1, 'error'
try:
retval, defaults_new, runtime_new, harmonization_new = getattr(
upgrades, function)(defaults, runtime, harmonization, dry_run)
retval, runtime_new, harmonization_new = getattr(
upgrades, function)(runtime, harmonization, dry_run)
# Handle changed configurations
if retval is True and not dry_run:
runtime_new['global'] = defaults_new
utils.write_configuration(RUNTIME_CONF_FILE, runtime_new,
backup=not no_backup)
utils.write_configuration(HARMONIZATION_CONF_FILE, harmonization_new,
Expand Down Expand Up @@ -1783,7 +1777,7 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None,
"time": datetime.datetime.now().isoformat()
}
try:
retval, defaults, runtime, harmonization = function(defaults, runtime, harmonization, dry_run)
retval, runtime, harmonization = function(runtime, harmonization, dry_run)
except Exception:
self.logger.exception('%s: Upgrade failed, please report this bug '
'with the traceback.', docstring)
Expand Down Expand Up @@ -1838,7 +1832,6 @@ def upgrade_conf(self, previous=None, dry_run=None, function=None,

try:
if not dry_run:
runtime['global'] = defaults
utils.write_configuration(RUNTIME_CONF_FILE, runtime,
backup=not no_backup)
utils.write_configuration(HARMONIZATION_CONF_FILE, harmonization,
Expand Down
Loading

0 comments on commit 8f5dc4f

Please sign in to comment.