scripts:Fix Python errors in checking scripts

Python3 (3.6.7) gives W605 errors in regular expressions, causing the
SPDK style checks to fail on the Python scripts doing the style checking.

This fix allows these Python scripts to run without errors.

This is a known issue - see https://github.com/PyCQA/pycodestyle/issues/814

Change-Id: I71cdff5d6c89e19b200c989f3d9da35bb4f7189d
Signed-off-by: James Bergsten <jamesx.bergsten@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443955
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
James Bergsten 2019-02-08 09:50:49 -08:00 committed by Jim Harris
parent 14c18abb7a
commit 0c93fc7330
4 changed files with 32 additions and 32 deletions

View File

@ -166,7 +166,7 @@ def get_aio_bdev_json(config, section):
if value is None: if value is None:
return aio_json return aio_json
for item in value: for item in value:
items = re.findall("\S+", item) items = re.findall(r"\S+", item)
params = {} params = {}
params['filename'] = items[0] params['filename'] = items[0]
params['name'] = items[1] params['name'] = items[1]
@ -215,12 +215,12 @@ def get_nvme_bdev_json(config, section):
for option in config.options("Nvme"): for option in config.options("Nvme"):
value = config.get("Nvme", option) value = config.get("Nvme", option)
if "TransportID" == option: if "TransportID" == option:
entry = re.findall("\S+", value) entry = re.findall(r"\S+", value)
nvme_name = entry[-1] nvme_name = entry[-1]
trtype = re.findall("trtype:\S+", value) trtype = re.findall(r"trtype:\S+", value)
if trtype: if trtype:
trtype = trtype[0].replace("trtype:", "").replace("\"", "") trtype = trtype[0].replace("trtype:", "").replace("\"", "")
traddr = re.findall("traddr:\S+", value) traddr = re.findall(r"traddr:\S+", value)
if traddr: if traddr:
traddr = traddr[0].replace("traddr:", "").replace("\"", "") traddr = traddr[0].replace("traddr:", "").replace("\"", "")
nvme_json.append({ nvme_json.append({
@ -251,7 +251,7 @@ def get_pmem_bdev_json(config, section):
for option in config.options(section): for option in config.options(section):
if "Blk" == option: if "Blk" == option:
for value in config.get(section, option).split("\n"): for value in config.get(section, option).split("\n"):
items = re.findall("\S+", value) items = re.findall(r"\S+", value)
pmem_json.append({ pmem_json.append({
"params": { "params": {
"name": items[1], "name": items[1],
@ -272,7 +272,7 @@ def get_split_bdev_json(config, section):
if value and not isinstance(value, list): if value and not isinstance(value, list):
value = [value] value = [value]
for split in value: for split in value:
items = re.findall("\S+", split) items = re.findall(r"\S+", split)
split_size_mb = 0 split_size_mb = 0
base_bdev = items[0] base_bdev = items[0]
split_count = int(items[1]) split_count = int(items[1])
@ -330,7 +330,7 @@ def get_nvmf_subsystem_json(config, section):
set_param(params, option, value) set_param(params, option, value)
continue continue
if "Listen" == option: if "Listen" == option:
items = re.findall("\S+", value) items = re.findall(r"\S+", value)
adrfam = "IPv4" adrfam = "IPv4"
if len(items[1].split(":")) > 2: if len(items[1].split(":")) > 2:
adrfam = "IPv6" adrfam = "IPv6"
@ -343,7 +343,7 @@ def get_nvmf_subsystem_json(config, section):
}) })
if "Namespace" == option: if "Namespace" == option:
for item in value.split("\n"): for item in value.split("\n"):
items = re.findall("\S+", item) items = re.findall(r"\S+", item)
if len(items) == 2: if len(items) == 2:
nsid = items[1] nsid = items[1]
else: else:
@ -404,7 +404,7 @@ def get_vhost_scsi_json(config, section):
set_param(params, option, value) set_param(params, option, value)
if "Target" == option: if "Target" == option:
for item in value.split("\n"): for item in value.split("\n"):
items = re.findall("\S+", item) items = re.findall(r"\S+", item)
targets.append({ targets.append({
"scsi_target_num": int(items[0]), "scsi_target_num": int(items[0]),
"ctrlr": params[0][3], "ctrlr": params[0][3],
@ -523,7 +523,7 @@ def get_iscsi_portal_group_json(config, name):
for option in config.options(name): for option in config.options(name):
if "Portal" == option: if "Portal" == option:
for value in config.get(name, option).split("\n"): for value in config.get(name, option).split("\n"):
items = re.findall("\S+", value) items = re.findall(r"\S+", value)
portal = {'host': items[1].rsplit(":", 1)[0]} portal = {'host': items[1].rsplit(":", 1)[0]}
if "@" in items[1]: if "@" in items[1]:
portal['port'] =\ portal['port'] =\
@ -537,7 +537,7 @@ def get_iscsi_portal_group_json(config, name):
portal_group_json.append({ portal_group_json.append({
"params": { "params": {
"portals": portals, "portals": portals,
"tag": int(re.findall('\d+', name)[0]) "tag": int(re.findall(r'\d+', name)[0])
}, },
"method": "add_portal_group" "method": "add_portal_group"
}) })
@ -557,7 +557,7 @@ def get_iscsi_initiator_group_json(config, name):
initiator_group_json = { initiator_group_json = {
"params": { "params": {
"initiators": initiators, "initiators": initiators,
"tag": int(re.findall('\d+', name)[0]), "tag": int(re.findall(r'\d+', name)[0]),
"netmasks": netmasks "netmasks": netmasks
}, },
"method": "add_initiator_group" "method": "add_initiator_group"
@ -586,13 +586,13 @@ def get_iscsi_target_node_json(config, section):
if "TargetAlias" == option: if "TargetAlias" == option:
alias_name = value.replace("\"", "") alias_name = value.replace("\"", "")
if "Mapping" == option: if "Mapping" == option:
items = re.findall("\S+", value) items = re.findall(r"\S+", value)
pg_ig_maps.append({ pg_ig_maps.append({
"ig_tag": int(re.findall('\d+', items[1])[0]), "ig_tag": int(re.findall(r'\d+', items[1])[0]),
"pg_tag": int(re.findall('\d+', items[0])[0]) "pg_tag": int(re.findall(r'\d+', items[0])[0])
}) })
if "AuthMethod" == option: if "AuthMethod" == option:
items = re.findall("\S+", value) items = re.findall(r"\S+", value)
for item in items: for item in items:
if "CHAP" == item: if "CHAP" == item:
require_chap = True require_chap = True
@ -607,10 +607,10 @@ def get_iscsi_target_node_json(config, section):
require_chap = False require_chap = False
mutual_chap = False mutual_chap = False
if "AuthGroup" == option: # AuthGroup1 if "AuthGroup" == option: # AuthGroup1
items = re.findall("\S+", value) items = re.findall(r"\S+", value)
chap_group = int(re.findall('\d+', items[0])[0]) chap_group = int(re.findall(r'\d+', items[0])[0])
if "UseDigest" == option: if "UseDigest" == option:
items = re.findall("\S+", value) items = re.findall(r"\S+", value)
for item in items: for item in items:
if "Header" == item: if "Header" == item:
header_digest = True header_digest = True
@ -620,7 +620,7 @@ def get_iscsi_target_node_json(config, section):
header_digest = False header_digest = False
data_digest = False data_digest = False
if re.match("LUN\d+", option): if re.match(r"LUN\d+", option):
luns.append({"lun_id": len(luns), luns.append({"lun_id": len(luns),
"bdev_name": value}) "bdev_name": value})
if "QueueDepth" == option: if "QueueDepth" == option:
@ -663,10 +663,10 @@ if __name__ == "__main__":
config.add_section(section) config.add_section(section)
for section in config.sections(): for section in config.sections():
match = re.match("(Bdev|Nvme|Malloc|VirtioUser\d+|Split|Pmem|AIO|" match = re.match(r'(Bdev|Nvme|Malloc|VirtioUser\d+|Split|Pmem|AIO|'
"iSCSI|PortalGroup\d+|InitiatorGroup\d+|" r'iSCSI|PortalGroup\d+|InitiatorGroup\d+|'
"TargetNode\d+|Nvmf|Subsystem\d+|VhostScsi\d+|" r'TargetNode\d+|Nvmf|Subsystem\d+|VhostScsi\d+|'
"VhostBlk\d+|VhostNvme\d+)", section) r'VhostBlk\d+|VhostNvme\d+)', section)
if match: if match:
match_section = ''.join(letter for letter in match.group(0) match_section = ''.join(letter for letter in match.group(0)
if not letter.isdigit()) if not letter.isdigit())

View File

@ -4,8 +4,8 @@ import os
import re import re
import sys import sys
comment = re.compile('^\s*#') comment = re.compile(r'^\s*#')
assign = re.compile('^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)') assign = re.compile(r'^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)')
args = os.environ.copy() args = os.environ.copy()
for arg in sys.argv: for arg in sys.argv:

View File

@ -12,14 +12,14 @@ from pyparsing import (alphanums, Optional, Suppress, Word, Regex,
def add_quotes_to_shell(spdk_shell): def add_quotes_to_shell(spdk_shell):
command = shell.locatedExpr(Word(alphanums + '_'))('command') command = shell.locatedExpr(Word(alphanums + '_'))('command')
value = dblQuotedString.addParseAction(removeQuotes) value = dblQuotedString.addParseAction(removeQuotes)
value_word = Word(alphanums + ';,=_\+/.<>()~@:-%[]') value_word = Word(alphanums + r';,=_\+/.<>()~@:-%[]')
keyword = Word(alphanums + '_\-') keyword = Word(alphanums + r'_\-')
kparam = shell.locatedExpr(keyword + Suppress('=') + kparam = shell.locatedExpr(keyword + Suppress('=') +
Optional(value | value_word, default=''))('kparams*') Optional(value | value_word, default=''))('kparams*')
pparam = shell.locatedExpr(value | value_word)('pparams*') pparam = shell.locatedExpr(value | value_word)('pparams*')
parameters = OneOrMore(kparam | pparam) parameters = OneOrMore(kparam | pparam)
bookmark = Regex('@([A-Za-z0-9:_.]|-)+') bookmark = Regex(r'@([A-Za-z0-9:_.]|-)+')
pathstd = Regex('([A-Za-z0-9:_.\[\]]|-)*' + '/' + '([A-Za-z0-9:_.\[\]/]|-)*') \ pathstd = Regex(r'([A-Za-z0-9:_.\[\]]|-)*' + '/' + r'([A-Za-z0-9:_.\[\]/]|-)*') \
| '..' | '.' | '..' | '.'
path = shell.locatedExpr(bookmark | pathstd | '*')('path') path = shell.locatedExpr(bookmark | pathstd | '*')('path')
spdk_shell._parser = Optional(path) + Optional(command) + Optional(parameters) spdk_shell._parser = Optional(path) + Optional(command) + Optional(parameters)

View File

@ -407,7 +407,7 @@ def verify_get_interfaces(rpc_py):
nics_names = set(x["name"] for x in nics) nics_names = set(x["name"] for x in nics)
# parse ip link show to verify the get_interfaces result # parse ip link show to verify the get_interfaces result
ip_show = ns_cmd + " ip link show" ip_show = ns_cmd + " ip link show"
ifcfg_nics = set(re.findall("\S+:\s(\S+?)(?:@\S+){0,1}:\s<.*", check_output(ip_show.split()).decode())) ifcfg_nics = set(re.findall(r'\S+:\s(\S+?)(?:@\S+){0,1}:\s<.*', check_output(ip_show.split()).decode()))
verify(nics_names == ifcfg_nics, 1, "get_interfaces returned {}".format(nics)) verify(nics_names == ifcfg_nics, 1, "get_interfaces returned {}".format(nics))
print("verify_get_interfaces passed.") print("verify_get_interfaces passed.")
@ -461,7 +461,7 @@ def verify_add_nvme_bdev_rpc_methods(rpc_py):
rpc = spdk_rpc(rpc_py) rpc = spdk_rpc(rpc_py)
test_pass = 0 test_pass = 0
output = check_output(["lspci", "-mm", "-nn"]) output = check_output(["lspci", "-mm", "-nn"])
addrs = re.findall('^([0-9]{2}:[0-9]{2}.[0-9]) "Non-Volatile memory controller \[0108\]".*-p02', output.decode(), re.MULTILINE) addrs = re.findall(r'^([0-9]{2}:[0-9]{2}.[0-9]) "Non-Volatile memory controller \[0108\]".*-p02', output.decode(), re.MULTILINE)
for addr in addrs: for addr in addrs:
ctrlr_address = "-b Nvme{} -t pcie -a 0000:{}".format(addrs.index(addr), addr) ctrlr_address = "-b Nvme{} -t pcie -a 0000:{}".format(addrs.index(addr), addr)
rpc.construct_nvme_bdev(ctrlr_address) rpc.construct_nvme_bdev(ctrlr_address)