From 28a696ea625e4113706e030b773fcf39cb1c49a1 Mon Sep 17 00:00:00 2001 From: Angela Smith Date: Fri, 15 Feb 2019 12:23:24 -0800 Subject: [PATCH] Fix for auth version change in Brcd HTTP On FOS 8.1.0b and greater firmwares, the authentication for HTTP sessions has changed. Add check to get the auth version, then authenticate with identifier rather than randomno when authversion is not 1. Also, the formatting of nsinfo.htm has changed, so now using the formatted nsinfo.html page to gather nport wwns from the name server. Change-Id: Ia2773f930513a5c8914e40805291d015a2ecb130 Closes-Bug: #1810327 --- .../test_brcd_http_fc_zone_client.py | 19 ++++---- .../brocade/brcd_http_fc_zone_client.py | 45 +++++++++++-------- .../drivers/brocade/fc_zone_constants.py | 8 ++-- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/cinder/tests/unit/zonemanager/test_brcd_http_fc_zone_client.py b/cinder/tests/unit/zonemanager/test_brcd_http_fc_zone_client.py index 53c4c588e17..70f159be796 100644 --- a/cinder/tests/unit/zonemanager/test_brcd_http_fc_zone_client.py +++ b/cinder/tests/unit/zonemanager/test_brcd_http_fc_zone_client.py @@ -47,6 +47,7 @@ qlps = {} ifas = {} parsed_raw_zoneinfo = "" random_no = '' +auth_version = '' session = None active_cfg = 'openstack_cfg' activate = True @@ -62,15 +63,14 @@ nameserver_info = """
---BEGIN NS INFO
-
-2;8;020800;N    ;10:00:00:05:1e:7c:64:96;20:00:00:05:1e:7c:64:96;[89]""" \
-"""Brocade-825 | 3.0.4.09 | DCM-X3650-94 | Microsoft Windows Server 2003 R2"""\
-    """| Service Pack 2";FCP ;      3;20:08:00:05:1e:89:54:a0;"""\
-    """0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0;000000;port8"""\
-    """
---END NS INFO
-
+--BEGIN DEVICEPORT 10:00:00:05:1e:7c:64:96
+node.wwn=20:00:00:05:1e:7c:64:96
+deviceport.portnum=9
+deviceport.portid=300900
+deviceport.portIndex=9
+deviceport.porttype=N
+deviceport.portwwn=10:00:00:05:1e:7c:64:96
+--END DEVICEPORT 10:00:00:05:1e:7c:64:96
 
@@ -472,6 +472,7 @@ class TestBrcdHttpFCZoneClient(client.BrcdHTTPFCZoneClient, test.TestCase): self.ifas = {} self.parsed_raw_zoneinfo = "" self.random_no = '' + self.auth_version = '' self.session = None super(TestBrcdHttpFCZoneClient, self).setUp() 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 ea53350dd77..57bd7d954c5 100644 --- a/cinder/zonemanager/drivers/brocade/brcd_http_fc_zone_client.py +++ b/cinder/zonemanager/drivers/brocade/brcd_http_fc_zone_client.py @@ -62,6 +62,7 @@ class BrcdHTTPFCZoneClient(object): self.active_cfg = '' self.parsed_raw_zoneinfo = "" self.random_no = '' + self.auth_version = '' self.session = None # Create and assign the authentication header based on the credentials @@ -98,7 +99,7 @@ class BrcdHTTPFCZoneClient(object): adapter = requests.adapters.HTTPAdapter(pool_connections=1, pool_maxsize=1) self.session.mount(protocol + '://', adapter) - url = protocol + "://" + self.switch_ip + requestURL + url = '%s://%s%s' % (protocol, self.switch_ip, requestURL) response = None if requestType == zone_constant.GET_METHOD: response = self.session.get(url, @@ -154,12 +155,19 @@ class BrcdHTTPFCZoneClient(object): zone_constant.SECINFO_BEGIN, zone_constant.SECINFO_END) - # Extract the random no from secinfo.html response - self.random_no = self.get_nvp_value(parsed_data, - zone_constant.RANDOM) - # Form the authentication string - auth_string = (self.switch_user + ":" + self.switch_pwd + - ":" + self.random_no) + # Get the auth version for 8.1.0b+ switches + self.auth_version = self.get_nvp_value(parsed_data, + zone_constant.AUTHVERSION) + + if self.auth_version == "1": + # Extract the random no from secinfo.html response + self.random_no = self.get_nvp_value(parsed_data, + zone_constant.RANDOM) + # Form the authentication string + auth_string = '%s:%s:%s' % (self.switch_user, self.switch_pwd, + self.random_no) + else: + auth_string = '%s:%s' % (self.switch_user, self.switch_pwd) auth_token = base64.encode_as_text(auth_string).strip() auth_header = (zone_constant.AUTH_STRING + auth_token) # Build the proper header @@ -191,9 +199,14 @@ class BrcdHTTPFCZoneClient(object): isauthenticated = self.get_nvp_value( parsed_data, zone_constant.AUTHENTICATED) if isauthenticated == "yes": - # Replace password in the authentication string with xxx - auth_string = (self.switch_user + - ":" + "xxx" + ":" + self.random_no) + if self.auth_version == "3": + auth_id = self.get_nvp_value(parsed_data, + zone_constant.IDENTIFIER) + auth_string = '%s:xxx:%s' % (self.switch_user, auth_id) + else: + # Replace password in the authentication string with xxx + auth_string = '%s:xxx:%s' % (self.switch_user, + self.random_no) auth_token = base64.encode_as_text(auth_string).strip() auth_header = zone_constant.AUTH_STRING + auth_token return True, auth_header @@ -763,15 +776,9 @@ class BrcdHTTPFCZoneClient(object): response = self.connect(zone_constant.GET_METHOD, zone_constant.NS_PAGE, header=headers) # GET request to nsinfo.html - parsed_raw_zoneinfo = self.get_parsed_data( - response, - zone_constant.NSINFO_BEGIN, - zone_constant.NSINFO_END).strip("\t\n\r") - # build the name server information in the correct format - for line in parsed_raw_zoneinfo.splitlines(): - start_index = line.find(zone_constant.NS_DELIM) + 7 - if start_index != -1: - nsinfo.extend([line[start_index:start_index + 23].strip()]) + for line in response.splitlines(): + if line.startswith(zone_constant.NS_DELIM): + nsinfo.append(line.split('=')[-1]) return nsinfo def delete_zones_cfgs( diff --git a/cinder/zonemanager/drivers/brocade/fc_zone_constants.py b/cinder/zonemanager/drivers/brocade/fc_zone_constants.py index 8af6333ea5b..d49a23c4015 100644 --- a/cinder/zonemanager/drivers/brocade/fc_zone_constants.py +++ b/cinder/zonemanager/drivers/brocade/fc_zone_constants.py @@ -58,6 +58,8 @@ POST_METHOD = "POST" SECINFO_BEGIN = "--BEGIN SECINFO" SECINFO_END = "--END SECINFO" RANDOM = "RANDOM" +AUTHVERSION = "AUTHVERSION" +IDENTIFIER = "Identifier" AUTH_STRING = "Custom_Basic " # Trailing space is required, do not remove AUTHEN_BEGIN = "--BEGIN AUTHENTICATE" AUTHEN_END = "--END AUTHENTICATE" @@ -86,10 +88,8 @@ ZONE_END_DELIM = "\x05&saveonly=" IFA_DELIM = "\x06" ACTIVE_CFG_DELIM = "\x07" DEFAULT_CFG = "d__efault__Cfg" -NS_PAGE = "/nsinfo.htm" -NSINFO_BEGIN = "--BEGIN NS INFO" -NSINFO_END = "--END NS INFO" -NS_DELIM = ";N ;" +NS_PAGE = "/nsinfo.htm?format=1&type=all" +NS_DELIM = "deviceport.portwwn=" ZONE_TX_BEGIN = "--BEGIN ZONE_TXN_INFO" ZONE_TX_END = "--END ZONE_TXN_INFO" ZONE_ERROR_CODE = "errorCode"