From f6241f4ef8edd19eb2b921779ee2f44fb0ba34dc Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Mon, 29 Oct 2018 14:13:47 +0200 Subject: [PATCH] TVD: Do not crash in case the project is not found When the different service plugins filter the list results by the project id of the current requestor, the code should not raise an error if one of the objects project was not found. Instead that object will be skipped, and a message will be logged. Change-Id: Ia78f059e1334a23cd9cda07a8981d1f74ae2c430 --- vmware_nsx/plugins/nsx/utils.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/plugins/nsx/utils.py b/vmware_nsx/plugins/nsx/utils.py index 6cde964964..8bf68f3a58 100644 --- a/vmware_nsx/plugins/nsx/utils.py +++ b/vmware_nsx/plugins/nsx/utils.py @@ -14,6 +14,7 @@ # under the License. from oslo_config import cfg +from oslo_log import log from neutron_lib import context as n_context from neutron_lib import exceptions @@ -21,6 +22,8 @@ from neutron_lib.plugins import directory from vmware_nsx.db import db as nsx_db +LOG = log.getLogger(__name__) + def is_tvd_core_plugin(): core_plugin = cfg.CONF.core_plugin @@ -63,14 +66,22 @@ def filter_plugins(cls): by the project id of the context """ entries = orig_method(self, context, **kwargs) - if not context.project_id: + if not context.project_id or not entries: return entries req_p = get_project_mapping(context, context.project_id) for entry in entries[:]: if entry.get('tenant_id'): - p = get_project_mapping(context, entry['tenant_id']) - if p != req_p: + try: + p = get_project_mapping(context, entry['tenant_id']) + except exceptions.ObjectNotFound: + # This could be a project that was already deleted + LOG.info("Project %s is not associated with any " + "plugin and will be ignored", + entry['tenant_id']) entries.remove(entry) + else: + if p != req_p: + entries.remove(entry) return entries