Merge "Fix HTTP sessions left open in Brocade zone driver"

This commit is contained in:
Jenkins 2016-03-02 00:11:27 +00:00 committed by Gerrit Code Review
commit d80beca07a
3 changed files with 39 additions and 5 deletions

View File

@ -200,7 +200,6 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver):
client.add_zones(
zone_map, zone_activate,
cfgmap_from_fabric)
client.cleanup()
except (exception.BrocadeZoningCliException,
exception.BrocadeZoningHttpException) as brocade_ex:
raise exception.FCZoneDriverException(brocade_ex)
@ -208,8 +207,9 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver):
msg = _("Failed to add zoning configuration.")
LOG.exception(msg)
raise exception.FCZoneDriverException(msg)
LOG.debug("Zones added successfully: %(zonemap)s",
{'zonemap': zone_map})
LOG.debug("Zones added successfully: %(zonemap)s",
{'zonemap': zone_map})
client.cleanup()
@lockutils.synchronized('brcd', 'fcfabric-', True)
def delete_connection(self, fabric, initiator_target_map, host_name=None,
@ -342,7 +342,6 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver):
conn.delete_zones(
zone_name_string, zone_activate,
cfgmap_from_fabric)
conn.cleanup()
except (exception.BrocadeZoningCliException,
exception.BrocadeZoningHttpException) as brocade_ex:
raise exception.FCZoneDriverException(brocade_ex)
@ -351,6 +350,8 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver):
"configuration.")
LOG.exception(msg)
raise exception.FCZoneDriverException(msg)
finally:
conn.cleanup()
def get_san_context(self, target_wwn_list):
"""Lookup SAN context for visible end devices.
@ -380,7 +381,6 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver):
nsinfo = conn.get_nameserver_info()
LOG.debug("Name server info from fabric: %(nsinfo)s",
{'nsinfo': nsinfo})
conn.cleanup()
except (exception.BrocadeZoningCliException,
exception.BrocadeZoningHttpException):
if not conn.is_supported_firmware():
@ -395,6 +395,8 @@ class BrcdFCZoneDriver(fc_zone_driver.FCZoneDriver):
msg = _("Failed to get name server info.")
LOG.exception(msg)
raise exception.FCZoneDriverException(msg)
finally:
conn.cleanup()
visible_targets = filter(
lambda x: x in formatted_target_list,
nsinfo)

View File

@ -834,6 +834,37 @@ class BrcdHTTPFCZoneClient(object):
LOG.error(msg)
raise exception.BrocadeZoningHttpException(reason=msg)
def _disconnect(self):
"""Disconnect from the switch using HTTP/HTTPS protocol.
:raises: BrocadeZoningHttpException
"""
try:
headers = {zone_constant.AUTH_HEADER: self.auth_header}
response = self.connect(zone_constant.GET_METHOD,
zone_constant.LOGOUT_PAGE,
header=headers)
return response
except requests.exceptions.ConnectionError as e:
msg = (_("Error while connecting the switch %(switch_id)s "
"with protocol %(protocol)s. Error: %(error)s.")
% {'switch_id': self.switch_ip,
'protocol': self.protocol,
'error': six.text_type(e)})
LOG.error(msg)
raise exception.BrocadeZoningHttpException(reason=msg)
except exception.BrocadeZoningHttpException as ex:
msg = (_("Unexpected status code from the switch %(switch_id)s "
"with protocol %(protocol)s for url %(page)s. "
"Error: %(error)s")
% {'switch_id': self.switch_ip,
'protocol': self.protocol,
'page': zone_constant.LOG_OUT_PAGE,
'error': six.text_type(ex)})
LOG.error(msg)
raise exception.BrocadeZoningHttpException(reason=msg)
def cleanup(self):
"""Close session."""
self._disconnect()
self.session.close()

View File

@ -64,6 +64,7 @@ SESSION_PAGE_ACTION = "/session.html?action=query"
SESSION_BEGIN = "--BEGIN SESSION"
SESSION_END = "--END SESSION"
SESSION_PAGE = "/session.html"
LOGOUT_PAGE = "/logout.html"
ZONEINFO_BEGIN = "--BEGIN ZONE INFO"
ZONEINFO_END = "--END ZONE INFO"
SWITCH_PAGE = "/switch.html"