Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: small refactor of upgrade functions #2058

Merged
3 commits merged into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ CHANGELOG
### Configuration

### 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: 5 additions & 1 deletion docs/user/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ Check your installation and configuration to detect any problems:
intelmqctl upgrade-config
intelmqctl check

## Start IntelMQ
``intelmqctl upgrade-config`` supports upgrades from one IntelMQ version to the succeeding.
If you skip one or more IntelMQ versions, some automatic upgrades *may not* work and manual intervention *may* be necessary.

Start IntelMQ
-------------

.. code-block:: bash

Expand Down
21 changes: 8 additions & 13 deletions intelmq/bin/intelmqctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ def check(self, no_connections=False):
if extra_type != 'JSONDict':
check_logger.warning("'extra' field needs to be of type 'JSONDict'.")
retval = 1
if upgrades.harmonization({}, {}, files[HARMONIZATION_CONF_FILE],
if upgrades.harmonization({}, files[HARMONIZATION_CONF_FILE],
dry_run=True)[0]:
check_logger.warning("Harmonization needs an upgrade, call "
"intelmqctl upgrade-config.")
Expand Down 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,11 @@ 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,
version_history=state['version_history'])
# 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 +1778,8 @@ 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,
version_history=state['version_history'])
except Exception:
self.logger.exception('%s: Upgrade failed, please report this bug '
'with the traceback.', docstring)
Expand Down Expand Up @@ -1838,7 +1834,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