Remove metadata from apps_metadata dict when deleting app

When some application is deleted, it's information remains
cached in all dicts and lists from apps_metadata, with this
structure:

    apps_metadata =
        {apps: {},
        platform_managed_apps_list: {},
        desired_states: {},
        ordered_apps: []}

The mentioned behavior was causing a bug after an upgrade from
stx 6 to stx 8, because an app that has no support in stx 8 is
deleted but continue cached in apps_metadata, and when
k8s_application_audit() is run after the upgrade is complete,
the system uses the cached list to try to upload this app until
the upload-failed state appears in the alarms list.

Now the created method is called right after deleting an
application, this way the app will be completely out of the
system.

Test-Plan:
  PASS: Ugrade from stx 6.0 to 8.0 in a standard config lab.
  PASS: During the upgrade, an app from the previous version
  which has no support in the next version is automatically
deleted.
  PASS: Validate that the deleted app is not in any
  collection from apps_metadata.
  PASS: Validate that the upload try of the deleted app doesn't
happen anymore.

Closes-Bug: 2009025

Signed-off-by: Gabriel de Araújo Cabral <gabriel.cabral@windriver.com>
Change-Id: I6a54218b398493acc931c5eca34b800383b16cc0
This commit is contained in:
Gabriel de Araújo Cabral 2023-03-02 06:58:17 -05:00
parent 3f20541077
commit b1f44a16d0
1 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (c) 2018-2022 Wind River Systems, Inc.
# Copyright (c) 2018-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@ -2891,6 +2891,24 @@ class AppOperator(object):
app.name,
metadata)
def _remove_from_metadata_dict(self, app_name):
"""Remove all the information about an app in apps_metadada dict
This method will perform the removal of an app in all collections from
self._apps_metadata. It is called after an application delete.
:param app_name: Name of the app
"""
if app_name in self._apps_metadata[constants.APP_METADATA_APPS]:
del self._apps_metadata[constants.APP_METADATA_APPS][app_name]
if app_name in self._apps_metadata[constants.APP_METADATA_PLATFORM_MANAGED_APPS]:
del self._apps_metadata[constants.APP_METADATA_PLATFORM_MANAGED_APPS][app_name]
if app_name in self._apps_metadata[constants.APP_METADATA_DESIRED_STATES]:
del self._apps_metadata[constants.APP_METADATA_DESIRED_STATES][app_name]
if app_name in self._apps_metadata[constants.APP_METADATA_ORDERED_APPS]:
self._apps_metadata[constants.APP_METADATA_ORDERED_APPS].remove(app_name)
def perform_app_apply(self, rpc_app, mode, lifecycle_hook_info_app_apply, caller=None):
"""Process application install request
@ -3540,6 +3558,10 @@ class AppOperator(object):
# One last check of app alarm, should be no-op unless the
# user deletes the application following an upload failure.
self._clear_app_alarm(app.name)
# Remove the deleted app from _apps_metadata, since it's
# not in the system anymore.
self._remove_from_metadata_dict(app.name)
LOG.info("Application (%s) has been purged from the system." %
app.name)
msg = None