From b20c3180b4b640f2a3106f3c91b27373f6da4912 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Thu, 7 Apr 2016 10:32:32 +0300 Subject: [PATCH] NSX|V log warning when getting a router-binding entry with bad status Add a wrapper to the different getters of the nsxv_router_bindings table, to log warnings in case the retrieved entries had an erroneous status. Change-Id: If4671d2fb4a3555de3e0f27b8da44e94f4dd6981 --- requirements.txt | 1 + vmware_nsx/db/nsxv_db.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9e9bdc51a0..e4ce4db10e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,4 @@ oslo.utils>=3.5.0 # Apache-2.0 oslo.vmware>=1.16.0 # Apache-2.0 PrettyTable<0.8,>=0.7 # BSD tooz>=1.28.0 # Apache-2.0 +decorator>=3.4.0 # BSD diff --git a/vmware_nsx/db/nsxv_db.py b/vmware_nsx/db/nsxv_db.py index 42975c87e9..f8f66d1674 100644 --- a/vmware_nsx/db/nsxv_db.py +++ b/vmware_nsx/db/nsxv_db.py @@ -15,6 +15,9 @@ # under the License. import neutron.db.api as db +from neutron.plugins.common import constants as neutron_const + +import decorator from oslo_db import exception as db_exc from oslo_log import log as logging from oslo_utils import excutils @@ -23,7 +26,7 @@ from sqlalchemy import func from sqlalchemy.orm import exc from sqlalchemy.sql import expression as expr -from vmware_nsx._i18n import _, _LE +from vmware_nsx._i18n import _, _LE, _LW from vmware_nsx.common import exceptions as nsx_exc from vmware_nsx.common import nsxv_constants from vmware_nsx.db import nsxv_models @@ -63,21 +66,50 @@ def add_nsxv_router_binding(session, router_id, vse_id, lswitch_id, status, return binding +@decorator.decorator +def warn_on_binding_status_error(f, *args, **kwargs): + result = f(*args, **kwargs) + if result is None: + return + # we support functions that return a single entry or a list + if type(result) == list: + bindings = result + else: + bindings = [result] + + for binding in bindings: + if binding and binding['status'] == neutron_const.ERROR: + LOG.warning(_LW("Found NSXV router binding entry with status " + "%(status)s: router %(router)s, " + "edge %(edge)s, lswitch %(lswitch)s, " + "status description: %(desc)s "), + {'status': binding['status'], + 'router': binding['router_id'], + 'edge': binding['edge_id'], + 'lswitch': binding['lswitch_id'], + 'desc': binding['status_description']}) + return result + + +@warn_on_binding_status_error def get_nsxv_router_binding(session, router_id): return session.query(nsxv_models.NsxvRouterBinding).filter_by( router_id=router_id).first() +@warn_on_binding_status_error def get_nsxv_router_binding_by_edge(session, edge_id): return session.query(nsxv_models.NsxvRouterBinding).filter_by( edge_id=edge_id).first() +@warn_on_binding_status_error def get_nsxv_router_bindings_by_edge(session, edge_id): return session.query(nsxv_models.NsxvRouterBinding).filter_by( edge_id=edge_id).all() +@warn_on_binding_status_error def get_nsxv_router_bindings(session, filters=None, like_filters=None): session = db.get_session()