Fix anomalous backslashes and enable pylint test.

pull/27734/merge
Matt Clay 7 years ago
parent 9735a70059
commit c6bb6c72cc

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: cl_bond
version_added: "2.1"

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: cl_bridge
version_added: "2.1"

@ -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)

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: cl_interface
version_added: "2.1"

@ -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

@ -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

@ -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)

@ -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)
}

@ -451,7 +451,7 @@ class ApiParameters(Parameters):
@address.setter
def address(self, value):
pattern = '^(?P<ip>[0-9A-Fa-f:.]+)%?(?P<rd>\d+)?\/(?P<nm>\d+)$'
pattern = r'^(?P<ip>[0-9A-Fa-f:.]+)%?(?P<rd>\d+)?\/(?P<nm>\d+)$'
matches = re.match(pattern, value)
if not matches:
raise F5ModuleError(

@ -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'}

@ -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<pct>\d+)\s+\w+\s+\((?P<rx>\d+)\/(?P<tx>\d+)\)")
rtt_re = re.compile(".*,\s+\S+\s+\S+\s+=\s+(?P<min>\d+)\/(?P<avg>\d+)\/(?P<max>\d+)\s+\w+\s*$|.*\s*$")
rate_re = re.compile(r"^\w+\s+\w+\s+\w+\s+(?P<pct>\d+)\s+\w+\s+\((?P<rx>\d+)/(?P<tx>\d+)\)")
rtt_re = re.compile(r".*,\s+\S+\s+\S+\s+=\s+(?P<min>\d+)/(?P<avg>\d+)/(?P<max>\d+)\s+\w+\s*$|.*\s*$")
rate = rate_re.match(ping_stats)
rtt = rtt_re.match(ping_stats)

@ -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)

@ -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):

@ -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

@ -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<key>\S+).*'.format(server_type)
aaa_regex = r'.*{0}-server\skey\s\d\s+(?P<key>\S+).*'.format(server_type)
server_body = execute_show_command(
server_command, module, command_type='cli_show_ascii')[0]

@ -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',

@ -87,7 +87,7 @@ def check_args(module, warnings):
def get_available_features(feature, module):
available_features = {}
feature_regex = '(?P<feature>\S+)\s+\d+\s+(?P<state>.*)'
feature_regex = r'(?P<feature>\S+)\s+\d+\s+(?P<state>.*)'
command = {'command': 'show feature', 'output': 'text'}
try:

@ -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<route_map>\S+).*')
prefix_source_regex = ('.*ip igmp static-oif\s+(?P<prefix>'
'((\d+.){3}\d+))(\ssource\s'
'(?P<source>\S+))?.*')
route_map_regex = (r'.*ip igmp static-oif route-map\s+'
r'(?P<route_map>\S+).*')
prefix_source_regex = (r'.*ip igmp static-oif\s+(?P<prefix>'
r'((\d+.){3}\d+))(\ssource\s'
r'(?P<source>\S+))?.*')
for line in split_body:
temp = {}

@ -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<addr>\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \
'\s\d{1,3}(?:\.\d{1,3}){3}\/(?P<mask>\d+)(?:\s(?P<secondary>secondary)\s)?' + \
'(.+?tag:\s(?P<tag>\d+).*)?'
regex = r'.*IP\saddress:\s(?P<addr>\d{1,3}(?:\.\d{1,3}){3}),\sIP\ssubnet:' + \
r'\s\d{1,3}(?:\.\d{1,3}){3}\/(?P<mask>\d+)(?:\s(?P<secondary>secondary)\s)?' + \
r'(.+?tag:\s(?P<tag>\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<vrf>\S+?)\s'
vrf_regex = r'.+?VRF\s+(?P<vrf>\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<dot1q>\d+).*)?'
regex = r'(.+?ID\s(?P<dot1q>\d+).*)?'
match = re.match(regex, splitted_body[index])
if match:
match_dict = match.groupdict()

@ -179,9 +179,9 @@ def get_ntp_peer(module):
ntp = response
if ntp:
ntp_regex = (
".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
"(key\s(?P<key_id>\d+))?.*"
r".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
r"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
r"(key\s(?P<key_id>\d+))?.*"
)
split_ntp = ntp.splitlines()

@ -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<key_id>\d+)\s"
"md5\s(?P<md5string>\S+).*")
auth_regex = (r".*ntp\sauthentication-key\s(?P<key_id>\d+)\s"
r"md5\s(?P<md5string>\S+).*")
body = execute_show_command(command, module)[0]

@ -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)

@ -72,7 +72,7 @@ PARAM_TO_COMMAND_KEYMAP = {
def get_value(config, module):
splitted_config = config.splitlines()
value_list = []
REGEX = '^router ospf\s(?P<ospf>\S+).*'
REGEX = r'^router ospf\s(?P<ospf>\S+).*'
for line in splitted_config:
value = ''
if 'router ospf' in line:

@ -191,8 +191,8 @@ def get_existing(module):
body = execute_show_command(command, module)[0]
if body:
split_body = body.splitlines()
snapshot_regex = ('(?P<name>\S+)\s+(?P<date>\w+\s+\w+\s+\d+\s+\d+'
':\d+:\d+\s+\d+)\s+(?P<description>.*)')
snapshot_regex = (r'(?P<name>\S+)\s+(?P<date>\w+\s+\w+\s+\d+\s+\d+'
r':\d+:\d+\s+\d+)\s+(?P<description>.*)')
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<section>\S+)\].*'
section_regex = r'.*\[(?P<section>\S+)\].*'
split_body = body.split('\n\n')
for section in split_body:
temp = {}

@ -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

@ -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<vrf>\S+).*"
vrf_regex = r".*vrf\s+member\s+(?P<vrf>\S+).*"
try:
body = execute_show_command(command, module)

@ -123,8 +123,8 @@ def get_vtp_config(module):
vtp_parsed = {}
if body:
version_regex = '.*VTP version running\s+:\s+(?P<version>\d).*'
domain_regex = '.*VTP Domain Name\s+:\s+(?P<domain>\S+).*'
version_regex = r'.*VTP version running\s+:\s+(?P<version>\d).*'
domain_regex = r'.*VTP Domain Name\s+:\s+(?P<domain>\S+).*'
try:
match_version = re.match(version_regex, body, re.DOTALL)

@ -154,8 +154,8 @@ def get_vtp_config(module):
vtp_parsed = {}
if body:
version_regex = '.*VTP version running\s+:\s+(?P<version>\d).*'
domain_regex = '.*VTP Domain Name\s+:\s+(?P<domain>\S+).*'
version_regex = r'.*VTP version running\s+:\s+(?P<version>\d).*'
domain_regex = r'.*VTP Domain Name\s+:\s+(?P<domain>\S+).*'
try:
match_version = re.match(version_regex, body, re.DOTALL)

@ -121,8 +121,8 @@ def get_vtp_config(module):
vtp_parsed = {}
if body:
version_regex = '.*VTP version running\s+:\s+(?P<version>\d).*'
domain_regex = '.*VTP Domain Name\s+:\s+(?P<domain>\S+).*'
version_regex = r'.*VTP version running\s+:\s+(?P<version>\d).*'
domain_regex = r'.*VTP Domain Name\s+:\s+(?P<domain>\S+).*'
try:
match_version = re.match(version_regex, body, re.DOTALL)

@ -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,

Loading…
Cancel
Save