From 5c96825f6df16d3ad5bd0bf72e6ed589ac25552e Mon Sep 17 00:00:00 2001 From: Angela Smith Date: Wed, 24 Feb 2016 11:18:42 -0800 Subject: [PATCH] Fix HTTP sessions left open in Brocade zone driver Add missing call to logout html page on FC switch to close the HTTP session on the FC switch in HTTP connector. Also, move the session cleanup calls in the zone driver so that it is invoked for all code paths. Change-Id: Id08c1b1f1e75188cacfb9b5586519a7fee827602 --- .../drivers/brocade/brcd_fc_zone_driver.py | 12 ++++--- .../brocade/brcd_http_fc_zone_client.py | 31 +++++++++++++++++++ .../drivers/brocade/fc_zone_constants.py | 1 + 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py index b927a6bb7..d42990200 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py +++ b/cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py @@ -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) diff --git a/cinder/zonemanager/drivers/brocade/brcd_http_fc_zone_client.py b/cinder/zonemanager/drivers/brocade/brcd_http_fc_zone_client.py index 7e8093314..1ce007f6c 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_http_fc_zone_client.py +++ b/cinder/zonemanager/drivers/brocade/brcd_http_fc_zone_client.py @@ -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() diff --git a/cinder/zonemanager/drivers/brocade/fc_zone_constants.py b/cinder/zonemanager/drivers/brocade/fc_zone_constants.py index e9aa241fd..18e658e67 100644 --- a/cinder/zonemanager/drivers/brocade/fc_zone_constants.py +++ b/cinder/zonemanager/drivers/brocade/fc_zone_constants.py @@ -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" -- 2.45.2