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
This commit is contained in:
Adit Sarfaty 2016-04-07 10:32:32 +03:00
parent 45f809514e
commit b20c3180b4
2 changed files with 34 additions and 1 deletions

View File

@ -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

View File

@ -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()