]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix HTTP sessions left open in Brocade zone driver
authorAngela Smith <aallen@brocade.com>
Wed, 24 Feb 2016 19:18:42 +0000 (11:18 -0800)
committerAngela Smith <aallen@brocade.com>
Mon, 29 Feb 2016 19:09:23 +0000 (11:09 -0800)
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

cinder/zonemanager/drivers/brocade/brcd_fc_zone_driver.py
cinder/zonemanager/drivers/brocade/brcd_http_fc_zone_client.py
cinder/zonemanager/drivers/brocade/fc_zone_constants.py

index b927a6bb71926de3d90ecfe5b0641e8728e7828a..d42990200e1aa1acdeac146008760994e97078d7 100644 (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)
index 7e8093314581658f4d2d23c6521fe91b556a3f27..1ce007f6c9e926162fd7df8d150a2ede26078800 100644 (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()
index e9aa241fdadf57499e4f99dd7a040d5cc01bbf66..18e658e67c2c9f75d04566f2872159d12ffb70d2 100644 (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"