From 2ae39162122386f218f06324b6ea7b9428f7b8c4 Mon Sep 17 00:00:00 2001 From: Nate Johnston Date: Sat, 13 Aug 2016 23:36:52 -0400 Subject: [PATCH] L2 Agent Extensions handle unimplemented methods If an L2 agent extension does not implement the handle_port or delete_port methods, we should check for that using hasattr() beforehand rather than catching any AttributeErrors. This is based on a conversation related to identical code in the L3 agent extensions: https://review.openstack.org/#/c/339246/15/neutron/agent/l3/l3_agent_extensions_manager.py@44 Change-Id: Ic0c5133a9f49c39f1f446328beb3e0ca7eb85095 --- .../agent/l2/l2_agent_extensions_manager.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/neutron/agent/l2/l2_agent_extensions_manager.py b/neutron/agent/l2/l2_agent_extensions_manager.py index d14c2e30b38..bcdc2ca2028 100644 --- a/neutron/agent/l2/l2_agent_extensions_manager.py +++ b/neutron/agent/l2/l2_agent_extensions_manager.py @@ -38,23 +38,23 @@ class L2AgentExtensionsManager(agent_ext_manager.AgentExtensionsManager): def handle_port(self, context, data): """Notify all agent extensions to handle port.""" for extension in self: - try: + if hasattr(extension.obj, 'handle_port'): extension.obj.handle_port(context, data) - except AttributeError: - LOG.exception( - _LE("Agent Extension '%(name)s' failed " - "while handling port update"), + else: + LOG.error( + _LE("Agent Extension '%(name)s' does not " + "implement method handle_port"), {'name': extension.name} ) def delete_port(self, context, data): """Notify all agent extensions to delete port.""" for extension in self: - try: + if hasattr(extension.obj, 'delete_port'): extension.obj.delete_port(context, data) - except AttributeError: - LOG.exception( - _LE("Agent Extension '%(name)s' failed " - "while handling port deletion"), + else: + LOG.error( + _LE("Agent Extension '%(name)s' does not " + "implement method delete_port"), {'name': extension.name} )