Skip to content

Commit 524a086

Browse files
authored
Merge pull request #1465 from napalm-automation/develop
Release 3.3.1
2 parents f8ea101 + 9bf3cc4 commit 524a086

File tree

14 files changed

+61
-31
lines changed

14 files changed

+61
-31
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![PyPI](https://img.shields.io/pypi/v/napalm.svg)](https://pypi.python.org/pypi/napalm)
22
[![PyPI versions](https://img.shields.io/pypi/pyversions/napalm.svg)](https://pypi.python.org/pypi/napalm)
3-
[![Coverage Status](https://coveralls.io/repos/github/napalm-automation/napalm/badge.svg)](https://coveralls.io/github/napalm-automation/napalm)
3+
[![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)
44
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
55

66

napalm/base/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,7 @@ def ping(
12731273
size=c.PING_SIZE,
12741274
count=c.PING_COUNT,
12751275
vrf=c.PING_VRF,
1276+
source_interface=c.PING_SOURCE_INTERFACE,
12761277
):
12771278
"""
12781279
Executes ping on the device and returns a dictionary with the result
@@ -1290,6 +1291,8 @@ def ping(
12901291
:type count: optional
12911292
:param vrf: Use a specific VRF to execute the ping
12921293
:type vrf: optional
1294+
:param source_interface: Use an IP from a source interface as source address of echo request
1295+
:type source_interface: optional
12931296
12941297
Output dictionary has one of following keys:
12951298

napalm/base/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
PING_SIZE = 100
5858
PING_COUNT = 5
5959
PING_VRF = ""
60+
PING_SOURCE_INTERFACE = ""
6061

6162
NETMIKO_MAP = {
6263
"ios": "cisco_ios",

napalm/eos/eos.py

+3
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,7 @@ def ping(
20062006
size=c.PING_SIZE,
20072007
count=c.PING_COUNT,
20082008
vrf=c.PING_VRF,
2009+
source_interface=c.PING_SOURCE_INTERFACE,
20092010
):
20102011
"""
20112012
Execute ping on the device and returns a dictionary with the result.
@@ -2036,6 +2037,8 @@ def ping(
20362037
command += " repeat {}".format(count)
20372038
if source != "":
20382039
command += " source {}".format(source)
2040+
if source_interface != "":
2041+
command += " interface {}".format(source_interface)
20392042

20402043
commands.append(command)
20412044
output = self.device.run_commands(commands, encoding="text")[-1]["output"]

napalm/ios/ios.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,7 @@ def ping(
31783178
size=C.PING_SIZE,
31793179
count=C.PING_COUNT,
31803180
vrf=C.PING_VRF,
3181+
source_interface=C.PING_SOURCE_INTERFACE,
31813182
):
31823183
"""
31833184
Execute ping on the device and returns a dictionary with the result.
@@ -3208,6 +3209,8 @@ def ping(
32083209
command += " repeat {}".format(count)
32093210
if source != "":
32103211
command += " source {}".format(source)
3212+
elif source_interface != "":
3213+
command += " source {}".format(source_interface)
32113214

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

34433446
# remove interfaces in the VRF from the default VRF
34443447
for item in interfaces:
3445-
del instances["default"]["interfaces"]["interface"][item]
3448+
if item in instances["default"]["interfaces"]["interface"]:
3449+
del instances["default"]["interfaces"]["interface"][item]
34463450

34473451
instances[vrf_name] = {
34483452
"name": vrf_name,

napalm/iosxr/iosxr.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
12831283
output_messages = napalm.base.helpers.convert(
12841284
int, napalm.base.helpers.find_txt(neighbor, "MessagesSent"), 0
12851285
)
1286-
connection_down_count = napalm.base.helpers.convert(
1286+
flap_count = napalm.base.helpers.convert(
12871287
int,
12881288
napalm.base.helpers.find_txt(neighbor, "ConnectionDownCount"),
12891289
0,
@@ -1361,9 +1361,6 @@ def get_bgp_neighbors_detail(self, neighbor_address=""):
13611361
napalm.base.helpers.find_txt(neighbor, "ConfiguredKeepalive"),
13621362
0,
13631363
)
1364-
flap_count = int(connection_down_count / 2)
1365-
if up:
1366-
flap_count -= 1
13671364
if remote_as not in bgp_neighbors_detail[vrf_name].keys():
13681365
bgp_neighbors_detail[vrf_name][remote_as] = []
13691366
bgp_neighbors_detail[vrf_name][remote_as].append(

napalm/iosxr_netconf/iosxr_netconf.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ def get_vrf_neighbors_detail(
18551855
),
18561856
0,
18571857
)
1858-
connection_down_count = napalm.base.helpers.convert(
1858+
flap_count = napalm.base.helpers.convert(
18591859
int,
18601860
self._find_txt(
18611861
neighbor,
@@ -1995,10 +1995,6 @@ def get_vrf_neighbors_detail(
19951995
),
19961996
0,
19971997
)
1998-
flap_count = int(connection_down_count / 2)
1999-
if up:
2000-
flap_count -= 1
2001-
20021998
if remote_as not in bgp_vrf_neighbors_detail[vrf_name].keys():
20031999
bgp_vrf_neighbors_detail[vrf_name][remote_as] = []
20042000
bgp_vrf_neighbors_detail[vrf_name][remote_as].append(

napalm/junos/junos.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,11 @@ def _process_pipe(cmd, txt):
11151115
)
11161116
)
11171117
raw_txt = self.device.cli(safe_command, warning=False)
1118-
cli_output[str(command)] = str(_process_pipe(command, raw_txt))
1118+
if isinstance(raw_txt, etree._Element):
1119+
raw_txt = etree.tostring(raw_txt.get_parent()).decode()
1120+
cli_output[str(command)] = raw_txt
1121+
else:
1122+
cli_output[str(command)] = str(_process_pipe(command, raw_txt))
11191123
return cli_output
11201124

11211125
def get_bgp_config(self, group="", neighbor=""):
@@ -2061,6 +2065,7 @@ def ping(
20612065
size=C.PING_SIZE,
20622066
count=C.PING_COUNT,
20632067
vrf=C.PING_VRF,
2068+
source_interface=C.PING_SOURCE_INTERFACE,
20642069
):
20652070

20662071
ping_dict = {}
@@ -2071,6 +2076,7 @@ def ping(
20712076
size_str = ""
20722077
count_str = ""
20732078
vrf_str = ""
2079+
source_interface_str = ""
20742080

20752081
if source:
20762082
source_str = " source {source}".format(source=source)
@@ -2084,17 +2090,22 @@ def ping(
20842090
count_str = " count {count}".format(count=count)
20852091
if vrf:
20862092
vrf_str = " routing-instance {vrf}".format(vrf=vrf)
2093+
if source_interface:
2094+
source_interface_str = " interface {source_interface}".format(
2095+
source_interface=source_interface
2096+
)
20872097

20882098
ping_command = (
2089-
"ping {destination}{source}{ttl}{timeout}{size}{count}{vrf}".format(
2090-
destination=destination,
2091-
source=source_str,
2092-
ttl=maxttl_str,
2093-
timeout=timeout_str,
2094-
size=size_str,
2095-
count=count_str,
2096-
vrf=vrf_str,
2097-
)
2099+
"ping {destination}{source}{ttl}{timeout}{size}{count}{vrf}{source_interface}"
2100+
).format(
2101+
destination=destination,
2102+
source=source_str,
2103+
ttl=maxttl_str,
2104+
timeout=timeout_str,
2105+
size=size_str,
2106+
count=count_str,
2107+
vrf=vrf_str,
2108+
source_interface=source_interface_str,
20982109
)
20992110

21002111
ping_rpc = E("command", ping_command)

napalm/nxos/nxos.py

+3
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def ping(
276276
size=c.PING_SIZE,
277277
count=c.PING_COUNT,
278278
vrf=c.PING_VRF,
279+
source_interface=c.PING_SOURCE_INTERFACE,
279280
):
280281
"""
281282
Execute ping on the device and returns a dictionary with the result.
@@ -311,6 +312,8 @@ def ping(
311312
command += " count {}".format(count)
312313
if source != "":
313314
command += " source {}".format(source)
315+
elif source_interface != "":
316+
command += " source {}".format(source_interface)
314317

315318
if vrf != "":
316319
command += " vrf {}".format(vrf)

requirements-dev.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
black==21.5b0
2-
coveralls==3.0.1
1+
black==21.5b1
2+
coveralls==3.1.0
33
ddt==1.4.2
44
flake8-import-order==0.18.1
55
pytest==5.4.3
6-
pytest-cov==2.11.1
6+
pytest-cov==2.12.0
77
pytest-json==0.4.0
88
pytest-pythonpath==0.7.3
99
pylama==7.7.1

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="napalm",
15-
version="3.3.0",
15+
version="3.3.1",
1616
packages=find_packages(exclude=("test*",)),
1717
test_suite="test_base",
1818
author="David Barroso, Kirk Byers, Mircea Ulinic",

test/iosxr/mocked_data/test_get_bgp_neighbors_detail/normal/expected_result.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"active_prefix_count": 273802,
9191
"configured_holdtime": 180,
9292
"routing_table": "default",
93-
"flap_count": 1,
93+
"flap_count": 5,
9494
"suppressed_prefix_count": 9,
9595
"local_address": "20.20.20.21",
9696
"remote_port": 179,
@@ -127,7 +127,7 @@
127127
"active_prefix_count": 0,
128128
"configured_holdtime": 180,
129129
"routing_table": "default",
130-
"flap_count": 3,
130+
"flap_count": 9,
131131
"suppressed_prefix_count": 0,
132132
"local_address": "8.8.8.8",
133133
"remote_port": 63014,

test/iosxr_netconf/mocked_data/test_get_bgp_neighbors_detail/normal/expected_result.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"configured_keepalive": 60,
1010
"connection_state": "Established",
1111
"export_policy": "EBGP-OUT-POLICY",
12-
"flap_count": -1,
12+
"flap_count": 0,
1313
"holdtime": 180,
1414
"import_policy": "EBGP-IN-POLICY",
1515
"input_messages": 0,
@@ -83,7 +83,7 @@
8383
"configured_keepalive": 60,
8484
"connection_state": "Established",
8585
"export_policy": "IBGPv6-OUT-POLICY",
86-
"flap_count": -1,
86+
"flap_count": 0,
8787
"holdtime": 180,
8888
"import_policy": "IBGPv6-IN-POLICY",
8989
"input_messages": 0,
@@ -161,7 +161,7 @@
161161
"configured_keepalive": 60,
162162
"connection_state": "Established",
163163
"export_policy": "IBGP-OUT-POLICY",
164-
"flap_count": 0,
164+
"flap_count": 2,
165165
"holdtime": 180,
166166
"import_policy": "",
167167
"input_messages": 0,
@@ -198,7 +198,7 @@
198198
"configured_keepalive": 60,
199199
"connection_state": "Established",
200200
"export_policy": "IBGP-OUT-POLICY",
201-
"flap_count": -1,
201+
"flap_count": 0,
202202
"holdtime": 180,
203203
"import_policy": "",
204204
"input_messages": 0,

test/junos/conftest.py

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from napalm.junos import junos
1212

13+
from ncclient.devices.junos import JunosDeviceHandler
14+
1315

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

87+
@property
88+
def transform(self):
89+
# Junos device transform, inherited from the ncclient class
90+
return self._conn._device_handler.transform_reply
91+
92+
@transform.setter
93+
def transform(self, func):
94+
self._conn._device_handler.transform_reply = func
95+
8596
@property
8697
def facts(self):
8798
# we want to reinitialize it every time to avoid side effects
@@ -183,6 +194,7 @@ class FakeConnection:
183194
def __init__(self, rpc):
184195
self.rpc = FakeConnectionRPCObject(rpc)
185196
self._session = FakeSession()
197+
self._device_handler = JunosDeviceHandler({})
186198

187199

188200
class FakeSession:

0 commit comments

Comments
 (0)