Merge "Fix for auth version change in Brcd HTTP" into stable/rocky

This commit is contained in:
Zuul 2019-02-27 22:40:41 +00:00 committed by Gerrit Code Review
commit 61f9bbf700
3 changed files with 40 additions and 32 deletions

View File

@ -47,6 +47,7 @@ qlps = {}
ifas = {} ifas = {}
parsed_raw_zoneinfo = "" parsed_raw_zoneinfo = ""
random_no = '' random_no = ''
auth_version = ''
session = None session = None
active_cfg = 'openstack_cfg' active_cfg = 'openstack_cfg'
activate = True activate = True
@ -62,15 +63,14 @@ nameserver_info = """
</HEAD> </HEAD>
<BODY> <BODY>
<PRE> <PRE>
--BEGIN NS INFO --BEGIN DEVICEPORT 10:00:00:05:1e:7c:64:96
node.wwn=20:00:00:05:1e:7c:64:96
2;8;020800;N ;10:00:00:05:1e:7c:64:96;20:00:00:05:1e:7c:64:96;[89]""" \ deviceport.portnum=9
"""Brocade-825 | 3.0.4.09 | DCM-X3650-94 | Microsoft Windows Server 2003 R2"""\ deviceport.portid=300900
"""| Service Pack 2";FCP ; 3;20:08:00:05:1e:89:54:a0;"""\ deviceport.portIndex=9
"""0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0;000000;port8"""\ deviceport.porttype=N
""" deviceport.portwwn=10:00:00:05:1e:7c:64:96
--END NS INFO --END DEVICEPORT 10:00:00:05:1e:7c:64:96
</PRE> </PRE>
</BODY> </BODY>
</HTML> </HTML>
@ -472,6 +472,7 @@ class TestBrcdHttpFCZoneClient(client.BrcdHTTPFCZoneClient, test.TestCase):
self.ifas = {} self.ifas = {}
self.parsed_raw_zoneinfo = "" self.parsed_raw_zoneinfo = ""
self.random_no = '' self.random_no = ''
self.auth_version = ''
self.session = None self.session = None
super(TestBrcdHttpFCZoneClient, self).setUp() super(TestBrcdHttpFCZoneClient, self).setUp()

View File

@ -62,6 +62,7 @@ class BrcdHTTPFCZoneClient(object):
self.active_cfg = '' self.active_cfg = ''
self.parsed_raw_zoneinfo = "" self.parsed_raw_zoneinfo = ""
self.random_no = '' self.random_no = ''
self.auth_version = ''
self.session = None self.session = None
# Create and assign the authentication header based on the credentials # Create and assign the authentication header based on the credentials
@ -98,7 +99,7 @@ class BrcdHTTPFCZoneClient(object):
adapter = requests.adapters.HTTPAdapter(pool_connections=1, adapter = requests.adapters.HTTPAdapter(pool_connections=1,
pool_maxsize=1) pool_maxsize=1)
self.session.mount(protocol + '://', adapter) self.session.mount(protocol + '://', adapter)
url = protocol + "://" + self.switch_ip + requestURL url = '%s://%s%s' % (protocol, self.switch_ip, requestURL)
response = None response = None
if requestType == zone_constant.GET_METHOD: if requestType == zone_constant.GET_METHOD:
response = self.session.get(url, response = self.session.get(url,
@ -154,12 +155,19 @@ class BrcdHTTPFCZoneClient(object):
zone_constant.SECINFO_BEGIN, zone_constant.SECINFO_BEGIN,
zone_constant.SECINFO_END) zone_constant.SECINFO_END)
# Extract the random no from secinfo.html response # Get the auth version for 8.1.0b+ switches
self.random_no = self.get_nvp_value(parsed_data, self.auth_version = self.get_nvp_value(parsed_data,
zone_constant.RANDOM) zone_constant.AUTHVERSION)
# Form the authentication string
auth_string = (self.switch_user + ":" + self.switch_pwd + if self.auth_version == "1":
":" + self.random_no) # 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_token = base64.encode_as_text(auth_string).strip()
auth_header = (zone_constant.AUTH_STRING + auth_header = (zone_constant.AUTH_STRING +
auth_token) # Build the proper header auth_token) # Build the proper header
@ -191,9 +199,14 @@ class BrcdHTTPFCZoneClient(object):
isauthenticated = self.get_nvp_value( isauthenticated = self.get_nvp_value(
parsed_data, zone_constant.AUTHENTICATED) parsed_data, zone_constant.AUTHENTICATED)
if isauthenticated == "yes": if isauthenticated == "yes":
# Replace password in the authentication string with xxx if self.auth_version == "3":
auth_string = (self.switch_user + auth_id = self.get_nvp_value(parsed_data,
":" + "xxx" + ":" + self.random_no) 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_token = base64.encode_as_text(auth_string).strip()
auth_header = zone_constant.AUTH_STRING + auth_token auth_header = zone_constant.AUTH_STRING + auth_token
return True, auth_header return True, auth_header
@ -763,15 +776,9 @@ class BrcdHTTPFCZoneClient(object):
response = self.connect(zone_constant.GET_METHOD, response = self.connect(zone_constant.GET_METHOD,
zone_constant.NS_PAGE, zone_constant.NS_PAGE,
header=headers) # GET request to nsinfo.html header=headers) # GET request to nsinfo.html
parsed_raw_zoneinfo = self.get_parsed_data( for line in response.splitlines():
response, if line.startswith(zone_constant.NS_DELIM):
zone_constant.NSINFO_BEGIN, nsinfo.append(line.split('=')[-1])
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()])
return nsinfo return nsinfo
def delete_zones_cfgs( def delete_zones_cfgs(

View File

@ -58,6 +58,8 @@ POST_METHOD = "POST"
SECINFO_BEGIN = "--BEGIN SECINFO" SECINFO_BEGIN = "--BEGIN SECINFO"
SECINFO_END = "--END SECINFO" SECINFO_END = "--END SECINFO"
RANDOM = "RANDOM" RANDOM = "RANDOM"
AUTHVERSION = "AUTHVERSION"
IDENTIFIER = "Identifier"
AUTH_STRING = "Custom_Basic " # Trailing space is required, do not remove AUTH_STRING = "Custom_Basic " # Trailing space is required, do not remove
AUTHEN_BEGIN = "--BEGIN AUTHENTICATE" AUTHEN_BEGIN = "--BEGIN AUTHENTICATE"
AUTHEN_END = "--END AUTHENTICATE" AUTHEN_END = "--END AUTHENTICATE"
@ -86,10 +88,8 @@ ZONE_END_DELIM = "\x05&saveonly="
IFA_DELIM = "\x06" IFA_DELIM = "\x06"
ACTIVE_CFG_DELIM = "\x07" ACTIVE_CFG_DELIM = "\x07"
DEFAULT_CFG = "d__efault__Cfg" DEFAULT_CFG = "d__efault__Cfg"
NS_PAGE = "/nsinfo.htm" NS_PAGE = "/nsinfo.htm?format=1&type=all"
NSINFO_BEGIN = "--BEGIN NS INFO" NS_DELIM = "deviceport.portwwn="
NSINFO_END = "--END NS INFO"
NS_DELIM = ";N ;"
ZONE_TX_BEGIN = "--BEGIN ZONE_TXN_INFO" ZONE_TX_BEGIN = "--BEGIN ZONE_TXN_INFO"
ZONE_TX_END = "--END ZONE_TXN_INFO" ZONE_TX_END = "--END ZONE_TXN_INFO"
ZONE_ERROR_CODE = "errorCode" ZONE_ERROR_CODE = "errorCode"