Skip to content

Commit

Permalink
[test] Resolve deprecation warnings in tests (#565)
Browse files Browse the repository at this point in the history
Resolve deprecation warnings in tests.
  • Loading branch information
bewing committed Dec 1, 2017
2 parents 584197e + cc3d5a1 commit 890b936
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 99 deletions.
2 changes: 1 addition & 1 deletion napalm/base/clitools/cl_napalm_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import logging

logger = logging.getLogger('cl-napalm-config.py')
warning()


def run(vendor, hostname, user, password, strategy, optional_args, config_file, dry_run):
Expand Down Expand Up @@ -55,6 +54,7 @@ def run(vendor, hostname, user, password, strategy, optional_args, config_file,


def main():
warning()
args = build_help(configure=True)
configure_logging(logger, args.debug)

Expand Down
2 changes: 1 addition & 1 deletion napalm/base/clitools/cl_napalm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import logging

logger = logging.getLogger('cl_napalm_test.py')
warning()


def main():
warning()
args = build_help(connect_test=True)
configure_logging(logger, args.debug)

Expand Down
2 changes: 1 addition & 1 deletion napalm/base/clitools/cl_napalm_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import logging

logger = logging.getLogger('cl_napalm_validate.py')
warning()


def main():
warning()
args = build_help(validate=True)
configure_logging(logger, args.debug)

Expand Down
6 changes: 5 additions & 1 deletion napalm/base/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
from pydoc import locate


# inspect.getargspec deprecated in Python 3.5, use getfullargspec if available
inspect_getargspec = getattr(inspect, "getfullargspec", inspect.getargspec)


def raise_exception(result):
exc = locate(result["exception"])
if exc:
Expand All @@ -45,7 +49,7 @@ def is_mocked_method(method):

def mocked_method(path, name, count):
parent_method = getattr(NetworkDriver, name)
parent_method_args = inspect.getargspec(parent_method)
parent_method_args = inspect_getargspec(parent_method)
modifier = 0 if 'self' not in parent_method_args.args else 1

def _mocked_method(*args, **kwargs):
Expand Down
12 changes: 8 additions & 4 deletions napalm/base/test/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from napalm.base.test import conftest


# inspect.getargspec deprecated in Python 3.5, use getfullargspec if available
inspect_getargspec = getattr(inspect, "getfullargspec", inspect.getargspec)


def list_dicts_diff(prv, nxt):
"""Compare two lists of dicts."""
result = []
Expand Down Expand Up @@ -133,17 +137,17 @@ def test_method_signatures(self):
continue
try:
orig = getattr(NetworkDriver, attr)
orig_spec = inspect.getargspec(orig)
orig_spec = inspect_getargspec(orig)
except AttributeError:
orig_spec = 'Method does not exist in napalm.base'
func_spec = inspect.getargspec(func)
func_spec = inspect_getargspec(func)
if orig_spec != func_spec:
errors[attr] = (orig_spec, func_spec)

EXTRA_METHODS = ['__init__', ]
for method in EXTRA_METHODS:
orig_spec = inspect.getargspec(getattr(NetworkDriver, method))
func_spec = inspect.getargspec(getattr(cls, method))
orig_spec = inspect_getargspec(getattr(NetworkDriver, method))
func_spec = inspect_getargspec(getattr(cls, method))
if orig_spec != func_spec:
errors[attr] = (orig_spec, func_spec)

Expand Down
2 changes: 1 addition & 1 deletion napalm/base/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


# We put it here to compile it only once
numeric_compare_regex = re.compile("^(<|>|<=|>=|==|!=)(\d+(\.\d+){0,1})$")
numeric_compare_regex = re.compile(r"^(<|>|<=|>=|==|!=)(\d+(\.\d+){0,1})$")


def _get_validation_file(validation_file):
Expand Down
48 changes: 24 additions & 24 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class EOSDriver(NetworkDriver):
("protocol https certificate", 2)
]

_RE_BGP_INFO = re.compile('BGP neighbor is (?P<neighbor>.*?), remote AS (?P<as>.*?), .*') # noqa
_RE_BGP_RID_INFO = re.compile('.*BGP version 4, remote router ID (?P<rid>.*?), VRF (?P<vrf>.*?)$') # noqa
_RE_BGP_DESC = re.compile('\s+Description: (?P<description>.*?)')
_RE_BGP_LOCAL = re.compile('Local AS is (?P<as>.*?),.*')
_RE_BGP_PREFIX = re.compile('(\s*?)(?P<af>IPv[46]) Unicast:\s*(?P<sent>\d+)\s*(?P<received>\d+)') # noqa
_RE_BGP_INFO = re.compile(r'BGP neighbor is (?P<neighbor>.*?), remote AS (?P<as>.*?), .*') # noqa
_RE_BGP_RID_INFO = re.compile(r'.*BGP version 4, remote router ID (?P<rid>.*?), VRF (?P<vrf>.*?)$') # noqa
_RE_BGP_DESC = re.compile(r'\s+Description: (?P<description>.*?)')
_RE_BGP_LOCAL = re.compile(r'Local AS is (?P<as>.*?),.*')
_RE_BGP_PREFIX = re.compile(r'(\s*?)(?P<af>IPv[46]) Unicast:\s*(?P<sent>\d+)\s*(?P<received>\d+)') # noqa
_RE_SNMP_COMM = re.compile(r"""^snmp-server\s+community\s+(?P<community>\S+)
(\s+view\s+(?P<view>\S+))?(\s+(?P<access>ro|rw)?)
(\s+ipv6\s+(?P<v6_acl>\S+))?(\s+(?P<v4_acl>\S+))?$""", re.VERBOSE)
Expand Down Expand Up @@ -524,7 +524,7 @@ def extract_temperature_data(data):
# Matches either of
# Mem: 3844356k total, 3763184k used, 81172k free, 16732k buffers ( 4.16 > )
# KiB Mem: 32472080 total, 5697604 used, 26774476 free, 372052 buffers ( 4.16 < )
mem_regex = '.*total,\s+(?P<used>\d+)[k\s]+used,\s+(?P<free>\d+)[k\s]+free,.*'
mem_regex = r'.*total,\s+(?P<used>\d+)[k\s]+used,\s+(?P<free>\d+)[k\s]+free,.*'
m = re.match(mem_regex, cpu_lines[3])
environment_counters['memory'] = {
'available_ram': int(m.group('free')),
Expand Down Expand Up @@ -864,11 +864,11 @@ def get_ntp_stats(self):
ntp_stats = []

REGEX = (
'^\s?(\+|\*|x|-)?([a-zA-Z0-9\.+-:]+)'
'\s+([a-zA-Z0-9\.]+)\s+([0-9]{1,2})'
'\s+(-|u)\s+([0-9h-]+)\s+([0-9]+)'
'\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.-]+)'
'\s+([0-9\.]+)\s?$'
r'^\s?(\+|\*|x|-)?([a-zA-Z0-9\.+-:]+)'
r'\s+([a-zA-Z0-9\.]+)\s+([0-9]{1,2})'
r'\s+(-|u)\s+([0-9h-]+)\s+([0-9]+)'
r'\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.-]+)'
r'\s+([0-9\.]+)\s?$'
)

commands = []
Expand Down Expand Up @@ -1233,24 +1233,24 @@ def traceroute(self,
vrf=c.TRACEROUTE_VRF):

_HOP_ENTRY_PROBE = [
'\s+',
'(', # beginning of host_name (ip_address) RTT group
'(', # beginning of host_name (ip_address) group only
'([a-zA-Z0-9\.:-]*)', # hostname
'\s+',
'\(?([a-fA-F0-9\.:][^\)]*)\)?' # IP Address between brackets
')?', # end of host_name (ip_address) group only
r'\s+',
r'(', # beginning of host_name (ip_address) RTT group
r'(', # beginning of host_name (ip_address) group only
r'([a-zA-Z0-9\.:-]*)', # hostname
r'\s+',
r'\(?([a-fA-F0-9\.:][^\)]*)\)?' # IP Address between brackets
r')?', # end of host_name (ip_address) group only
# also hostname/ip are optional -- they can or cannot be specified
# if not specified, means the current probe followed the same path as the previous
'\s+',
'(\d+\.\d+)\s+ms', # RTT
'|\*', # OR *, when non responsive hop
')' # end of host_name (ip_address) RTT group
r'\s+',
r'(\d+\.\d+)\s+ms', # RTT
r'|\*', # OR *, when non responsive hop
r')' # end of host_name (ip_address) RTT group
]

_HOP_ENTRY = [
'\s?', # space before hop index?
'(\d+)', # hop index
r'\s?', # space before hop index?
r'(\d+)', # hop index
]

traceroute_result = {}
Expand Down
14 changes: 7 additions & 7 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def get_interfaces(self):
mac_addr_match = re.search(mac_addr_regex, line)
mac_address = napalm.base.helpers.mac(mac_addr_match.groups()[0])

descr_regex = "^\s+Description:\s+(.+?)$"
descr_regex = r"^\s+Description:\s+(.+?)$"
if re.search(descr_regex, line):
descr_match = re.search(descr_regex, line)
description = descr_match.groups()[0]
Expand Down Expand Up @@ -1728,7 +1728,7 @@ def get_ntp_stats(self):

elif len(line.split()) == 9:
address, ref_clock, st, when, poll, reach, delay, offset, disp = line.split()
address_regex = re.match('(\W*)([0-9.*]*)', address)
address_regex = re.match(r'(\W*)([0-9.*]*)', address)
try:
ntp_stats.append({
'remote': py23_compat.text_type(address_regex.group(2)),
Expand Down Expand Up @@ -1914,10 +1914,10 @@ def process_mac_fields(vlan, mac, mac_type, interface):
def get_probes_config(self):
probes = {}
probes_regex = r"ip\s+sla\s+(?P<id>\d+)\n" \
"\s+(?P<probe_type>\S+)\s+(?P<probe_args>.*\n).*" \
"\s+tag\s+(?P<name>\S+)\n.*" \
"\s+history\s+buckets-kept\s+(?P<probe_count>\d+)\n.*" \
"\s+frequency\s+(?P<interval>\d+)$"
r"\s+(?P<probe_type>\S+)\s+(?P<probe_args>.*\n).*" \
r"\s+tag\s+(?P<name>\S+)\n.*" \
r"\s+history\s+buckets-kept\s+(?P<probe_count>\d+)\n.*" \
r"\s+frequency\s+(?P<interval>\d+)$"
probe_args = {
'icmp-echo': r"^(?P<target>\S+)\s+source-(?:ip|interface)\s+(?P<source>\S+)$"
}
Expand Down Expand Up @@ -2128,7 +2128,7 @@ def traceroute(self, destination, source=C.TRACEROUTE_SOURCE,

results = dict()
# Find all hops
hops = re.findall('\\n\s+[0-9]{1,3}\s', output)
hops = re.findall(r'\n\s+[0-9]{1,3}\s', output)
for hop in hops:
# Search for hop in the output
hop_match = re.search(hop, output)
Expand Down
2 changes: 1 addition & 1 deletion napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def get_module_xml_query(module, selection):
if napalm.base.helpers.find_txt(
card, 'Card/Attributes/FRUInfo/ModuleAdministrativeState') == "ADMIN_UP":
slot_name = napalm.base.helpers.find_txt(slot, 'Naming/Name')
module_type = re.sub("\d+", "", slot_name)
module_type = re.sub(r"\d+", "", slot_name)
if len(module_type) > 0:
active_modules[module_type].append(slot_name)
else:
Expand Down
10 changes: 5 additions & 5 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,11 +1260,11 @@ def get_ntp_stats(self):
ntp_stats = []

REGEX = (
'^\s?(\+|\*|x|-)?([a-zA-Z0-9\.+-:]+)'
'\s+([a-zA-Z0-9\.]+)\s+([0-9]{1,2})'
'\s+(-|u)\s+([0-9h-]+)\s+([0-9]+)'
'\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.-]+)'
'\s+([0-9\.]+)\s?$'
r'^\s?(\+|\*|x|-)?([a-zA-Z0-9\.+-:]+)'
r'\s+([a-zA-Z0-9\.]+)\s+([0-9]{1,2})'
r'\s+(-|u)\s+([0-9h-]+)\s+([0-9]+)'
r'\s+([0-9]+)\s+([0-9\.]+)\s+([0-9\.-]+)'
r'\s+([0-9\.]+)\s?$'
)

ntp_assoc_output = self.device.cli('show ntp associations no-resolve')
Expand Down
44 changes: 22 additions & 22 deletions napalm/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ def get_lldp_neighbors_detail(self, interface=''):
if not lldp_neighbors_list:
return lldp_neighbors # empty dict

CHASSIS_REGEX = '^(Chassis id:)\s+([a-z0-9\.]+)$'
PORT_REGEX = '^(Port id:)\s+([0-9]+)$'
LOCAL_PORT_ID_REGEX = '^(Local Port id:)\s+(.*)$'
PORT_DESCR_REGEX = '^(Port Description:)\s+(.*)$'
SYSTEM_NAME_REGEX = '^(System Name:)\s+(.*)$'
SYSTEM_DESCR_REGEX = '^(System Description:)\s+(.*)$'
SYST_CAPAB_REEGX = '^(System Capabilities:)\s+(.*)$'
ENABL_CAPAB_REGEX = '^(Enabled Capabilities:)\s+(.*)$'
VLAN_ID_REGEX = '^(Vlan ID:)\s+(.*)$'
CHASSIS_REGEX = r'^(Chassis id:)\s+([a-z0-9\.]+)$'
PORT_REGEX = r'^(Port id:)\s+([0-9]+)$'
LOCAL_PORT_ID_REGEX = r'^(Local Port id:)\s+(.*)$'
PORT_DESCR_REGEX = r'^(Port Description:)\s+(.*)$'
SYSTEM_NAME_REGEX = r'^(System Name:)\s+(.*)$'
SYSTEM_DESCR_REGEX = r'^(System Description:)\s+(.*)$'
SYST_CAPAB_REEGX = r'^(System Capabilities:)\s+(.*)$'
ENABL_CAPAB_REGEX = r'^(Enabled Capabilities:)\s+(.*)$'
VLAN_ID_REGEX = r'^(Vlan ID:)\s+(.*)$'

lldp_neighbor = {}
interface_name = None
Expand Down Expand Up @@ -870,24 +870,24 @@ def traceroute(self,
timeout=c.TRACEROUTE_TIMEOUT,
vrf=c.TRACEROUTE_VRF):
_HOP_ENTRY_PROBE = [
'\s+',
'(', # beginning of host_name (ip_address) RTT group
'(', # beginning of host_name (ip_address) group only
'([a-zA-Z0-9\.:-]*)', # hostname
'\s+',
'\(?([a-fA-F0-9\.:][^\)]*)\)?' # IP Address between brackets
')?', # end of host_name (ip_address) group only
r'\s+',
r'(', # beginning of host_name (ip_address) RTT group
r'(', # beginning of host_name (ip_address) group only
r'([a-zA-Z0-9\.:-]*)', # hostname
r'\s+',
r'\(?([a-fA-F0-9\.:][^\)]*)\)?' # IP Address between brackets
r')?', # end of host_name (ip_address) group only
# also hostname/ip are optional -- they can or cannot be specified
# if not specified, means the current probe followed the same path as the previous
'\s+',
'(\d+\.\d+)\s+ms', # RTT
'|\*', # OR *, when non responsive hop
')' # end of host_name (ip_address) RTT group
r'\s+',
r'(\d+\.\d+)\s+ms', # RTT
r'|\*', # OR *, when non responsive hop
r')' # end of host_name (ip_address) RTT group
]

_HOP_ENTRY = [
'\s?', # space before hop index?
'(\d+)', # hop index
r'\s?', # space before hop index?
r'(\d+)', # hop index
]

traceroute_result = {}
Expand Down
Loading

0 comments on commit 890b936

Please sign in to comment.