Deactivate app plugins when update fails prior to recovery

When an application update fails and the previous version is recovered,
the plugin infrastructure for the new app version is not fully cleaned
up during recovery. If another application update is attempted, plugin
activation/deactivation becomes out of sync and results in a KeyError
when attempting to enable the new app plugins for update.

This update will:
 - ensure that the failed app plugins are disabled prior to cleanup
   during application recovery
 - catch the KeyError if a similar situation occurs, log a message, and
   continue to cleanup the working set for the plugins

Change-Id: If58942cd9342802bfd2055152c2f2d6289054084
Closes-Bug: #1923004
Signed-off-by: Robert Church <robert.church@windriver.com>
This commit is contained in:
Robert Church 2021-04-08 00:59:50 -04:00
parent b4992c6250
commit 38c0ae47c3
1 changed files with 9 additions and 1 deletions

View File

@ -1527,6 +1527,9 @@ class AppOperator(object):
LOG.info("Starting recover Application %s from version: %s to version: %s" %
(old_app.name, new_app.version, old_app.version))
# Ensure that the the failed app plugins are disabled prior to cleanup
self._plugins.deactivate_plugins(new_app)
self._update_app_status(
old_app, constants.APP_RECOVER_IN_PROGRESS,
constants.APP_PROGRESS_UPDATE_ABORTED.format(old_app.version, new_app.version) +
@ -3803,7 +3806,12 @@ class PluginHelper(object):
# Clean up the working set
for distribution in plugin_distributions:
del pkg_resources.working_set.by_key[distribution]
try:
del pkg_resources.working_set.by_key[distribution]
except KeyError:
LOG.warn("Plugin distribution %s not enabled for version %s"
", but expected to be. Continuing with plugin "
"deactivation." % (distribution, app.version))
del pkg_resources.working_set.entry_keys[app.sync_plugins_dir]
pkg_resources.working_set.entries.remove(app.sync_plugins_dir)