Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
Added pytest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ogenstad committed Dec 2, 2016
1 parent b6c386f commit 79a5755
Show file tree
Hide file tree
Showing 63 changed files with 1,964 additions and 20 deletions.
24 changes: 4 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@ deploy:
tags: true
branch: master
script:
- py.test --cov-report= --cov=napalm_ios test/
- pylama .
- cd test/unit
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_arp_table
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_bgp_neighbors
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_environment
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_facts
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_interfaces
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_interfaces_counters
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_interfaces_ip
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_lldp_neighbors
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_lldp_neighbors_detail
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_mac_address_table
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_ntp_servers
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_ntp_stats
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_snmp_information
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_ios_only_bgp_time_conversion
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_ping
- nosetests --with-coverage --cover-package napalm_ios -v TestIOSDriver:TestGetterIOSDriver.test_get_config
- cd ../..
- coverage combine test/unit/.coverage
after_success: coveralls
after_success:
- coveralls
- if [ $TRAVIS_TAG ]; then curl -X POST https://readthedocs.org/build/napalm; fi
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
future
coveralls
pytest
pytest-cov
Expand Down
66 changes: 66 additions & 0 deletions test/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""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_base.utils import py23_compat

from napalm_ios import ios


@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 = ios.IOSDriver
request.cls.patched_driver = PatchedIOSDriver
request.cls.vendor = 'ios'
parent_conftest.set_device_parameters(request)


def pytest_generate_tests(metafunc):
"""Generate test cases dynamically."""
parent_conftest.pytest_generate_tests(metafunc, __file__)


class PatchedIOSDriver(ios.IOSDriver):
"""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 = FakeIOSDevice()

def disconnect(self):
pass

def is_alive(self):
return {
'is_alive': True # In testing everything works..
}

def open(self):
pass


class FakeIOSDevice(BaseTestDouble):
"""IOS device test double."""

def send_command(self, command):
filename = '{}.txt'.format(self.sanitize_text(command))
full_path = self.find_file(filename)
result = self.read_txt_file(full_path)
return py23_compat.text_type(result)

def disconnect(self):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[{
"interface": "Vlan20",
"ip": "172.29.50.1",
"mac": "84b8.0276.ac0e",
"age": 8.0
}, {
"interface": "Vlan20",
"ip": "172.29.50.2",
"mac": "0019.0725.344a",
"age": 221.0
}, {
"interface": "Vlan20",
"ip": "172.29.50.3",
"mac": "0024.f7dd.7741",
"age": 0.0
}, {
"interface": "Vlan20",
"ip": "172.29.50.10",
"mac": "6805.ca12.71c2",
"age": 37.0
}, {
"interface": "Vlan41",
"ip": "172.29.52.33",
"mac": "84b8.0276.ac0e",
"age": 61.0
}, {
"interface": "Vlan41",
"ip": "172.29.52.34",
"mac": "0024.f7dd.7743",
"age": 0.0
}, {
"interface": "Vlan41",
"ip": "172.29.52.40",
"mac": "a099.9b1c.dfa7",
"age": 3.0
}, {
"interface": "Vlan41",
"ip": "192.168.81.34",
"mac": "0024.f7dd.7743",
"age": 0.0
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Protocol Address Age (min) Hardware Addr Type Interface
Internet 172.29.50.1 8 84b8.0276.ac0e ARPA Vlan20
Internet 172.29.50.2 221 0019.0725.344a ARPA Vlan20
Internet 172.29.50.3 - 0024.f7dd.7741 ARPA Vlan20
Internet 172.29.50.10 37 6805.ca12.71c2 ARPA Vlan20
Internet 172.29.52.33 61 84b8.0276.ac0e ARPA Vlan41
Internet 172.29.52.34 - 0024.f7dd.7743 ARPA Vlan41
Internet 172.29.52.40 3 a099.9b1c.dfa7 ARPA Vlan41
Internet 192.168.81.34 - 0024.f7dd.7743 ARPA Vlan41
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"global": {"router_id": "192.168.0.1", "peers": {"192.168.0.2": {"is_enabled": true, "uptime": -1, "remote_as": 65001, "description": "", "remote_id": "0.0.0.0", "local_as": 65000, "is_up": false, "address_family": {"ipv4": {"sent_prefixes": 0, "accepted_prefixes": 0, "received_prefixes": 0} }}, "192.168.0.3": {"is_enabled": true, "uptime": -1, "remote_as": 65010, "description": "", "remote_id": "192.168.0.3", "local_as": 65000, "is_up": false, "address_family": {"ipv4": {"sent_prefixes": 0, "accepted_prefixes": 0, "received_prefixes": 0} }}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prefixes Current: 0 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BGP version 4, remote router ID 0.0.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Local Policy Denied Prefixes: -------- -------
Total: 0 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prefixes Current: 0 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BGP version 4, remote router ID 192.168.0.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Local Policy Denied Prefixes: -------- -------
Total: 0 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BGP router identifier 192.168.0.1, local AS number 65000
BGP table version is 1, main routing table version 1

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.0.2 4 65001 0 0 1 0 0 never Idle
192.168.0.3 4 65010 0 0 1 0 0 never Active
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.0.2 4 65001 0 0 1 0 0 never Idle
192.168.0.3 4 65010 0 0 1 0 0 never Active
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"startup": "!\n! Last configuration change at 18:41:02 UTC Thu Nov 24 2016\n!\nversion 15.5\nservice timestamps debug datetime msec\nservice timestamps log datetime msec\nno platform punt-keepalive disable-kernel-core\nplatform console auto\n!\nhostname CSR1\n!\nboot-start-marker\nboot-end-marker\n!\n!\nenable password cisco\n!\naaa new-model\n!\n!\naaa authentication login default local\naaa authorization exec default local\n!\n!\n!\n!\n!\naaa session-id common\n!\nip vrf MGMT\n!\n!\n!\n!\n!\n!\n!\n!\n!\n\n\nip domain name example.local\n\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nsubscriber templating\n!\nmultilink bundle-name authenticated\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nlicense udi pid CSR1000V sn 9OSEGKJXRHE\nspanning-tree extend system-id\n!\nusername cisco privilege 15 password 0 cisco\n!\nredundancy\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\ninterface Loopback0\n ip address 1.1.1.1 255.255.255.255\n!\ninterface GigabitEthernet1\n ip vrf forwarding MGMT\n ip address 192.168.35.121 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet2\n ip address 10.1.1.1 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet3\n no ip address\n shutdown\n negotiation auto\n!\nrouter ospf 1\n redistribute connected subnets\n network 10.1.1.0 0.0.0.255 area 0\n!\n!\nvirtual-service csr_mgmt\n!\nip forward-protocol nd\n!\nno ip http server\nno ip http secure-server\n!\n!\n!\n!\n!\n!\ncontrol-plane\n!\n !\n !\n !\n !\n!\n!\n!\n!\n!\nline con 0\nline vty 0 4\n!\n!\nend",
"running": "Building configuration...\n\nCurrent configuration : 1366 bytes\n!\n! Last configuration change at 18:41:02 UTC Thu Nov 24 2016\n!\nversion 15.5\nservice timestamps debug datetime msec\nservice timestamps log datetime msec\nno platform punt-keepalive disable-kernel-core\nplatform console auto\n!\nhostname CSR1\n!\nboot-start-marker\nboot-end-marker\n!\n!\nenable password cisco\n!\naaa new-model\n!\n!\naaa authentication login default local\naaa authorization exec default local\n!\n!\n!\n!\n!\naaa session-id common\n!\nip vrf MGMT\n!\n!\n!\n!\n!\n!\n!\n!\n!\n\n\nip domain name example.local\n\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nsubscriber templating\n!\nmultilink bundle-name authenticated\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nlicense udi pid CSR1000V sn 9OSEGKJXRHE\nspanning-tree extend system-id\n!\nusername cisco privilege 15 password 0 cisco\n!\nredundancy\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\ninterface Loopback0\n ip address 1.1.1.1 255.255.255.255\n!\ninterface GigabitEthernet1\n ip vrf forwarding MGMT\n ip address 192.168.35.121 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet2\n ip address 10.1.1.1 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet3\n no ip address\n shutdown\n negotiation auto\n!\nrouter ospf 1\n redistribute connected subnets\n network 10.1.1.0 0.0.0.255 area 0\n!\n!\nvirtual-service csr_mgmt\n!\nip forward-protocol nd\n!\nno ip http server\nno ip http secure-server\n!\n!\n!\n!\n!\n!\ncontrol-plane\n!\n !\n !\n !\n !\n!\n!\n!\n!\n!\nline con 0\nline vty 0 4\n!\n!\nend",
"candidate": ""
}
151 changes: 151 additions & 0 deletions test/unit/mocked_data/test_get_config/normal/show_running_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
Building configuration...

Current configuration : 1366 bytes
!
! Last configuration change at 18:41:02 UTC Thu Nov 24 2016
!
version 15.5
service timestamps debug datetime msec
service timestamps log datetime msec
no platform punt-keepalive disable-kernel-core
platform console auto
!
hostname CSR1
!
boot-start-marker
boot-end-marker
!
!
enable password cisco
!
aaa new-model
!
!
aaa authentication login default local
aaa authorization exec default local
!
!
!
!
!
aaa session-id common
!
ip vrf MGMT
!
!
!
!
!
!
!
!
!


ip domain name example.local

!
!
!
!
!
!
!
!
!
!
subscriber templating
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
license udi pid CSR1000V sn 9OSEGKJXRHE
spanning-tree extend system-id
!
username cisco privilege 15 password 0 cisco
!
redundancy
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface Loopback0
ip address 1.1.1.1 255.255.255.255
!
interface GigabitEthernet1
ip vrf forwarding MGMT
ip address 192.168.35.121 255.255.255.0
negotiation auto
!
interface GigabitEthernet2
ip address 10.1.1.1 255.255.255.0
negotiation auto
!
interface GigabitEthernet3
no ip address
shutdown
negotiation auto
!
router ospf 1
redistribute connected subnets
network 10.1.1.0 0.0.0.255 area 0
!
!
virtual-service csr_mgmt
!
ip forward-protocol nd
!
no ip http server
no ip http secure-server
!
!
!
!
!
!
control-plane
!
!
!
!
!
!
!
!
!
!
line con 0
line vty 0 4
!
!
end
Loading

0 comments on commit 79a5755

Please sign in to comment.