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
This commit is contained in:
Nate Johnston 2016-08-13 23:36:52 -04:00
parent c96f48162a
commit 2ae3916212
1 changed files with 10 additions and 10 deletions

View File

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