Fix anomalous backslashes and enable pylint test.

This commit is contained in:
Matt Clay
2017-11-21 22:22:40 -08:00
parent 9735a70059
commit c6bb6c72cc
30 changed files with 76 additions and 77 deletions

View File

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

View File

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

View File

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

View File

@@ -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 = {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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 = {}

View File

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

View File

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

View File

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

View File

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

View File

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