From 0c93fc733032ddcfd0339977b3a88d2c8243d1e8 Mon Sep 17 00:00:00 2001 From: James Bergsten Date: Fri, 8 Feb 2019 09:50:49 -0800 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/c/443955 Tested-by: SPDK CI Jenkins Reviewed-by: Pawel Wodkowski Reviewed-by: Karol Latecki Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- scripts/config_converter.py | 48 ++++++++++++------------- scripts/genconfig.py | 4 +-- scripts/spdkcli.py | 8 ++--- test/iscsi_tgt/rpc_config/rpc_config.py | 4 +-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/scripts/config_converter.py b/scripts/config_converter.py index 918921cc5..d337e44c0 100755 --- a/scripts/config_converter.py +++ b/scripts/config_converter.py @@ -166,7 +166,7 @@ def get_aio_bdev_json(config, section): if value is None: return aio_json for item in value: - items = re.findall("\S+", item) + items = re.findall(r"\S+", item) params = {} params['filename'] = items[0] params['name'] = items[1] @@ -215,12 +215,12 @@ def get_nvme_bdev_json(config, section): for option in config.options("Nvme"): value = config.get("Nvme", option) if "TransportID" == option: - entry = re.findall("\S+", value) + entry = re.findall(r"\S+", value) nvme_name = entry[-1] - trtype = re.findall("trtype:\S+", value) + trtype = re.findall(r"trtype:\S+", value) if trtype: trtype = trtype[0].replace("trtype:", "").replace("\"", "") - traddr = re.findall("traddr:\S+", value) + traddr = re.findall(r"traddr:\S+", value) if traddr: traddr = traddr[0].replace("traddr:", "").replace("\"", "") nvme_json.append({ @@ -251,7 +251,7 @@ def get_pmem_bdev_json(config, section): for option in config.options(section): if "Blk" == option: for value in config.get(section, option).split("\n"): - items = re.findall("\S+", value) + items = re.findall(r"\S+", value) pmem_json.append({ "params": { "name": items[1], @@ -272,7 +272,7 @@ def get_split_bdev_json(config, section): if value and not isinstance(value, list): value = [value] for split in value: - items = re.findall("\S+", split) + items = re.findall(r"\S+", split) split_size_mb = 0 base_bdev = items[0] split_count = int(items[1]) @@ -330,7 +330,7 @@ def get_nvmf_subsystem_json(config, section): set_param(params, option, value) continue if "Listen" == option: - items = re.findall("\S+", value) + items = re.findall(r"\S+", value) adrfam = "IPv4" if len(items[1].split(":")) > 2: adrfam = "IPv6" @@ -343,7 +343,7 @@ def get_nvmf_subsystem_json(config, section): }) if "Namespace" == option: for item in value.split("\n"): - items = re.findall("\S+", item) + items = re.findall(r"\S+", item) if len(items) == 2: nsid = items[1] else: @@ -404,7 +404,7 @@ def get_vhost_scsi_json(config, section): set_param(params, option, value) if "Target" == option: for item in value.split("\n"): - items = re.findall("\S+", item) + items = re.findall(r"\S+", item) targets.append({ "scsi_target_num": int(items[0]), "ctrlr": params[0][3], @@ -523,7 +523,7 @@ def get_iscsi_portal_group_json(config, name): for option in config.options(name): if "Portal" == option: 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]} if "@" in items[1]: portal['port'] =\ @@ -537,7 +537,7 @@ def get_iscsi_portal_group_json(config, name): portal_group_json.append({ "params": { "portals": portals, - "tag": int(re.findall('\d+', name)[0]) + "tag": int(re.findall(r'\d+', name)[0]) }, "method": "add_portal_group" }) @@ -557,7 +557,7 @@ def get_iscsi_initiator_group_json(config, name): initiator_group_json = { "params": { "initiators": initiators, - "tag": int(re.findall('\d+', name)[0]), + "tag": int(re.findall(r'\d+', name)[0]), "netmasks": netmasks }, "method": "add_initiator_group" @@ -586,13 +586,13 @@ def get_iscsi_target_node_json(config, section): if "TargetAlias" == option: alias_name = value.replace("\"", "") if "Mapping" == option: - items = re.findall("\S+", value) + items = re.findall(r"\S+", value) pg_ig_maps.append({ - "ig_tag": int(re.findall('\d+', items[1])[0]), - "pg_tag": int(re.findall('\d+', items[0])[0]) + "ig_tag": int(re.findall(r'\d+', items[1])[0]), + "pg_tag": int(re.findall(r'\d+', items[0])[0]) }) if "AuthMethod" == option: - items = re.findall("\S+", value) + items = re.findall(r"\S+", value) for item in items: if "CHAP" == item: require_chap = True @@ -607,10 +607,10 @@ def get_iscsi_target_node_json(config, section): require_chap = False mutual_chap = False if "AuthGroup" == option: # AuthGroup1 - items = re.findall("\S+", value) - chap_group = int(re.findall('\d+', items[0])[0]) + items = re.findall(r"\S+", value) + chap_group = int(re.findall(r'\d+', items[0])[0]) if "UseDigest" == option: - items = re.findall("\S+", value) + items = re.findall(r"\S+", value) for item in items: if "Header" == item: header_digest = True @@ -620,7 +620,7 @@ def get_iscsi_target_node_json(config, section): header_digest = False data_digest = False - if re.match("LUN\d+", option): + if re.match(r"LUN\d+", option): luns.append({"lun_id": len(luns), "bdev_name": value}) if "QueueDepth" == option: @@ -663,10 +663,10 @@ if __name__ == "__main__": config.add_section(section) for section in config.sections(): - match = re.match("(Bdev|Nvme|Malloc|VirtioUser\d+|Split|Pmem|AIO|" - "iSCSI|PortalGroup\d+|InitiatorGroup\d+|" - "TargetNode\d+|Nvmf|Subsystem\d+|VhostScsi\d+|" - "VhostBlk\d+|VhostNvme\d+)", section) + match = re.match(r'(Bdev|Nvme|Malloc|VirtioUser\d+|Split|Pmem|AIO|' + r'iSCSI|PortalGroup\d+|InitiatorGroup\d+|' + r'TargetNode\d+|Nvmf|Subsystem\d+|VhostScsi\d+|' + r'VhostBlk\d+|VhostNvme\d+)', section) if match: match_section = ''.join(letter for letter in match.group(0) if not letter.isdigit()) diff --git a/scripts/genconfig.py b/scripts/genconfig.py index 550f0e9bc..87781e0b7 100755 --- a/scripts/genconfig.py +++ b/scripts/genconfig.py @@ -4,8 +4,8 @@ import os import re import sys -comment = re.compile('^\s*#') -assign = re.compile('^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)') +comment = re.compile(r'^\s*#') +assign = re.compile(r'^\s*([a-zA-Z_]+)\s*(\?)?=\s*([^#]*)') args = os.environ.copy() for arg in sys.argv: diff --git a/scripts/spdkcli.py b/scripts/spdkcli.py index 82343a5cd..be2350a1a 100755 --- a/scripts/spdkcli.py +++ b/scripts/spdkcli.py @@ -12,14 +12,14 @@ from pyparsing import (alphanums, Optional, Suppress, Word, Regex, def add_quotes_to_shell(spdk_shell): command = shell.locatedExpr(Word(alphanums + '_'))('command') value = dblQuotedString.addParseAction(removeQuotes) - value_word = Word(alphanums + ';,=_\+/.<>()~@:-%[]') - keyword = Word(alphanums + '_\-') + value_word = Word(alphanums + r';,=_\+/.<>()~@:-%[]') + keyword = Word(alphanums + r'_\-') kparam = shell.locatedExpr(keyword + Suppress('=') + Optional(value | value_word, default=''))('kparams*') pparam = shell.locatedExpr(value | value_word)('pparams*') parameters = OneOrMore(kparam | pparam) - bookmark = Regex('@([A-Za-z0-9:_.]|-)+') - pathstd = Regex('([A-Za-z0-9:_.\[\]]|-)*' + '/' + '([A-Za-z0-9:_.\[\]/]|-)*') \ + bookmark = Regex(r'@([A-Za-z0-9:_.]|-)+') + pathstd = Regex(r'([A-Za-z0-9:_.\[\]]|-)*' + '/' + r'([A-Za-z0-9:_.\[\]/]|-)*') \ | '..' | '.' path = shell.locatedExpr(bookmark | pathstd | '*')('path') spdk_shell._parser = Optional(path) + Optional(command) + Optional(parameters) diff --git a/test/iscsi_tgt/rpc_config/rpc_config.py b/test/iscsi_tgt/rpc_config/rpc_config.py index bc7f7365e..c53d50ae9 100755 --- a/test/iscsi_tgt/rpc_config/rpc_config.py +++ b/test/iscsi_tgt/rpc_config/rpc_config.py @@ -407,7 +407,7 @@ def verify_get_interfaces(rpc_py): nics_names = set(x["name"] for x in nics) # parse ip link show to verify the get_interfaces result 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)) print("verify_get_interfaces passed.") @@ -461,7 +461,7 @@ def verify_add_nvme_bdev_rpc_methods(rpc_py): rpc = spdk_rpc(rpc_py) test_pass = 0 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: ctrlr_address = "-b Nvme{} -t pcie -a 0000:{}".format(addrs.index(addr), addr) rpc.construct_nvme_bdev(ctrlr_address)