[Python-modules-commits] [napalm-iosxr] 01/04: Import napalm-iosxr_0.4.2.orig.tar.gz
Vincent Bernat
bernat at moszumanska.debian.org
Sun Dec 25 10:43:32 UTC 2016
This is an automated email from the git hooks/post-receive script.
bernat pushed a commit to branch master
in repository napalm-iosxr.
commit 459c3e4e898a47de108a81cd5ee0ce1f009671e5
Author: Vincent Bernat <bernat at debian.org>
Date: Sun Dec 25 11:28:57 2016 +0100
Import napalm-iosxr_0.4.2.orig.tar.gz
---
PKG-INFO | 2 +-
napalm_iosxr.egg-info/PKG-INFO | 2 +-
napalm_iosxr.egg-info/SOURCES.txt | 8 +-
napalm_iosxr/iosxr.py | 248 +++++++++++++++------------
napalm_iosxr/templates/delete_ntp_servers.j2 | 3 +
napalm_iosxr/templates/delete_snmp_config.j2 | 14 ++
napalm_iosxr/templates/set_ntp_servers.j2 | 3 +
napalm_iosxr/templates/snmp_config.j2 | 23 +++
setup.cfg | 5 +
setup.py | 2 +-
test/unit/conftest.py | 74 ++++++++
test/unit/test_getters.py | 13 ++
12 files changed, 281 insertions(+), 116 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index d7f302a..e4387e5 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: napalm-iosxr
-Version: 0.3.2
+Version: 0.4.2
Summary: Network Automation and Programmability Abstraction Layer with Multivendor support
Home-page: https://github.com/napalm-automation/napalm-iosxr
Author: David Barroso, Mircea Ulinic
diff --git a/napalm_iosxr.egg-info/PKG-INFO b/napalm_iosxr.egg-info/PKG-INFO
index d7f302a..e4387e5 100644
--- a/napalm_iosxr.egg-info/PKG-INFO
+++ b/napalm_iosxr.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: napalm-iosxr
-Version: 0.3.2
+Version: 0.4.2
Summary: Network Automation and Programmability Abstraction Layer with Multivendor support
Home-page: https://github.com/napalm-automation/napalm-iosxr
Author: David Barroso, Mircea Ulinic
diff --git a/napalm_iosxr.egg-info/SOURCES.txt b/napalm_iosxr.egg-info/SOURCES.txt
index dfccece..ec19830 100644
--- a/napalm_iosxr.egg-info/SOURCES.txt
+++ b/napalm_iosxr.egg-info/SOURCES.txt
@@ -10,11 +10,17 @@ napalm_iosxr.egg-info/dependency_links.txt
napalm_iosxr.egg-info/requires.txt
napalm_iosxr.egg-info/top_level.txt
napalm_iosxr/templates/delete_ntp_peers.j2
+napalm_iosxr/templates/delete_ntp_servers.j2
napalm_iosxr/templates/delete_probes.j2
+napalm_iosxr/templates/delete_snmp_config.j2
napalm_iosxr/templates/schedule_probes.j2
napalm_iosxr/templates/set_hostname.j2
napalm_iosxr/templates/set_ntp_peers.j2
+napalm_iosxr/templates/set_ntp_servers.j2
napalm_iosxr/templates/set_probes.j2
+napalm_iosxr/templates/snmp_config.j2
test/__init__.py
test/unit/TestIOSXRDriver.py
-test/unit/__init__.py
\ No newline at end of file
+test/unit/__init__.py
+test/unit/conftest.py
+test/unit/test_getters.py
\ No newline at end of file
diff --git a/napalm_iosxr/iosxr.py b/napalm_iosxr/iosxr.py
index 87812d3..d6a1221 100644
--- a/napalm_iosxr/iosxr.py
+++ b/napalm_iosxr/iosxr.py
@@ -33,6 +33,7 @@ from pyIOSXR.exceptions import InvalidInputError
# import NAPALM base
import napalm_base.helpers
+import napalm_base.constants as C
from napalm_base.base import NetworkDriver
from napalm_base.utils import py23_compat
from napalm_base.exceptions import ConnectionException
@@ -72,6 +73,11 @@ class IOSXRDriver(NetworkDriver):
def close(self):
self.device.close()
+ def is_alive(self):
+ return {
+ 'is_alive': self.device.device.remote_conn.transport.is_active()
+ }
+
def load_replace_candidate(self, filename=None, config=None):
self.pending_changes = True
self.replace = True
@@ -480,44 +486,53 @@ class IOSXRDriver(NetworkDriver):
# Memory
#
- rpc_command = '<Get><AdminOperational><MemorySummary>\
- </MemorySummary></AdminOperational></Get>'
- result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))
-
- for node in result_tree.xpath('.//Node'):
- if napalm_base.helpers.find_txt(node,
- 'Naming/NodeName/Slot') == active_modules['RSP'][0]:
- available_ram = napalm_base.helpers.convert(
- int, napalm_base.helpers.find_txt(node, 'Summary/SystemRAMMemory'))
- free_ram = napalm_base.helpers.convert(
- int, napalm_base.helpers.find_txt(node, 'Summary/FreeApplicationMemory'))
- break # we're only looking at one of the RSP's
-
- if available_ram and free_ram:
- used_ram = available_ram - free_ram
- memory = {}
- memory['available_ram'] = available_ram
- memory['used_ram'] = used_ram
- environment_status['memory'] = memory
-
- #
- # Fans
- #
+ facts = self.get_facts()
+ router_model = facts.get('model')
+ is_xrv = router_model.lower().startswith('xrv')
+ environment_status['memory'] = {
+ 'available_ram': 0.0,
+ 'used_ram': 0.0
+ }
- for fan in active_modules['FT']:
- rpc_command = get_module_xml_query(fan, '')
+ if not is_xrv:
+ rpc_command = '<Get><AdminOperational><MemorySummary>\
+ </MemorySummary></AdminOperational></Get>'
result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))
- for module in result_tree.xpath('.//Module'):
- for sensortype in module.xpath('.//SensorType'):
- for sensorname in sensortype.xpath('.//SensorNameTable'):
- if napalm_base.helpers.find_txt(sensorname,
- 'SensorName/Naming/Name') == "host__FanSpeed_0":
- environment_status['fans'][fan] = {
- 'status': napalm_base.helpers.convert(
- int, napalm_base.helpers.find_txt(sensorname,
- 'SensorName/ValueDetailed/Status')
- ) == 1
- }
+
+ for node in result_tree.xpath('.//Node'):
+ if napalm_base.helpers.find_txt(node,
+ 'Naming/NodeName/Slot') == active_modules['RSP'][0]:
+ available_ram = napalm_base.helpers.convert(
+ int, napalm_base.helpers.find_txt(node, 'Summary/SystemRAMMemory'))
+ free_ram = napalm_base.helpers.convert(
+ int, napalm_base.helpers.find_txt(node, 'Summary/FreeApplicationMemory'))
+ break # we're only looking at one of the RSP's
+
+ if available_ram and free_ram:
+ used_ram = available_ram - free_ram
+ memory = {}
+ memory['available_ram'] = available_ram
+ memory['used_ram'] = used_ram
+ environment_status['memory'] = memory
+
+ #
+ # Fans
+ #
+
+ for fan in active_modules['FT']:
+ rpc_command = get_module_xml_query(fan, '')
+ result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))
+ for module in result_tree.xpath('.//Module'):
+ for sensortype in module.xpath('.//SensorType'):
+ for sensorname in sensortype.xpath('.//SensorNameTable'):
+ if napalm_base.helpers.find_txt(sensorname,
+ 'SensorName/Naming/Name') == "host__FanSpeed_0":
+ environment_status['fans'][fan] = {
+ 'status': napalm_base.helpers.convert(
+ int, napalm_base.helpers.find_txt(sensorname,
+ 'SensorName/ValueDetailed/Status')
+ ) == 1
+ }
#
# CPU
@@ -549,25 +564,26 @@ class IOSXRDriver(NetworkDriver):
for category, slot in active_modules.iteritems():
slot_list |= set(slot)
- for slot in slot_list:
- rpc_command = get_module_xml_query(slot, '')
- result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))
- for sensor in result_tree.xpath(".//SensorName"):
- if not napalm_base.helpers.find_txt(sensor, 'Naming/Name') == "host__Inlet0":
- continue
- this_reading = {}
- this_reading['temperature'] = napalm_base.helpers.convert(
- float, napalm_base.helpers.find_txt(sensor, 'ValueBrief'))
- threshold_value = [
- napalm_base.helpers.convert(float, x.text)
- for x in sensor.xpath("ThresholdTable/Threshold/ValueBrief")
- ]
- this_reading['is_alert'] = \
- threshold_value[2] <= this_reading['temperature'] <= threshold_value[3]
- this_reading['is_critical'] = \
- threshold_value[4] <= this_reading['temperature'] <= threshold_value[5]
- this_reading['temperature'] = this_reading['temperature']/10
- environment_status["temperature"][slot] = this_reading
+ if not is_xrv:
+ for slot in slot_list:
+ rpc_command = get_module_xml_query(slot, '')
+ result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))
+ for sensor in result_tree.xpath(".//SensorName"):
+ if not napalm_base.helpers.find_txt(sensor, 'Naming/Name') == "host__Inlet0":
+ continue
+ this_reading = {}
+ this_reading['temperature'] = napalm_base.helpers.convert(
+ float, napalm_base.helpers.find_txt(sensor, 'ValueBrief'))
+ threshold_value = [
+ napalm_base.helpers.convert(float, x.text)
+ for x in sensor.xpath("ThresholdTable/Threshold/ValueBrief")
+ ]
+ this_reading['is_alert'] = \
+ threshold_value[2] <= this_reading['temperature'] <= threshold_value[3]
+ this_reading['is_critical'] = \
+ threshold_value[4] <= this_reading['temperature'] <= threshold_value[5]
+ this_reading['temperature'] = this_reading['temperature']/10
+ environment_status["temperature"][slot] = this_reading
return environment_status
@@ -635,7 +651,7 @@ class IOSXRDriver(NetworkDriver):
return lldp_neighbors
- def cli(self, commands=None):
+ def cli(self, commands):
cli_output = {}
@@ -1189,7 +1205,7 @@ class IOSXRDriver(NetworkDriver):
return mac_table
- def get_route_to(self, destination=None, protocol=None):
+ def get_route_to(self, destination='', protocol=''):
routes = {}
@@ -1223,11 +1239,14 @@ class IOSXRDriver(NetworkDriver):
routes_tree = ETREE.fromstring(self.device.make_rpc_call(route_info_rpc_command))
for route in routes_tree.xpath('.//Route'):
+ route_protocol = napalm_base.helpers.convert(
+ unicode, napalm_base.helpers.find_txt(route, 'ProtocolName').upper())
+ if route_protocol.lower() != protocol:
+ continue # ignore routes learned via a different protocol
route_details = {}
address = napalm_base.helpers.find_txt(route, 'Prefix')
length = napalm_base.helpers.find_txt(route, 'PrefixLength')
- protocol = napalm_base.helpers.convert(
- unicode, napalm_base.helpers.find_txt(route, 'ProtocolName').upper())
+
priority = napalm_base.helpers.convert(
int, napalm_base.helpers.find_txt(route, 'Priority'))
age = napalm_base.helpers.convert(
@@ -1247,7 +1266,7 @@ class IOSXRDriver(NetworkDriver):
'last_active': False,
'age': age,
'next_hop': u'',
- 'protocol': protocol,
+ 'protocol': route_protocol,
'outgoing_interface': u'',
'preference': priority,
'selected_next_hop': False,
@@ -1271,58 +1290,59 @@ class IOSXRDriver(NetworkDriver):
bgp_route_tree = ETREE.fromstring(
self.device.make_rpc_call(bgp_route_info_rpc_command))
for bgp_path in bgp_route_tree.xpath('.//Path'):
- best_path = eval(napalm_base.helpers.find_txt(
- bgp_path, 'PathInformation/IsBestPath', 'false').title())
- local_preference = napalm_base.helpers.convert(
- int,
- napalm_base.helpers.find_txt(
- bgp_path,
- 'AttributesAfterPolicyIn/CommonAttributes/LocalPreference'
- ),
- 0
- )
- local_preference = napalm_base.helpers.convert(
- int,
- napalm_base.helpers.find_txt(
- bgp_path,
- 'AttributesAfterPolicyIn/CommonAttributes/LocalPreference',
- ),
- 0
- )
- remote_as = napalm_base.helpers.convert(
- int,
- napalm_base.helpers.find_txt(
- bgp_path,
- 'AttributesAfterPolicyIn/CommonAttributes/NeighborAS',
- ),
- 0
- )
- remote_address = napalm_base.helpers.ip(
- napalm_base.helpers.find_txt(
- bgp_path, 'PathInformation/NeighborAddress/IPV4Address') or
- napalm_base.helpers.find_txt(
- bgp_path, 'PathInformation/NeighborAddress/IPV6Address')
- )
- as_path = ' '.join(
- [
- bgp_as.text
- for bgp_as in bgp_path.xpath(
- 'AttributesAfterPolicyIn/CommonAttributes/NeighborAS/Entry')
- ]
- )
- next_hop = napalm_base.helpers.find_txt(
- bgp_path, 'PathInformation/NextHop/IPV4Address') \
- or napalm_base.helpers.find_txt(
- bgp_path, 'PathInformation/NextHop/IPV6Address')
single_route_details = route_details.copy()
- single_route_details['current_active'] = best_path
- single_route_details['next_hop'] = next_hop
- single_route_details['protocol_attributes'] = {
- 'local_preference': local_preference,
- 'as_path': as_path,
- 'remote_as': remote_as,
- 'remote_address': remote_address
- }
+ if 'NotFound' not in bgp_path.keys():
+ best_path = eval(napalm_base.helpers.find_txt(
+ bgp_path, 'PathInformation/IsBestPath', 'false').title())
+ local_preference = napalm_base.helpers.convert(
+ int,
+ napalm_base.helpers.find_txt(
+ bgp_path,
+ 'AttributesAfterPolicyIn/CommonAttributes/LocalPreference'
+ ),
+ 0
+ )
+ local_preference = napalm_base.helpers.convert(
+ int,
+ napalm_base.helpers.find_txt(
+ bgp_path,
+ 'AttributesAfterPolicyIn/CommonAttributes/LocalPreference',
+ ),
+ 0
+ )
+ remote_as = napalm_base.helpers.convert(
+ int,
+ napalm_base.helpers.find_txt(
+ bgp_path,
+ 'AttributesAfterPolicyIn/CommonAttributes/NeighborAS',
+ ),
+ 0
+ )
+ remote_address = napalm_base.helpers.ip(
+ napalm_base.helpers.find_txt(
+ bgp_path, 'PathInformation/NeighborAddress/IPV4Address') or
+ napalm_base.helpers.find_txt(
+ bgp_path, 'PathInformation/NeighborAddress/IPV6Address')
+ )
+ as_path = ' '.join(
+ [
+ bgp_as.text
+ for bgp_as in bgp_path.xpath(
+ 'AttributesAfterPolicyIn/CommonAttributes/NeighborAS/Entry')
+ ]
+ )
+ next_hop = napalm_base.helpers.find_txt(
+ bgp_path, 'PathInformation/NextHop/IPV4Address') \
+ or napalm_base.helpers.find_txt(
+ bgp_path, 'PathInformation/NextHop/IPV6Address')
+ single_route_details['current_active'] = best_path
+ single_route_details['next_hop'] = next_hop
+ single_route_details['protocol_attributes'] = {
+ 'local_preference': local_preference,
+ 'as_path': as_path,
+ 'remote_as': remote_as,
+ 'remote_address': remote_address
+ }
routes[destination].append(single_route_details)
else:
@@ -1533,7 +1553,11 @@ class IOSXRDriver(NetworkDriver):
return sla_results
- def traceroute(self, destination, source='', ttl=0, timeout=0):
+ def traceroute(self,
+ destination,
+ source=C.TRACEROUTE_SOURCE,
+ ttl=C.TRACEROUTE_TTL,
+ timeout=C.TRACEROUTE_TIMEOUT):
traceroute_result = {}
diff --git a/napalm_iosxr/templates/delete_ntp_servers.j2 b/napalm_iosxr/templates/delete_ntp_servers.j2
new file mode 100644
index 0000000..38accdf
--- /dev/null
+++ b/napalm_iosxr/templates/delete_ntp_servers.j2
@@ -0,0 +1,3 @@
+{% for server in servers %}
+no ntp server {{server}}
+{% endfor %}
diff --git a/napalm_iosxr/templates/delete_snmp_config.j2 b/napalm_iosxr/templates/delete_snmp_config.j2
new file mode 100644
index 0000000..0543dfe
--- /dev/null
+++ b/napalm_iosxr/templates/delete_snmp_config.j2
@@ -0,0 +1,14 @@
+{% if (location is defined) and location %}
+no snmp-server location "{{location}}"
+{% endif %}
+{% if (contact is defined) and contact %}
+no snmp-server contact "{{contact}}"
+{% endif %}
+{% if (chassis_id is defined) and chassis_id %}
+no snmp-server chassis-id "{{chassis_id}}"
+{% endif %}
+{% if (community is defined) and community %}
+{% for comm_name, comm_details in community.iteritems() %}
+no community {{comm_name}}
+{% endfor %}
+{% endif %}
diff --git a/napalm_iosxr/templates/set_ntp_servers.j2 b/napalm_iosxr/templates/set_ntp_servers.j2
new file mode 100644
index 0000000..1cebc15
--- /dev/null
+++ b/napalm_iosxr/templates/set_ntp_servers.j2
@@ -0,0 +1,3 @@
+{% for server in servers %}
+ntp server {{server}}
+{% endfor %}
diff --git a/napalm_iosxr/templates/snmp_config.j2 b/napalm_iosxr/templates/snmp_config.j2
new file mode 100644
index 0000000..b75e5d1
--- /dev/null
+++ b/napalm_iosxr/templates/snmp_config.j2
@@ -0,0 +1,23 @@
+{% if (location is defined) and location %}
+snmp-server location "{{location}}"
+{% endif %}
+{% if (contact is defined) and contact %}
+snmp-server contact "{{contact}}"
+{% endif %}
+{% if (chassis_id is defined) and chassis_id %}
+snmp-server chassis-id "{{chassis_id}}"
+{% endif %}
+{% if (community is defined) and community %}
+{% for comm_name, comm_details in community.iteritems() %}
+{% if (comm_details is defined) and comm_details %}
+{% if (comm_details.get('mode') is defined) and comm_details.get('mode') == 'rw' %}
+community {{comm_name}} RW
+{% else %}
+community {{comm_name}} RO
+{% endif %}
+{% else %}
+community {{comm_name}} RO
+{% endif %}
+{% endfor %}
+{% endif %}
+
diff --git a/setup.cfg b/setup.cfg
index 1757eff..b18e827 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,6 +5,11 @@ ignore = D203,C901,E128
[pylama:pep8]
max_line_length = 100
+[tool:pytest]
+addopts = --cov=./ -vs
+json_report = report.json
+jsonapi = true
+
[egg_info]
tag_build =
tag_date = 0
diff --git a/setup.py b/setup.py
index ea9a91f..0a28f35 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ reqs = [str(ir.req) for ir in install_reqs]
setup(
name="napalm-iosxr",
- version="0.3.2",
+ version="0.4.2",
packages=find_packages(),
author="David Barroso, Mircea Ulinic",
author_email="dbarrosop at dravetech.com, mircea at cloudflare.com",
diff --git a/test/unit/conftest.py b/test/unit/conftest.py
new file mode 100644
index 0000000..3b948c3
--- /dev/null
+++ b/test/unit/conftest.py
@@ -0,0 +1,74 @@
+"""Test fixtures."""
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from builtins import super
+
+import pytest
+from napalm_base.test import conftest as parent_conftest
+
+from napalm_base.test.double import BaseTestDouble
+
+from napalm_iosxr import iosxr
+
+
+ at pytest.fixture(scope='class')
+def set_device_parameters(request):
+ """Set up the class."""
+ def fin():
+ request.cls.device.close()
+ request.addfinalizer(fin)
+
+ request.cls.driver = iosxr.IOSXRDriver
+ request.cls.patched_driver = PatchedIOSXRDriver
+ request.cls.vendor = 'iosxr'
+ parent_conftest.set_device_parameters(request)
+
+
+def pytest_generate_tests(metafunc):
+ """Generate test cases dynamically."""
+ parent_conftest.pytest_generate_tests(metafunc, __file__)
+
+
+class PatchedIOSXRDriver(iosxr.IOSXRDriver):
+ """Patched IOS Driver."""
+
+ def __init__(self, hostname, username, password, timeout=60, optional_args=None):
+
+ super().__init__(hostname, username, password, timeout, optional_args)
+
+ self.patched_attrs = ['device']
+ self.device = FakeIOSXRDevice()
+
+ def is_alive(self):
+ return {
+ 'is_alive': True # In testing everything works..
+ }
+
+ def open(self):
+ pass
+
+
+class FakeIOSXRDevice(BaseTestDouble):
+ """IOSXR device test double."""
+
+ def close(self):
+ pass
+
+ def make_rpc_call(self, rpc_call):
+ filename = '{}.txt'.format(self.sanitize_text(rpc_call))
+ full_path = self.find_file(filename)
+ result = self.read_txt_file(full_path)
+ return result
+
+ def show_lldp_neighbors(self):
+ filename = 'show_lldp_neighbors.txt'
+ full_path = self.find_file(filename)
+ result = self.read_txt_file(full_path)
+ return result
+
+ def _execute_config_show(self, show_command):
+ rpc_request = '<CLI><Configuration>{show_command}</Configuration></CLI>'.format(
+ show_command=show_command
+ )
+ return self.make_rpc_call(rpc_request)
diff --git a/test/unit/test_getters.py b/test/unit/test_getters.py
new file mode 100644
index 0000000..6156b91
--- /dev/null
+++ b/test/unit/test_getters.py
@@ -0,0 +1,13 @@
+"""Tests for getters."""
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from napalm_base.test.getters import BaseTestGetters
+
+
+import pytest
+
+
+ at pytest.mark.usefixtures("set_device_parameters")
+class TestGetter(BaseTestGetters):
+ """Test get_* methods."""
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/napalm-iosxr.git
More information about the Python-modules-commits
mailing list