Skip to content

Commit

Permalink
Merge pull request #1465 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release 3.3.1
  • Loading branch information
mirceaulinic authored Jun 16, 2021
2 parents f8ea101 + 9bf3cc4 commit 524a086
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![PyPI](https://img.shields.io/pypi/v/napalm.svg)](https://pypi.python.org/pypi/napalm)
[![PyPI versions](https://img.shields.io/pypi/pyversions/napalm.svg)](https://pypi.python.org/pypi/napalm)
[![Coverage Status](https://coveralls.io/repos/github/napalm-automation/napalm/badge.svg)](https://coveralls.io/github/napalm-automation/napalm)
[![Actions Build](https://github.com/napalm-automation/napalm/actions/workflows/commit.yaml/badge.svg?branch=develop)](https://github.com/napalm-automation/napalm/actions/workflows/commit.yaml)
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)


Expand Down
3 changes: 3 additions & 0 deletions napalm/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,7 @@ def ping(
size=c.PING_SIZE,
count=c.PING_COUNT,
vrf=c.PING_VRF,
source_interface=c.PING_SOURCE_INTERFACE,
):
"""
Executes ping on the device and returns a dictionary with the result
Expand All @@ -1290,6 +1291,8 @@ def ping(
:type count: optional
:param vrf: Use a specific VRF to execute the ping
:type vrf: optional
:param source_interface: Use an IP from a source interface as source address of echo request
:type source_interface: optional
Output dictionary has one of following keys:
Expand Down
1 change: 1 addition & 0 deletions napalm/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
PING_SIZE = 100
PING_COUNT = 5
PING_VRF = ""
PING_SOURCE_INTERFACE = ""

NETMIKO_MAP = {
"ios": "cisco_ios",
Expand Down
3 changes: 3 additions & 0 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,7 @@ def ping(
size=c.PING_SIZE,
count=c.PING_COUNT,
vrf=c.PING_VRF,
source_interface=c.PING_SOURCE_INTERFACE,
):
"""
Execute ping on the device and returns a dictionary with the result.
Expand Down Expand Up @@ -2036,6 +2037,8 @@ def ping(
command += " repeat {}".format(count)
if source != "":
command += " source {}".format(source)
if source_interface != "":
command += " interface {}".format(source_interface)

commands.append(command)
output = self.device.run_commands(commands, encoding="text")[-1]["output"]
Expand Down
6 changes: 5 additions & 1 deletion napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -3178,6 +3178,7 @@ def ping(
size=C.PING_SIZE,
count=C.PING_COUNT,
vrf=C.PING_VRF,
source_interface=C.PING_SOURCE_INTERFACE,
):
"""
Execute ping on the device and returns a dictionary with the result.
Expand Down Expand Up @@ -3208,6 +3209,8 @@ def ping(
command += " repeat {}".format(count)
if source != "":
command += " source {}".format(source)
elif source_interface != "":
command += " source {}".format(source_interface)

output = self._send_command(command)
if "%" in output:
Expand Down Expand Up @@ -3442,7 +3445,8 @@ def get_network_instances(self, name=""):

# remove interfaces in the VRF from the default VRF
for item in interfaces:
del instances["default"]["interfaces"]["interface"][item]
if item in instances["default"]["interfaces"]["interface"]:
del instances["default"]["interfaces"]["interface"][item]

instances[vrf_name] = {
"name": vrf_name,
Expand Down
5 changes: 1 addition & 4 deletions napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
output_messages = napalm.base.helpers.convert(
int, napalm.base.helpers.find_txt(neighbor, "MessagesSent"), 0
)
connection_down_count = napalm.base.helpers.convert(
flap_count = napalm.base.helpers.convert(
int,
napalm.base.helpers.find_txt(neighbor, "ConnectionDownCount"),
0,
Expand Down Expand Up @@ -1361,9 +1361,6 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
napalm.base.helpers.find_txt(neighbor, "ConfiguredKeepalive"),
0,
)
flap_count = int(connection_down_count / 2)
if up:
flap_count -= 1
if remote_as not in bgp_neighbors_detail[vrf_name].keys():
bgp_neighbors_detail[vrf_name][remote_as] = []
bgp_neighbors_detail[vrf_name][remote_as].append(
Expand Down
6 changes: 1 addition & 5 deletions napalm/iosxr_netconf/iosxr_netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ def get_vrf_neighbors_detail(
),
0,
)
connection_down_count = napalm.base.helpers.convert(
flap_count = napalm.base.helpers.convert(
int,
self._find_txt(
neighbor,
Expand Down Expand Up @@ -1995,10 +1995,6 @@ def get_vrf_neighbors_detail(
),
0,
)
flap_count = int(connection_down_count / 2)
if up:
flap_count -= 1

if remote_as not in bgp_vrf_neighbors_detail[vrf_name].keys():
bgp_vrf_neighbors_detail[vrf_name][remote_as] = []
bgp_vrf_neighbors_detail[vrf_name][remote_as].append(
Expand Down
31 changes: 21 additions & 10 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,11 @@ def _process_pipe(cmd, txt):
)
)
raw_txt = self.device.cli(safe_command, warning=False)
cli_output[str(command)] = str(_process_pipe(command, raw_txt))
if isinstance(raw_txt, etree._Element):
raw_txt = etree.tostring(raw_txt.get_parent()).decode()
cli_output[str(command)] = raw_txt
else:
cli_output[str(command)] = str(_process_pipe(command, raw_txt))
return cli_output

def get_bgp_config(self, group="", neighbor=""):
Expand Down Expand Up @@ -2061,6 +2065,7 @@ def ping(
size=C.PING_SIZE,
count=C.PING_COUNT,
vrf=C.PING_VRF,
source_interface=C.PING_SOURCE_INTERFACE,
):

ping_dict = {}
Expand All @@ -2071,6 +2076,7 @@ def ping(
size_str = ""
count_str = ""
vrf_str = ""
source_interface_str = ""

if source:
source_str = " source {source}".format(source=source)
Expand All @@ -2084,17 +2090,22 @@ def ping(
count_str = " count {count}".format(count=count)
if vrf:
vrf_str = " routing-instance {vrf}".format(vrf=vrf)
if source_interface:
source_interface_str = " interface {source_interface}".format(
source_interface=source_interface
)

ping_command = (
"ping {destination}{source}{ttl}{timeout}{size}{count}{vrf}".format(
destination=destination,
source=source_str,
ttl=maxttl_str,
timeout=timeout_str,
size=size_str,
count=count_str,
vrf=vrf_str,
)
"ping {destination}{source}{ttl}{timeout}{size}{count}{vrf}{source_interface}"
).format(
destination=destination,
source=source_str,
ttl=maxttl_str,
timeout=timeout_str,
size=size_str,
count=count_str,
vrf=vrf_str,
source_interface=source_interface_str,
)

ping_rpc = E("command", ping_command)
Expand Down
3 changes: 3 additions & 0 deletions napalm/nxos/nxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def ping(
size=c.PING_SIZE,
count=c.PING_COUNT,
vrf=c.PING_VRF,
source_interface=c.PING_SOURCE_INTERFACE,
):
"""
Execute ping on the device and returns a dictionary with the result.
Expand Down Expand Up @@ -311,6 +312,8 @@ def ping(
command += " count {}".format(count)
if source != "":
command += " source {}".format(source)
elif source_interface != "":
command += " source {}".format(source_interface)

if vrf != "":
command += " vrf {}".format(vrf)
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
black==21.5b0
coveralls==3.0.1
black==21.5b1
coveralls==3.1.0
ddt==1.4.2
flake8-import-order==0.18.1
pytest==5.4.3
pytest-cov==2.11.1
pytest-cov==2.12.0
pytest-json==0.4.0
pytest-pythonpath==0.7.3
pylama==7.7.1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="napalm",
version="3.3.0",
version="3.3.1",
packages=find_packages(exclude=("test*",)),
test_suite="test_base",
author="David Barroso, Kirk Byers, Mircea Ulinic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"active_prefix_count": 273802,
"configured_holdtime": 180,
"routing_table": "default",
"flap_count": 1,
"flap_count": 5,
"suppressed_prefix_count": 9,
"local_address": "20.20.20.21",
"remote_port": 179,
Expand Down Expand Up @@ -127,7 +127,7 @@
"active_prefix_count": 0,
"configured_holdtime": 180,
"routing_table": "default",
"flap_count": 3,
"flap_count": 9,
"suppressed_prefix_count": 0,
"local_address": "8.8.8.8",
"remote_port": 63014,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"configured_keepalive": 60,
"connection_state": "Established",
"export_policy": "EBGP-OUT-POLICY",
"flap_count": -1,
"flap_count": 0,
"holdtime": 180,
"import_policy": "EBGP-IN-POLICY",
"input_messages": 0,
Expand Down Expand Up @@ -83,7 +83,7 @@
"configured_keepalive": 60,
"connection_state": "Established",
"export_policy": "IBGPv6-OUT-POLICY",
"flap_count": -1,
"flap_count": 0,
"holdtime": 180,
"import_policy": "IBGPv6-IN-POLICY",
"input_messages": 0,
Expand Down Expand Up @@ -161,7 +161,7 @@
"configured_keepalive": 60,
"connection_state": "Established",
"export_policy": "IBGP-OUT-POLICY",
"flap_count": 0,
"flap_count": 2,
"holdtime": 180,
"import_policy": "",
"input_messages": 0,
Expand Down Expand Up @@ -198,7 +198,7 @@
"configured_keepalive": 60,
"connection_state": "Established",
"export_policy": "IBGP-OUT-POLICY",
"flap_count": -1,
"flap_count": 0,
"holdtime": 180,
"import_policy": "",
"input_messages": 0,
Expand Down
12 changes: 12 additions & 0 deletions test/junos/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from napalm.junos import junos

from ncclient.devices.junos import JunosDeviceHandler


@pytest.fixture(scope="class")
def set_device_parameters(request):
Expand Down Expand Up @@ -82,6 +84,15 @@ def __init__(self):
# disable it to use the DOM parser which was used prior.
self._use_filter = False

@property
def transform(self):
# Junos device transform, inherited from the ncclient class
return self._conn._device_handler.transform_reply

@transform.setter
def transform(self, func):
self._conn._device_handler.transform_reply = func

@property
def facts(self):
# we want to reinitialize it every time to avoid side effects
Expand Down Expand Up @@ -183,6 +194,7 @@ class FakeConnection:
def __init__(self, rpc):
self.rpc = FakeConnectionRPCObject(rpc)
self._session = FakeSession()
self._device_handler = JunosDeviceHandler({})


class FakeSession:
Expand Down

0 comments on commit 524a086

Please sign in to comment.