mirror of
https://github.com/napalm-automation-community/napalm-vyos.git
synced 2026-08-22 22:25:13 +00:00
changes in mock tests
This commit is contained in:
@@ -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,34 +37,25 @@ class PatchedVyOSDriver(vyos.VyOSDriver):
|
||||
|
||||
self.patched_attrs = ['device']
|
||||
self.device = FakeVyOSDevice()
|
||||
self._device = FakeVyOSDevice()
|
||||
|
||||
def disconnect(self):
|
||||
pass
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def is_alive(self):
|
||||
return {
|
||||
'is_alive': True # In testing everything works..
|
||||
}
|
||||
|
||||
def open(self):
|
||||
pass
|
||||
def is_alive(self):
|
||||
return {
|
||||
'is_alive': True # In testing everything works..
|
||||
}
|
||||
|
||||
def open(self):
|
||||
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)
|
||||
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
|
||||
def send_command(self, command, **kwargs):
|
||||
filename = '{}.text'.format(self.sanitize_text(command))
|
||||
full_path = self.find_file(filename)
|
||||
result = self.read_txt_file(full_path)
|
||||
return py23_compat.text_type(result)
|
||||
|
||||
@@ -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": "..."}}}}}}
|
||||
|
||||
@@ -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": "..."}}
|
||||
|
||||
@@ -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}}}}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"is_alive": true}
|
||||
Reference in New Issue
Block a user