From c6bb6c72ccfc52dbe85c19b3cd1d49a2c8490b45 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 21 Nov 2017 22:22:40 -0800 Subject: [PATCH] Fix anomalous backslashes and enable pylint test. --- lib/ansible/modules/network/cumulus/_cl_bond.py | 2 +- lib/ansible/modules/network/cumulus/_cl_bridge.py | 2 +- .../modules/network/cumulus/_cl_img_install.py | 10 +++++----- .../modules/network/cumulus/_cl_interface.py | 2 +- .../modules/network/dellos6/dellos6_facts.py | 12 ++++++------ .../modules/network/dellos9/dellos9_facts.py | 2 +- lib/ansible/modules/network/eos/eos_eapi.py | 2 +- lib/ansible/modules/network/eos/eos_system.py | 12 ++++++------ lib/ansible/modules/network/f5/bigip_selfip.py | 2 +- lib/ansible/modules/network/ios/ios_banner.py | 2 +- lib/ansible/modules/network/ios/ios_ping.py | 4 ++-- lib/ansible/modules/network/ios/ios_system.py | 12 ++++++------ lib/ansible/modules/network/iosxr/iosxr_system.py | 10 +++++----- .../modules/network/ironware/ironware_facts.py | 2 +- .../modules/network/nxos/nxos_aaa_server.py | 2 +- .../modules/network/nxos/nxos_aaa_server_host.py | 4 ++-- lib/ansible/modules/network/nxos/nxos_feature.py | 2 +- .../modules/network/nxos/nxos_igmp_interface.py | 10 +++++----- .../modules/network/nxos/nxos_ip_interface.py | 10 +++++----- lib/ansible/modules/network/nxos/nxos_ntp.py | 6 +++--- lib/ansible/modules/network/nxos/nxos_ntp_auth.py | 4 ++-- .../modules/network/nxos/nxos_ntp_options.py | 2 +- lib/ansible/modules/network/nxos/nxos_ospf.py | 2 +- lib/ansible/modules/network/nxos/nxos_snapshot.py | 6 +++--- lib/ansible/modules/network/nxos/nxos_system.py | 14 +++++++------- .../modules/network/nxos/nxos_vrf_interface.py | 2 +- .../modules/network/nxos/nxos_vtp_domain.py | 4 ++-- .../modules/network/nxos/nxos_vtp_password.py | 4 ++-- .../modules/network/nxos/nxos_vtp_version.py | 4 ++-- test/sanity/pylint/config/default | 1 - 30 files changed, 76 insertions(+), 77 deletions(-) diff --git a/lib/ansible/modules/network/cumulus/_cl_bond.py b/lib/ansible/modules/network/cumulus/_cl_bond.py index 6c9d9c8cda9..f9050f47a5d 100644 --- a/lib/ansible/modules/network/cumulus/_cl_bond.py +++ b/lib/ansible/modules/network/cumulus/_cl_bond.py @@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'community'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: cl_bond version_added: "2.1" diff --git a/lib/ansible/modules/network/cumulus/_cl_bridge.py b/lib/ansible/modules/network/cumulus/_cl_bridge.py index 15396c36970..5c9af56b2e5 100644 --- a/lib/ansible/modules/network/cumulus/_cl_bridge.py +++ b/lib/ansible/modules/network/cumulus/_cl_bridge.py @@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'community'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: cl_bridge version_added: "2.1" diff --git a/lib/ansible/modules/network/cumulus/_cl_img_install.py b/lib/ansible/modules/network/cumulus/_cl_img_install.py index 23ede495281..25072c90d2e 100644 --- a/lib/ansible/modules/network/cumulus/_cl_img_install.py +++ b/lib/ansible/modules/network/cumulus/_cl_img_install.py @@ -181,7 +181,7 @@ def check_fw_print_env(module, slot_num): cmd = "/usr/bin/grub-editenv list" grub_output = run_cl_cmd(module, cmd) for _line in grub_output: - _regex_str = re.compile('cl.ver' + slot_num + '=([\w.]+)-') + _regex_str = re.compile('cl.ver' + slot_num + r'=([\w.]+)-') m0 = re.match(_regex_str, _line) if m0: return m0.group(1) @@ -197,7 +197,7 @@ def get_primary_slot_num(module): cmd = "/usr/bin/grub-editenv list" grub_output = run_cl_cmd(module, cmd) for _line in grub_output: - _regex_str = re.compile('cl.active=(\d)') + _regex_str = re.compile(r'cl.active=(\d)') m0 = re.match(_regex_str, _line) if m0: return m0.group(1) @@ -210,7 +210,7 @@ def get_active_slot(module): module.fail_json(msg='Failed to open /proc/cmdline. ' + 'Unable to determine active slot') - _match = re.search('active=(\d+)', cmdline) + _match = re.search(r'active=(\d+)', cmdline) if _match: return _match.group(1) return None @@ -247,9 +247,9 @@ def determine_sw_version(module): return else: _filename = module.params.get('src').split('/')[-1] - _match = re.search('\d+\W\d+\W\w+', _filename) + _match = re.search(r'\d+\W\d+\W\w+', _filename) if _match: - module.sw_version = re.sub('\W', '.', _match.group()) + module.sw_version = re.sub(r'\W', '.', _match.group()) return _msg = 'Unable to determine version from file %s' % (_filename) module.exit_json(changed=False, msg=_msg) diff --git a/lib/ansible/modules/network/cumulus/_cl_interface.py b/lib/ansible/modules/network/cumulus/_cl_interface.py index a90412ed128..e6499685c41 100644 --- a/lib/ansible/modules/network/cumulus/_cl_interface.py +++ b/lib/ansible/modules/network/cumulus/_cl_interface.py @@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', 'supported_by': 'community'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: cl_interface version_added: "2.1" diff --git a/lib/ansible/modules/network/dellos6/dellos6_facts.py b/lib/ansible/modules/network/dellos6/dellos6_facts.py index b4ea8f21ef1..94d29891ffb 100644 --- a/lib/ansible/modules/network/dellos6/dellos6_facts.py +++ b/lib/ansible/modules/network/dellos6/dellos6_facts.py @@ -185,7 +185,7 @@ class Hardware(FactsBase): def populate(self): super(Hardware, self).populate() data = self.responses[0] - match = re.findall('\s(\d+)\s', data) + match = re.findall(r'\s(\d+)\s', data) if match: self.facts['memtotal_mb'] = int(match[0]) // 1024 self.facts['memfree_mb'] = int(match[1]) // 1024 @@ -231,12 +231,12 @@ class Interfaces(FactsBase): for en in vlan_info_next.splitlines(): if en == '': continue - match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en) + match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en) intf = match.group(1) if intf not in facts: facts[intf] = list() fact = dict() - matc = re.search('^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en) + matc = re.search(r'^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en) fact['address'] = matc.group(2) fact['masklen'] = matc.group(3) facts[intf].append(fact) @@ -299,7 +299,7 @@ class Interfaces(FactsBase): desc_val, desc_info = desc_next.split('Port') for en in desc_val.splitlines(): if key in en: - match = re.search('^(\S+)\s+(\S+)', en) + match = re.search(r'^(\S+)\s+(\S+)', en) if match.group(2) in ['Full', 'N/A']: return "Null" else: @@ -331,7 +331,7 @@ class Interfaces(FactsBase): for en in mediatype_next.splitlines(): if key in en: flag = 0 - match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en) + match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en) if match: strval = match.group(3) return strval @@ -344,7 +344,7 @@ class Interfaces(FactsBase): for en in type_val_next.splitlines(): if key in en: flag = 0 - match = re.search('^(\S+)\s+(\S+)\s+(\S+)', en) + match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en) if match: strval = match.group(2) return strval diff --git a/lib/ansible/modules/network/dellos9/dellos9_facts.py b/lib/ansible/modules/network/dellos9/dellos9_facts.py index d6376d9edde..004ffc1d7f5 100644 --- a/lib/ansible/modules/network/dellos9/dellos9_facts.py +++ b/lib/ansible/modules/network/dellos9/dellos9_facts.py @@ -215,7 +215,7 @@ class Hardware(FactsBase): self.facts['filesystems'] = self.parse_filesystems(data) data = self.responses[1] - match = re.findall('\s(\d+)\s', data) + match = re.findall(r'\s(\d+)\s', data) if match: self.facts['memtotal_mb'] = int(match[0]) // 1024 self.facts['memfree_mb'] = int(match[2]) // 1024 diff --git a/lib/ansible/modules/network/eos/eos_eapi.py b/lib/ansible/modules/network/eos/eos_eapi.py index 541b104a87d..b0db9387fb3 100644 --- a/lib/ansible/modules/network/eos/eos_eapi.py +++ b/lib/ansible/modules/network/eos/eos_eapi.py @@ -208,7 +208,7 @@ def validate_local_http_port(value, module): def validate_vrf(value, module): out = run_commands(module, ['show vrf']) - configured_vrfs = re.findall('^\s+(\w+)(?=\s)', out[0], re.M) + configured_vrfs = re.findall(r'^\s+(\w+)(?=\s)', out[0], re.M) configured_vrfs.append('default') if value not in configured_vrfs: module.fail_json(msg='vrf `%s` is not configured on the system' % value) diff --git a/lib/ansible/modules/network/eos/eos_system.py b/lib/ansible/modules/network/eos/eos_system.py index 669b0b6cc34..3ae8d8627cb 100644 --- a/lib/ansible/modules/network/eos/eos_system.py +++ b/lib/ansible/modules/network/eos/eos_system.py @@ -140,7 +140,7 @@ def has_vrf(module, vrf): if _CONFIGURED_VRFS is not None: return vrf in _CONFIGURED_VRFS config = get_config(module) - _CONFIGURED_VRFS = re.findall('vrf definition (\S+)', config) + _CONFIGURED_VRFS = re.findall(r'vrf definition (\S+)', config) _CONFIGURED_VRFS.append('default') return vrf in _CONFIGURED_VRFS @@ -223,18 +223,18 @@ def map_obj_to_commands(want, have, module): return commands def parse_hostname(config): - match = re.search('^hostname (\S+)', config, re.M) + match = re.search(r'^hostname (\S+)', config, re.M) if match: return match.group(1) def parse_domain_name(config): - match = re.search('^ip domain-name (\S+)', config, re.M) + match = re.search(r'^ip domain-name (\S+)', config, re.M) if match: return match.group(1) def parse_lookup_source(config): objects = list() - regex = 'ip domain lookup (?:vrf (\S+) )*source-interface (\S+)' + regex = r'ip domain lookup (?:vrf (\S+) )*source-interface (\S+)' for vrf, intf in re.findall(regex, config, re.M): if len(vrf) == 0: vrf= None @@ -243,7 +243,7 @@ def parse_lookup_source(config): def parse_name_servers(config): objects = list() - for vrf, addr in re.findall('ip name-server vrf (\S+) (\S+)', config, re.M): + for vrf, addr in re.findall(r'ip name-server vrf (\S+) (\S+)', config, re.M): objects.append({'server': addr, 'vrf': vrf}) return objects @@ -252,7 +252,7 @@ def map_config_to_obj(module): return { 'hostname': parse_hostname(config), 'domain_name': parse_domain_name(config), - 'domain_list': re.findall('^ip domain-list (\S+)', config, re.M), + 'domain_list': re.findall(r'^ip domain-list (\S+)', config, re.M), 'lookup_source': parse_lookup_source(config), 'name_servers': parse_name_servers(config) } diff --git a/lib/ansible/modules/network/f5/bigip_selfip.py b/lib/ansible/modules/network/f5/bigip_selfip.py index c6eca4b95c5..de861b37959 100644 --- a/lib/ansible/modules/network/f5/bigip_selfip.py +++ b/lib/ansible/modules/network/f5/bigip_selfip.py @@ -451,7 +451,7 @@ class ApiParameters(Parameters): @address.setter def address(self, value): - pattern = '^(?P[0-9A-Fa-f:.]+)%?(?P\d+)?\/(?P\d+)$' + pattern = r'^(?P[0-9A-Fa-f:.]+)%?(?P\d+)?\/(?P\d+)$' matches = re.match(pattern, value) if not matches: raise F5ModuleError( diff --git a/lib/ansible/modules/network/ios/ios_banner.py b/lib/ansible/modules/network/ios/ios_banner.py index 0787c2a7b6c..a81e55dcf0c 100644 --- a/lib/ansible/modules/network/ios/ios_banner.py +++ b/lib/ansible/modules/network/ios/ios_banner.py @@ -123,7 +123,7 @@ def map_config_to_obj(module): 'show running-config | begin banner %s' % module.params['banner']) if out: - output = re.search('\^C(.*)\^C', out, re.S).group(1).strip() + output = re.search(r'\^C(.*)\^C', out, re.S).group(1).strip() else: output = None obj = {'banner': module.params['banner'], 'state': 'absent'} diff --git a/lib/ansible/modules/network/ios/ios_ping.py b/lib/ansible/modules/network/ios/ios_ping.py index a61d78c6ae7..e4713395064 100644 --- a/lib/ansible/modules/network/ios/ios_ping.py +++ b/lib/ansible/modules/network/ios/ios_ping.py @@ -188,8 +188,8 @@ def parse_ping(ping_stats): Example: "Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/8 ms" Returns the percent of packet loss, recieved packets, transmitted packets, and RTT dict. """ - rate_re = re.compile("^\w+\s+\w+\s+\w+\s+(?P\d+)\s+\w+\s+\((?P\d+)\/(?P\d+)\)") - rtt_re = re.compile(".*,\s+\S+\s+\S+\s+=\s+(?P\d+)\/(?P\d+)\/(?P\d+)\s+\w+\s*$|.*\s*$") + rate_re = re.compile(r"^\w+\s+\w+\s+\w+\s+(?P\d+)\s+\w+\s+\((?P\d+)/(?P\d+)\)") + rtt_re = re.compile(r".*,\s+\S+\s+\S+\s+=\s+(?P\d+)/(?P\d+)/(?P\d+)\s+\w+\s*$|.*\s*$") rate = rate_re.match(ping_stats) rtt = rtt_re.match(ping_stats) diff --git a/lib/ansible/modules/network/ios/ios_system.py b/lib/ansible/modules/network/ios/ios_system.py index af7c801a333..260cf3b37a5 100644 --- a/lib/ansible/modules/network/ios/ios_system.py +++ b/lib/ansible/modules/network/ios/ios_system.py @@ -130,7 +130,7 @@ def has_vrf(module, vrf): if _CONFIGURED_VRFS is not None: return vrf in _CONFIGURED_VRFS config = get_config(module) - _CONFIGURED_VRFS = re.findall('vrf definition (\S+)', config) + _CONFIGURED_VRFS = re.findall(r'vrf definition (\S+)', config) return vrf in _CONFIGURED_VRFS def requires_vrf(module, vrf): @@ -244,11 +244,11 @@ def map_obj_to_commands(want, have, module): return commands def parse_hostname(config): - match = re.search('^hostname (\S+)', config, re.M) + match = re.search(r'^hostname (\S+)', config, re.M) return match.group(1) def parse_domain_name(config): - match = re.findall('^ip domain name (?:vrf (\S+) )*(\S+)', config, re.M) + match = re.findall(r'^ip domain name (?:vrf (\S+) )*(\S+)', config, re.M) matches = list() for vrf, name in match: if not vrf: @@ -257,7 +257,7 @@ def parse_domain_name(config): return matches def parse_domain_search(config): - match = re.findall('^ip domain list (?:vrf (\S+) )*(\S+)', config, re.M) + match = re.findall(r'^ip domain list (?:vrf (\S+) )*(\S+)', config, re.M) matches = list() for vrf, name in match: if not vrf: @@ -266,7 +266,7 @@ def parse_domain_search(config): return matches def parse_name_servers(config): - match = re.findall('^ip name-server (?:vrf (\S+) )*(.*)', config, re.M) + match = re.findall(r'^ip name-server (?:vrf (\S+) )*(.*)', config, re.M) matches = list() for vrf, servers in match: if not vrf: @@ -276,7 +276,7 @@ def parse_name_servers(config): return matches def parse_lookup_source(config): - match = re.search('ip domain lookup source-interface (\S+)', config, re.M) + match = re.search(r'ip domain lookup source-interface (\S+)', config, re.M) if match: return match.group(1) diff --git a/lib/ansible/modules/network/iosxr/iosxr_system.py b/lib/ansible/modules/network/iosxr/iosxr_system.py index ada79c664f3..32b981134f1 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_system.py +++ b/lib/ansible/modules/network/iosxr/iosxr_system.py @@ -168,16 +168,16 @@ def map_obj_to_commands(want, have, module): return commands def parse_hostname(config): - match = re.search('^hostname (\S+)', config, re.M) + match = re.search(r'^hostname (\S+)', config, re.M) return match.group(1) def parse_domain_name(config): - match = re.search('^domain name (\S+)', config, re.M) + match = re.search(r'^domain name (\S+)', config, re.M) if match: return match.group(1) def parse_lookup_source(config): - match = re.search('^domain lookup source-interface (\S+)', config, re.M) + match = re.search(r'^domain lookup source-interface (\S+)', config, re.M) if match: return match.group(1) @@ -186,10 +186,10 @@ def map_config_to_obj(module): return { 'hostname': parse_hostname(config), 'domain_name': parse_domain_name(config), - 'domain_search': re.findall('^domain list (\S+)', config, re.M), + 'domain_search': re.findall(r'^domain list (\S+)', config, re.M), 'lookup_source': parse_lookup_source(config), 'lookup_enabled': 'domain lookup disable' not in config, - 'name_servers': re.findall('^domain name-server (\S+)', config, re.M) + 'name_servers': re.findall(r'^domain name-server (\S+)', config, re.M) } def map_params_to_obj(module): diff --git a/lib/ansible/modules/network/ironware/ironware_facts.py b/lib/ansible/modules/network/ironware/ironware_facts.py index e23e0ccbacd..b05dbb85b32 100644 --- a/lib/ansible/modules/network/ironware/ironware_facts.py +++ b/lib/ansible/modules/network/ironware/ironware_facts.py @@ -418,7 +418,7 @@ class MPLS(FactsBase): path['up'] = True if match.group(1) == 'UP' else False path['name'] = None if path['up']: - match = re.search('bypass_lsp: (\S)', data, re.M) + match = re.search(r'bypass_lsp: (\S)', data, re.M) path['name'] = match.group(1) if match else None return path diff --git a/lib/ansible/modules/network/nxos/nxos_aaa_server.py b/lib/ansible/modules/network/nxos/nxos_aaa_server.py index a0f03ac5eee..4213a26da18 100644 --- a/lib/ansible/modules/network/nxos/nxos_aaa_server.py +++ b/lib/ansible/modules/network/nxos/nxos_aaa_server.py @@ -151,7 +151,7 @@ def get_aaa_server_info(server_type, module): server_command = 'show {0}-server'.format(server_type) request_command = 'show {0}-server directed-request'.format(server_type) global_key_command = 'show run | sec {0}'.format(server_type) - aaa_regex = '.*{0}-server\skey\s\d\s+(?P\S+).*'.format(server_type) + aaa_regex = r'.*{0}-server\skey\s\d\s+(?P\S+).*'.format(server_type) server_body = execute_show_command( server_command, module, command_type='cli_show_ascii')[0] diff --git a/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py b/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py index eb5ab6b2afd..e2e33079c99 100644 --- a/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py +++ b/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py @@ -211,8 +211,8 @@ def get_aaa_host_info(module, server_type, address): if body[0]: try: - pattern = ('(acct-port \d+)|(timeout \d+)|(auth-port \d+)|' - '(key 7 "\w+")|( port \d+)') + pattern = (r'(acct-port \d+)|(timeout \d+)|(auth-port \d+)|' + r'(key 7 "\w+")|( port \d+)') raw_match = re.findall(pattern, body[0]) aaa_host_info = _match_dict(raw_match, {'acct-port': 'acct_port', 'auth-port': 'auth_port', diff --git a/lib/ansible/modules/network/nxos/nxos_feature.py b/lib/ansible/modules/network/nxos/nxos_feature.py index 5815e7d0784..c513cb7987e 100644 --- a/lib/ansible/modules/network/nxos/nxos_feature.py +++ b/lib/ansible/modules/network/nxos/nxos_feature.py @@ -87,7 +87,7 @@ def check_args(module, warnings): def get_available_features(feature, module): available_features = {} - feature_regex = '(?P\S+)\s+\d+\s+(?P.*)' + feature_regex = r'(?P\S+)\s+\d+\s+(?P.*)' command = {'command': 'show feature', 'output': 'text'} try: diff --git a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py index 09f64fc9dce..3d626e93e01 100644 --- a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py @@ -358,11 +358,11 @@ def get_igmp_interface(module, interface): staticoif = [] if body: split_body = body.split('\n') - route_map_regex = ('.*ip igmp static-oif route-map\s+' - '(?P\S+).*') - prefix_source_regex = ('.*ip igmp static-oif\s+(?P' - '((\d+.){3}\d+))(\ssource\s' - '(?P\S+))?.*') + route_map_regex = (r'.*ip igmp static-oif route-map\s+' + r'(?P\S+).*') + prefix_source_regex = (r'.*ip igmp static-oif\s+(?P' + r'((\d+.){3}\d+))(\ssource\s' + r'(?P\S+))?.*') for line in split_body: temp = {} diff --git a/lib/ansible/modules/network/nxos/nxos_ip_interface.py b/lib/ansible/modules/network/nxos/nxos_ip_interface.py index d187540fee8..e5c721d8b2f 100644 --- a/lib/ansible/modules/network/nxos/nxos_ip_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_ip_interface.py @@ -306,9 +306,9 @@ def parse_unstructured_data(body, interface_name, version, module): else: for index in range(0, len(splitted_body) - 1): if "IP address" in splitted_body[index]: - regex = '.*IP\saddress:\s(?P\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \ - '\s\d{1,3}(?:\.\d{1,3}){3}\/(?P\d+)(?:\s(?Psecondary)\s)?' + \ - '(.+?tag:\s(?P\d+).*)?' + regex = r'.*IP\saddress:\s(?P\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \ + r'\s\d{1,3}(?:\.\d{1,3}){3}\/(?P\d+)(?:\s(?Psecondary)\s)?' + \ + r'(.+?tag:\s(?P\d+).*)?' match = re.match(regex, splitted_body[index]) if match: match_dict = match.groupdict() @@ -325,7 +325,7 @@ def parse_unstructured_data(body, interface_name, version, module): interface['prefixes'].append(prefix) try: - vrf_regex = '.+?VRF\s+(?P\S+?)\s' + vrf_regex = r'.+?VRF\s+(?P\S+?)\s' match_vrf = re.match(vrf_regex, body, re.DOTALL) vrf = match_vrf.groupdict()['vrf'] except AttributeError: @@ -344,7 +344,7 @@ def parse_interface_data(body): for index in range(0, len(splitted_body) - 1): if "Encapsulation 802.1Q" in splitted_body[index]: - regex = '(.+?ID\s(?P\d+).*)?' + regex = r'(.+?ID\s(?P\d+).*)?' match = re.match(regex, splitted_body[index]) if match: match_dict = match.groupdict() diff --git a/lib/ansible/modules/network/nxos/nxos_ntp.py b/lib/ansible/modules/network/nxos/nxos_ntp.py index 4b000a5ca55..248e0ba3e06 100644 --- a/lib/ansible/modules/network/nxos/nxos_ntp.py +++ b/lib/ansible/modules/network/nxos/nxos_ntp.py @@ -179,9 +179,9 @@ def get_ntp_peer(module): ntp = response if ntp: ntp_regex = ( - ".*ntp\s(server\s(?P
\S+)|peer\s(?P\S+))" - "\s*((?Pprefer)\s*)?(use-vrf\s(?P\S+)\s*)?" - "(key\s(?P\d+))?.*" + r".*ntp\s(server\s(?P
\S+)|peer\s(?P\S+))" + r"\s*((?Pprefer)\s*)?(use-vrf\s(?P\S+)\s*)?" + r"(key\s(?P\d+))?.*" ) split_ntp = ntp.splitlines() diff --git a/lib/ansible/modules/network/nxos/nxos_ntp_auth.py b/lib/ansible/modules/network/nxos/nxos_ntp_auth.py index a79a5866c69..b8157d8e3a0 100644 --- a/lib/ansible/modules/network/nxos/nxos_ntp_auth.py +++ b/lib/ansible/modules/network/nxos/nxos_ntp_auth.py @@ -161,8 +161,8 @@ def get_ntp_trusted_key(module): def get_ntp_auth_key(key_id, module): authentication_key = {} command = 'show run | inc ntp.authentication-key.{0}'.format(key_id) - auth_regex = (".*ntp\sauthentication-key\s(?P\d+)\s" - "md5\s(?P\S+).*") + auth_regex = (r".*ntp\sauthentication-key\s(?P\d+)\s" + r"md5\s(?P\S+).*") body = execute_show_command(command, module)[0] diff --git a/lib/ansible/modules/network/nxos/nxos_ntp_options.py b/lib/ansible/modules/network/nxos/nxos_ntp_options.py index 9befe3ccd8b..2bd56fe6dfe 100644 --- a/lib/ansible/modules/network/nxos/nxos_ntp_options.py +++ b/lib/ansible/modules/network/nxos/nxos_ntp_options.py @@ -97,7 +97,7 @@ def get_current(module): output = run_commands(module, ({'command': cmd[0], 'output': 'text'}, {'command': cmd[1], 'output': 'text'})) - match = re.search("^ntp master(?: (\d+))", output[0], re.M) + match = re.search(r"^ntp master(?: (\d+))", output[0], re.M) if match: master = True stratum = match.group(1) diff --git a/lib/ansible/modules/network/nxos/nxos_ospf.py b/lib/ansible/modules/network/nxos/nxos_ospf.py index 8e3a4610790..f709da0f878 100644 --- a/lib/ansible/modules/network/nxos/nxos_ospf.py +++ b/lib/ansible/modules/network/nxos/nxos_ospf.py @@ -72,7 +72,7 @@ PARAM_TO_COMMAND_KEYMAP = { def get_value(config, module): splitted_config = config.splitlines() value_list = [] - REGEX = '^router ospf\s(?P\S+).*' + REGEX = r'^router ospf\s(?P\S+).*' for line in splitted_config: value = '' if 'router ospf' in line: diff --git a/lib/ansible/modules/network/nxos/nxos_snapshot.py b/lib/ansible/modules/network/nxos/nxos_snapshot.py index d486b115516..7f79e8647b8 100644 --- a/lib/ansible/modules/network/nxos/nxos_snapshot.py +++ b/lib/ansible/modules/network/nxos/nxos_snapshot.py @@ -191,8 +191,8 @@ def get_existing(module): body = execute_show_command(command, module)[0] if body: split_body = body.splitlines() - snapshot_regex = ('(?P\S+)\s+(?P\w+\s+\w+\s+\d+\s+\d+' - ':\d+:\d+\s+\d+)\s+(?P.*)') + snapshot_regex = (r'(?P\S+)\s+(?P\w+\s+\w+\s+\d+\s+\d+' + r':\d+:\d+\s+\d+)\s+(?P.*)') for snapshot in split_body: temp = {} try: @@ -229,7 +229,7 @@ def action_add(module, existing_snapshots): body = execute_show_command(command, module)[0] if body: - section_regex = '.*\[(?P
\S+)\].*' + section_regex = r'.*\[(?P
\S+)\].*' split_body = body.split('\n\n') for section in split_body: temp = {} diff --git a/lib/ansible/modules/network/nxos/nxos_system.py b/lib/ansible/modules/network/nxos/nxos_system.py index da51e2bd422..1e220983520 100644 --- a/lib/ansible/modules/network/nxos/nxos_system.py +++ b/lib/ansible/modules/network/nxos/nxos_system.py @@ -125,7 +125,7 @@ def has_vrf(module, vrf): if _CONFIGURED_VRFS is not None: return vrf in _CONFIGURED_VRFS config = get_config(module) - _CONFIGURED_VRFS = re.findall('vrf context (\S+)', config) + _CONFIGURED_VRFS = re.findall(r'vrf context (\S+)', config) return vrf in _CONFIGURED_VRFS def map_obj_to_commands(want, have, module): @@ -207,13 +207,13 @@ def map_obj_to_commands(want, have, module): return commands def parse_hostname(config): - match = re.search('^hostname (\S+)', config, re.M) + match = re.search(r'^hostname (\S+)', config, re.M) if match: return match.group(1) def parse_domain_name(config, vrf_config): objects = list() - regex = re.compile('ip domain-name (\S+)') + regex = re.compile(r'ip domain-name (\S+)') match = regex.search(config, re.M) if match: @@ -229,11 +229,11 @@ def parse_domain_name(config, vrf_config): def parse_domain_search(config, vrf_config): objects = list() - for item in re.findall('^ip domain-list (\S+)', config, re.M): + for item in re.findall(r'^ip domain-list (\S+)', config, re.M): objects.append({'name': item, 'vrf': None}) for vrf, cfg in iteritems(vrf_config): - for item in re.findall('ip domain-list (\S+)', cfg, re.M): + for item in re.findall(r'ip domain-list (\S+)', cfg, re.M): objects.append({'name': item, 'vrf': vrf}) return objects @@ -257,7 +257,7 @@ def parse_name_servers(config, vrf_config, vrfs): return objects def parse_system_mtu(config): - match = re.search('^system jumbomtu (\d+)', config, re.M) + match = re.search(r'^system jumbomtu (\d+)', config, re.M) if match: return int(match.group(1)) @@ -267,7 +267,7 @@ def map_config_to_obj(module): vrf_config = {} - vrfs = re.findall('^vrf context (\S+)$', config, re.M) + vrfs = re.findall(r'^vrf context (\S+)$', config, re.M) for vrf in vrfs: config_data = configobj.get_block_config(path=['vrf context %s' % vrf]) vrf_config[vrf] = config_data diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index 33ca1df77da..ac61b71997f 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -151,7 +151,7 @@ def get_interface_info(interface, module): interface = interface.capitalize() command = 'show run | section interface.{0}'.format(interface) - vrf_regex = ".*vrf\s+member\s+(?P\S+).*" + vrf_regex = r".*vrf\s+member\s+(?P\S+).*" try: body = execute_show_command(command, module) diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_domain.py b/lib/ansible/modules/network/nxos/nxos_vtp_domain.py index e6e1352e166..97d6720718f 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_domain.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_domain.py @@ -123,8 +123,8 @@ def get_vtp_config(module): vtp_parsed = {} if body: - version_regex = '.*VTP version running\s+:\s+(?P\d).*' - domain_regex = '.*VTP Domain Name\s+:\s+(?P\S+).*' + version_regex = r'.*VTP version running\s+:\s+(?P\d).*' + domain_regex = r'.*VTP Domain Name\s+:\s+(?P\S+).*' try: match_version = re.match(version_regex, body, re.DOTALL) diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_password.py b/lib/ansible/modules/network/nxos/nxos_vtp_password.py index e21ed47c4c0..d5e8ba099fc 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_password.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_password.py @@ -154,8 +154,8 @@ def get_vtp_config(module): vtp_parsed = {} if body: - version_regex = '.*VTP version running\s+:\s+(?P\d).*' - domain_regex = '.*VTP Domain Name\s+:\s+(?P\S+).*' + version_regex = r'.*VTP version running\s+:\s+(?P\d).*' + domain_regex = r'.*VTP Domain Name\s+:\s+(?P\S+).*' try: match_version = re.match(version_regex, body, re.DOTALL) diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_version.py b/lib/ansible/modules/network/nxos/nxos_vtp_version.py index 33eeef07e94..9a4dacc274b 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_version.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_version.py @@ -121,8 +121,8 @@ def get_vtp_config(module): vtp_parsed = {} if body: - version_regex = '.*VTP version running\s+:\s+(?P\d).*' - domain_regex = '.*VTP Domain Name\s+:\s+(?P\S+).*' + version_regex = r'.*VTP version running\s+:\s+(?P\d).*' + domain_regex = r'.*VTP Domain Name\s+:\s+(?P\S+).*' try: match_version = re.match(version_regex, body, re.DOTALL) diff --git a/test/sanity/pylint/config/default b/test/sanity/pylint/config/default index d8a0234731b..9e2bd7f7f74 100644 --- a/test/sanity/pylint/config/default +++ b/test/sanity/pylint/config/default @@ -3,7 +3,6 @@ disable= abstract-method, access-member-before-definition, - anomalous-backslash-in-string, arguments-differ, assignment-from-no-return, attribute-defined-outside-init,