changes in mock tests

This commit is contained in:
Pieprzycki Piotr 2016-12-21 13:03:59 +01:00
parent 37ae8512c0
commit a63df96ade
8 changed files with 136 additions and 117 deletions

View File

@ -1,4 +1,3 @@
David Barroso <dbarrosop@dravetech.com>
Elisa Jasinska <elisa@bigwaveit.org>
Shota Muto
Shota Muto <dos9954@gmail.com>
Piotr Pieprzycki <piotr.pieprzycki@dreamlab.pl>
David Barroso <dbarrosop@dravetech.com>

View File

@ -198,8 +198,16 @@ class VyOSDriver(NetworkDriver):
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 61404 139624 139360 0 0 0 0 9 14 0 0 100 0
"""
output_cpu = self._device.send_command("vmstat").split("\n")[-1]
cpu = 100 - int(output_cpu.split()[-2])
output_cpu_list = list()
output_cpu = self._device.send_command("vmstat")
output_cpu = str(output_cpu)
output_cpu_list = output_cpu.split("\n")
if len(output_cpu_list[-1]) > 0:
output_cpu_list = output_cpu_list[-1]
else:
output_cpu_list = output_cpu_list[-2]
output_cpu_idle = output_cpu_list.split()[-2]
cpu = 100 - int(output_cpu_idle)
"""
'free' output:
@ -365,11 +373,12 @@ class VyOSDriver(NetworkDriver):
133.130.120.204 133.243.238.164 2 u 46 64 377 7.717 987996. 1669.77
"""
output = self._device.send_command("ntpq -np").split("\n")[2:]
output = self._device.send_command("ntpq -np")
output = output.split("\n")[2:]
ntp_stats = list()
for ntp_info in output:
if len(ntp_info) > 0:
remote, refid, st, t, when, hostpoll, reachability, delay, offset, \
jitter = ntp_info.split()
@ -398,11 +407,12 @@ class VyOSDriver(NetworkDriver):
return ntp_stats
def get_ntp_peers(self):
output = self._device.send_command("ntpq -np").split("\n")[2:]
output = self._device.send_command("ntpq -np")
output_peers = output.split("\n")[2:]
ntp_peers = dict()
for line in output:
for line in output_peers:
if len(line) > 0:
match = re.search("(\d+\.\d+\.\d+\.\d+)\s+", line)
ntp_peers.update({
unicode(match.group(1)): {}
@ -426,7 +436,8 @@ class VyOSDriver(NetworkDriver):
192.168.1.4 4 64522 0 0 0 0 0 never Active
"""
output = self._device.send_command("show ip bgp summary").split("\n")
output = self._device.send_command("show ip bgp summary")
output = output.split("\n")
match = re.search(".* router identifier (\d+\.\d+\.\d+\.\d+), local AS number (\d+)",
output[0])
@ -444,6 +455,7 @@ class VyOSDriver(NetworkDriver):
bgp_info = [i.strip() for i in output[6:-2] if i is not ""]
for i in bgp_info:
if len(i) > 0:
peer_id, bgp_version, remote_as, msg_rcvd, msg_sent, table_version, \
in_queue, out_queue, up_time, state_prefix = i.split()
@ -553,8 +565,10 @@ class VyOSDriver(NetworkDriver):
"""
output = self._device.send_command("show interfaces detail")
interfaces = re.findall("(\S+): <.*", output)
count = re.findall("(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+", output)
# count = re.findall("(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+", output)
count = re.findall("(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)", output)
counters = dict()
j = 0
for i in count:
@ -681,13 +695,15 @@ class VyOSDriver(NetworkDriver):
output = output.split("\n")
# delete the header line and the interfaces which has no ip address
if len(output[-1]) > 0:
ifaces = [x for x in output[3:] if "-" not in x]
else:
ifaces = [x for x in output[3:-1] if "-" not in x]
ifaces_ip = dict()
for iface in ifaces:
iface = iface.split()
if len(iface) != 1:
iface_name = iface[0]
@ -782,7 +798,12 @@ class VyOSDriver(NetworkDriver):
# 'packet_info' example:
# ['5', 'packets', 'transmitted,' '5', 'received,' '0%', 'packet',
# 'loss,', 'time', '3997ms']
packet_info = output_ping.split("\n")[-2]
packet_info = output_ping.split("\n")
if len(packet_info[-1]) > 0:
packet_info = packet_info[-2]
else:
packet_info = packet_info[-3]
packet_info = [x.strip() for x in packet_info.split()]
@ -792,7 +813,13 @@ class VyOSDriver(NetworkDriver):
# 'rtt_info' example:
# ["0.307/0.396/0.480/0.061"]
rtt_info = output_ping.split("\n")[-1]
rtt_info = output_ping.split("\n")
if len(rtt_info[-1]) > 0:
rtt_info = rtt_info[-1]
else:
rtt_info = rtt_info[-2]
match = re.search("([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+)", rtt_info)
if match is not None:

View File

@ -14,8 +14,8 @@ setup(
name="napalm-vyos",
version="0.1.2",
packages=find_packages(),
author="Piotr Pieprzycki, Shota Muto",
author_email="piotr.pieprzycki@dreamlab.pl, dos9954@gmail.com",
author="Piotr Pieprzycki",
author_email="piotr.pieprzycki@dreamlab.pl",
description="Network Automation and Programmability Abstraction Layer with Multivendor support",
classifiers=[
'Topic :: Utilities',

View File

@ -5,6 +5,7 @@ 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_vyos import vyos
@ -36,8 +37,9 @@ class PatchedVyOSDriver(vyos.VyOSDriver):
self.patched_attrs = ['device']
self.device = FakeVyOSDevice()
self._device = FakeVyOSDevice()
def disconnect(self):
def close(self):
pass
def is_alive(self):
@ -49,21 +51,11 @@ class PatchedVyOSDriver(vyos.VyOSDriver):
pass
class FakeVyOSDevice(BaseTestDouble):
"""VyOS device test double."""
def run_commands(self, command_list, encoding='json'):
"""Fake run_commands."""
result = list()
for command in command_list:
filename = '{}.{}'.format(self.sanitize_text(command), encoding)
def send_command(self, command, **kwargs):
filename = '{}.text'.format(self.sanitize_text(command))
full_path = self.find_file(filename)
if encoding == 'json':
result.append(self.read_json_file(full_path))
else:
result.append({'output': self.read_txt_file(full_path)})
return result
result = self.read_txt_file(full_path)
return py23_compat.text_type(result)

View File

@ -1 +1 @@
{"global": {"router_id": "...", "peers": {"10.0.1.100": {"is_enabled": true, "uptime": "...", "remote_as": 65001, "description": "", "remote_id": "...", "local_as": 65002, "is_up": "...", "address_family": {"ipv4": {"sent_prefixes": -1, "accepted_prefixes": "...", "received_prefixes": "..."}}}}}}
{"global": {"router_id": "...", "peers": {"10.0.1.100": {"is_enabled": true, "uptime": "...", "remote_as": 65001, "description": "", "remote_id": "...", "local_as": 65002, "is_up": true, "address_family": {"ipv4": {"sent_prefixes": -1, "accepted_prefixes": "...", "received_prefixes": "..."}}}}}}

View File

@ -1 +1 @@
{"eth1": {"tx_discards": 0, "tx_unicast_packets": "...", "rx_broadcast_packets": -1, "rx_discards": 0, "tx_multicast_packets": -1, "tx_octets": "...", "tx_errors": 0, "rx_octets": "...", "rx_errors": 0, "tx_broadcast_packets": -1, "rx_multicast_packets": "...", "rx_unicast_packets": "..."}, "eth0": {"tx_discards": 0, "tx_unicast_packets": "...", "rx_broadcast_packets": -1, "rx_discards": 0, "tx_multicast_packets": -1, "tx_octets": "...", "tx_errors": 0, "rx_octets": "...", "rx_errors": 0, "tx_broadcast_packets": -1, "rx_multicast_packets": "...", "rx_unicast_packets": "..."}, "eth2": {"tx_discards": 0, "tx_unicast_packets": "...", "rx_broadcast_packets": -1, "rx_discards": 0, "tx_multicast_packets": -1, "tx_octets": "...", "tx_errors": 0, "rx_octets": "...", "rx_errors": 0, "tx_broadcast_packets": -1, "rx_multicast_packets": "...", "rx_unicast_packets": "..."}}
{"lo": {"tx_multicast_packets": "...", "tx_discards": "...", "tx_octets": "...", "tx_errors": "...", "rx_octets": "...", "tx_unicast_packets": "...", "rx_errors": "...", "tx_broadcast_packets": "...", "rx_multicast_packets": "...", "rx_broadcast_packets": "...", "rx_discards": "...", "rx_unicast_packets": "..."},"eth1": {"tx_discards": "...", "tx_unicast_packets": "...", "rx_broadcast_packets": "...", "rx_discards": "...", "tx_multicast_packets": "...", "tx_octets": "...", "tx_errors": "...", "rx_octets": "...", "rx_errors": "...", "tx_broadcast_packets": "...", "rx_multicast_packets": "...", "rx_unicast_packets": "..."}, "eth0": {"tx_discards": "...", "tx_unicast_packets": "...", "rx_broadcast_packets": "...", "rx_discards": "...", "tx_multicast_packets": "...", "tx_octets": "...", "tx_errors": "...", "rx_octets": "...", "rx_errors": "...", "tx_broadcast_packets": "...", "rx_multicast_packets": "...", "rx_unicast_packets": "..."}, "eth2": {"tx_discards": "...", "tx_unicast_packets": "...", "rx_broadcast_packets": "...", "rx_discards": "...", "tx_multicast_packets": "...", "tx_octets": "...", "tx_errors": "...", "rx_octets": "...", "rx_errors": "...", "tx_broadcast_packets": "...", "rx_multicast_packets": "...", "rx_unicast_packets": "..."}}

View File

@ -1 +1 @@
{"lo": {"ipv4": {"8.8.8.8": {"prefix_length": 32}, "127.0.0.1": {"prefix_length": 8}, "10.2.2.2": {"prefix_length": 32}}}, "eth1": {"ipv4": {"10.0.1.222": {"prefix_length": 24}}}, "eth0": {"ipv4": {"10.0.2.15": {"prefix_length": 24}}}}
{"lo": {"ipv4": {"8.8.8.8": {"prefix_length": 32}, "127.0.0.1": {"prefix_length": 8}, "10.2.2.2": {"prefix_length": 32}}, "ipv6": {"::1": {"prefix_length": 128}}}, "eth1": {"ipv4": {"10.0.1.222": {"prefix_length": 24}}}, "eth0": {"ipv4": {"10.0.2.15": {"prefix_length": 24}}}}

View File

@ -0,0 +1 @@
{"is_alive": true}