Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue177 #178

Merged
merged 3 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyeapi/api/routemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def set_match_statements(self, name, action, seqno, statements):
"""
try:
current_statements = self.get(name)[action][seqno]['match']
except:
except Exception:
current_statements = []

commands = list()
Expand Down Expand Up @@ -275,7 +275,7 @@ def set_set_statements(self, name, action, seqno, statements):
"""
try:
current_statements = self.get(name)[action][seqno]['set']
except:
except Exception:
current_statements = []

commands = list()
Expand Down
6 changes: 3 additions & 3 deletions pyeapi/api/staticroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ def getall(self):
# Get the four identifying components
ip_dest = match[0]
next_hop = match[1]
next_hop_ip = None if match[2] is '' else match[2]
next_hop_ip = None if match[2] == '' else match[2]
distance = int(match[3])

# Create the data dict with the remaining components
data = {}
data['tag'] = None if match[4] is '' else int(match[4])
data['route_name'] = None if match[5] is '' else match[5]
data['tag'] = None if match[4] == '' else int(match[4])
data['route_name'] = None if match[5] == '' else match[5]

# Build the complete dict entry from the four components
# and the data.
Expand Down
2 changes: 1 addition & 1 deletion pyeapi/api/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _parse_banners(self):
into the resource dict
"""
motd_value = login_value = None
matches = re.findall('^banner\s+(login|motd)\s?$\n(.*?)$\nEOF$\n',
matches = re.findall(r'^banner\s+(login|motd)\s?$\n(.*?)$\nEOF$\n',
self.config, re.DOTALL | re.M)
for match in matches:
if match[0].strip() == "motd":
Expand Down
2 changes: 1 addition & 1 deletion pyeapi/api/varp.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def set_addresses(self, name, addresses=None, default=False,
elif addresses is not None:
try:
current_addresses = self.get(name)['addresses']
except:
except Exception:
current_addresses = []

# remove virtual-router addresses not present in addresses list
Expand Down
2 changes: 1 addition & 1 deletion pyeapi/api/vrrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ def _vrrp_set(self, name, vrid, **kwargs):
if primary_ip in ('no', None):
cmd = self.set_primary_ip(name, vrid, value=None,
disable=True, run=False)
elif primary_ip is 'default':
elif primary_ip == 'default':
cmd = self.set_primary_ip(name, vrid, value=None,
default=True, run=False)
else:
Expand Down
4 changes: 2 additions & 2 deletions pyeapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,13 @@ def _get_version_properties(self):
# Parse out version info
output = self.enable('show version')
self._version = str(output[0]['result']['version'])
match = re.match('[\d.\d]+', output[0]['result']['version'])
match = re.match(r'[\d.\d]+', output[0]['result']['version'])
if match:
self._version_number = str(match.group(0))
else:
self._version_number = str(output[0]['result']['version'])
# Parse out model number
match = re.search('\d\d\d\d', output[0]['result']['modelName'])
match = re.search(r'\d\d\d\d', output[0]['result']['modelName'])
if match:
self._model = str(match.group(0))
else:
Expand Down
29 changes: 6 additions & 23 deletions pyeapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#
import os
import sys
import imp
import importlib
import inspect
import logging
import logging.handlers
Expand Down Expand Up @@ -78,28 +78,11 @@ def import_module(name):
The module that was imported

"""
parts = name.split('.')
path = None
module_name = ''
fhandle = None

for index, part in enumerate(parts):
module_name = part if index == 0 else '%s.%s' % (module_name, part)
path = [path] if path is not None else path

try:
fhandle, path, descr = imp.find_module(part, path)
if module_name in sys.modules:
# since imp.load_module works like reload, need to be sure not
# to reload a previously loaded module
mod = sys.modules[module_name]
else:
mod = imp.load_module(module_name, fhandle, path, descr)
finally:
# lets be sure to clean up after ourselves
if fhandle:
fhandle.close()

if name in sys.modules:
# Be sure not to reload a previously loaded module
mod = sys.modules[name]
else:
mod = importlib.import_module(name)
return mod


Expand Down
4 changes: 2 additions & 2 deletions test/system/test_api_staticroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def _ip_addr():

def _next_hop():
next_hop = choice(NEXT_HOPS)
if next_hop is 'Null0':
if next_hop == 'Null0':
return (next_hop, None)
ip1 = random_int(0, 223)
ip2 = random_int(0, 255)
ip3 = random_int(0, 255)
ip4 = random_int(0, 255)
ip_addr = "%s.%s.%s.%s" % (ip1, ip2, ip3, ip4)
if next_hop is 'IP':
if next_hop == 'IP':
return (ip_addr, None)
return (next_hop, ip_addr)

Expand Down
4 changes: 1 addition & 3 deletions test/system/test_api_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_set_banner_motd(self):

def test_set_banner_motd_donkey(self):
for dut in self.duts:
donkey_chicken = """
donkey_chicken = r"""
/\ /\
( \\ // )
\ \\ // /
Expand All @@ -187,8 +187,6 @@ def test_set_banner_motd_donkey(self):
self.assertTrue(resp, 'dut=%s' % dut)
self.assertIn(donkey_chicken, dut.running_config)



def test_set_banner_motd_default(self):
for dut in self.duts:
dut.config([dict(cmd="banner motd",
Expand Down
7 changes: 3 additions & 4 deletions test/system/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ def test_exception_trace(self):
# Send an incomplete command
cases.append(('show run', rfmt
% (1002, 'invalid command',
'incomplete token \(at token \d+: \'.*\'\)')))
r'incomplete token \(at token \d+: \'.*\'\)')))
# Send a mangled command
cases.append(('shwo version', rfmt
% (1002, 'invalid command',
'Invalid input \(at token \d+: \'.*\'\)')))
r'Invalid input \(at token \d+: \'.*\'\)')))
# Send a command that cannot be run through the api
# note the command for reload looks to change in new EOS
# in 4.15 the reload now is replaced with 'force' if you are
Expand All @@ -295,8 +295,7 @@ def test_exception_trace(self):
# Send a command that has insufficient priv
cases.append(('show running-config', rfmt
% (1002, 'invalid command',
'Invalid input \(privileged mode required\)')))

r'Invalid input \(privileged mode required\)')))

for dut in self.duts:
for (cmd, regex) in cases:
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pyeapi.utils


class TestUtils(unittest.TestCase):

@patch('pyeapi.utils.import_module')
Expand Down