From d331f0af978f97484ae3689dd225d7cdb2acb968 Mon Sep 17 00:00:00 2001 From: Sumit Naiksatam Date: Thu, 5 Oct 2017 16:28:10 -0700 Subject: [PATCH] Sqlalchemy event unregistering failure in UTs When running most of the UTs, log statements like the following: " No sqlalchemy event for resource router found " are being seen during the UT teardown stage. In the case of the py27 gate job it inundates the log and makes it difficult to find more relevant information. The log warnings are seen because the unregistering of events is attempted twice, and the warning is shown on the second instance. The unregsitering is triggered from the Neutron UT framework and there doesn't seem to be much control over this from GBP. This patch selectively suppresses these messages when running UTs, and the suppressing behavior is limited to the class and method where its considered redundant. Change-Id: I19e83d67b93cfeaa066ef8bd586df8662778dee3 --- gbpservice/neutron/tests/unit/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gbpservice/neutron/tests/unit/__init__.py b/gbpservice/neutron/tests/unit/__init__.py index 845b4fa42..daf401880 100644 --- a/gbpservice/neutron/tests/unit/__init__.py +++ b/gbpservice/neutron/tests/unit/__init__.py @@ -12,6 +12,7 @@ from neutron._i18n import _LI from neutron.agent import securitygroups_rpc from neutron.api import extensions +from neutron.quota import resource from neutron.quota import resource_registry from neutron.scheduler import l3_agent_scheduler from stevedore import named @@ -31,3 +32,22 @@ l3_agent_scheduler.LOG.warning = l3_agent_scheduler.LOG.info securitygroups_rpc.LOG.warning = securitygroups_rpc.LOG.info local_api.LOG.warning = local_api.LOG.info named.LOG.warning = named.LOG.info + + +import sys +orig_warning = resource.LOG.warning + + +def warning(*args): + try: + for val in sys._getframe(1).f_locals.itervalues(): + if isinstance(val, resource.TrackedResource) and ( + sys._getframe(1).f_code.co_name == ( + 'unregister_events')): + return + except Exception: + pass + orig_warning(*args) + + +resource.LOG.warning = warning