mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
add tests for all the getters
This commit is contained in:
parent
c63222358b
commit
386c4e5791
1 changed files with 195 additions and 1 deletions
|
@ -31,7 +31,128 @@ TEST_ENVIRONMENT = {
|
|||
'hot': 'yes'
|
||||
}
|
||||
|
||||
TEST_COMMAND_RESPONSE = 'all the command output'
|
||||
TEST_COMMAND_RESPONSE = {
|
||||
'show run': 'all the command output'
|
||||
}
|
||||
|
||||
TEST_TRACEROUTE_RESPONSE = {
|
||||
'success': {
|
||||
1: {
|
||||
'probes': {
|
||||
1: {
|
||||
'rtt': 1.123,
|
||||
'ip_address': u'206.223.116.21',
|
||||
'host_name': u'eqixsj-google-gige.google.com'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_PING_RESPONSE = {
|
||||
'success': {
|
||||
'probes_sent': 5,
|
||||
'packet_loss': 0,
|
||||
'rtt_min': 72.158,
|
||||
'rtt_max': 72.433,
|
||||
'rtt_avg': 72.268,
|
||||
'rtt_stddev': 0.094,
|
||||
'results': [
|
||||
{
|
||||
'ip_address': '1.1.1.1',
|
||||
'rtt': 72.248
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
TEST_ARP_TABLE = [
|
||||
{
|
||||
'interface': 'MgmtEth0/RSP0/CPU0/0',
|
||||
'mac': '5C:5E:AB:DA:3C:F0',
|
||||
'ip': '172.17.17.1',
|
||||
'age': 1454496274.84
|
||||
}
|
||||
]
|
||||
|
||||
TEST_IPADDRS = {
|
||||
'FastEthernet8': {
|
||||
'ipv4': {
|
||||
'10.66.43.169': {
|
||||
'prefix_length': 22
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_INTERFACES = {
|
||||
'Management1': {
|
||||
'is_up': False,
|
||||
'is_enabled': False,
|
||||
'description': u'',
|
||||
'last_flapped': -1,
|
||||
'speed': 1000,
|
||||
'mac_address': u'dead:beef:dead',
|
||||
}
|
||||
}
|
||||
|
||||
TEST_LLDP_NEIGHBORS = {
|
||||
u'Ethernet2':
|
||||
[
|
||||
{
|
||||
'hostname': u'junos-unittest',
|
||||
'port': u'520',
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
TEST_MAC_TABLE = [
|
||||
{
|
||||
'mac': '00:1C:58:29:4A:71',
|
||||
'interface': 'Ethernet47',
|
||||
'vlan': 100,
|
||||
'static': False,
|
||||
'active': True,
|
||||
'moves': 1,
|
||||
'last_move': 1454417742.58
|
||||
}
|
||||
]
|
||||
|
||||
TEST_RUNNING_CONFIG = {
|
||||
'one': 'two'
|
||||
}
|
||||
|
||||
TEST_OPTICS = {
|
||||
'et1': {
|
||||
'physical_channels': {
|
||||
'channel': [
|
||||
{
|
||||
'index': 0,
|
||||
'state': {
|
||||
'input_power': {
|
||||
'instant': 0.0,
|
||||
'avg': 0.0,
|
||||
'min': 0.0,
|
||||
'max': 0.0,
|
||||
},
|
||||
'output_power': {
|
||||
'instant': 0.0,
|
||||
'avg': 0.0,
|
||||
'min': 0.0,
|
||||
'max': 0.0,
|
||||
},
|
||||
'laser_bias_current': {
|
||||
'instant': 0.0,
|
||||
'avg': 0.0,
|
||||
'min': 0.0,
|
||||
'max': 0.0,
|
||||
},
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MockNapalmDevice(object):
|
||||
|
@ -42,6 +163,9 @@ class MockNapalmDevice(object):
|
|||
def get_environment(self):
|
||||
return TEST_ENVIRONMENT
|
||||
|
||||
def get_arp_table(self):
|
||||
return TEST_ARP_TABLE
|
||||
|
||||
def get(self, key, default=None, *args, **kwargs):
|
||||
try:
|
||||
if key == 'DRIVER':
|
||||
|
@ -54,6 +178,33 @@ class MockNapalmDevice(object):
|
|||
assert commands[0] == 'show run'
|
||||
return TEST_COMMAND_RESPONSE
|
||||
|
||||
def traceroute(self, destination, **kwargs):
|
||||
assert destination == 'destination.com'
|
||||
return TEST_TRACEROUTE_RESPONSE
|
||||
|
||||
def ping(self, destination, **kwargs):
|
||||
assert destination == 'destination.com'
|
||||
return TEST_PING_RESPONSE
|
||||
|
||||
def get_config(self, retrieve='all'):
|
||||
assert retrieve == 'running'
|
||||
return TEST_RUNNING_CONFIG
|
||||
|
||||
def get_interfaces_ip(self, **kwargs):
|
||||
return TEST_IPADDRS
|
||||
|
||||
def get_interfaces(self, **kwargs):
|
||||
return TEST_INTERFACES
|
||||
|
||||
def get_lldp_neighbors_detail(self, **kwargs):
|
||||
return TEST_LLDP_NEIGHBORS
|
||||
|
||||
def get_mac_address_table(self, **kwargs):
|
||||
return TEST_MAC_TABLE
|
||||
|
||||
def get_optics(self, **kwargs):
|
||||
return TEST_OPTICS
|
||||
|
||||
|
||||
def mock_proxy_napalm_wrap(func):
|
||||
'''
|
||||
|
@ -110,3 +261,46 @@ class NapalmNetworkModuleTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'''
|
||||
ret = napalm_network.cli("show run")
|
||||
assert ret['out'] == TEST_COMMAND_RESPONSE
|
||||
|
||||
def test_cli_multi_command(self):
|
||||
'''
|
||||
Test that CLI works with 2 arg
|
||||
'''
|
||||
ret = napalm_network.cli("show run", "show run")
|
||||
assert ret['out'] == TEST_COMMAND_RESPONSE
|
||||
|
||||
def test_traceroute(self):
|
||||
ret = napalm_network.traceroute('destination.com')
|
||||
assert ret['out'].keys()[0] == 'success'
|
||||
|
||||
def test_ping(self):
|
||||
ret = napalm_network.ping('destination.com')
|
||||
assert ret['out'].keys()[0] == 'success'
|
||||
|
||||
def test_arp(self):
|
||||
ret = napalm_network.arp()
|
||||
assert ret['out'] == TEST_ARP_TABLE
|
||||
|
||||
def test_ipaddrs(self):
|
||||
ret = napalm_network.ipaddrs()
|
||||
assert ret['out'] == TEST_IPADDRS
|
||||
|
||||
def test_interfaces(self):
|
||||
ret = napalm_network.interfaces()
|
||||
assert ret['out'] == TEST_INTERFACES
|
||||
|
||||
def test_lldp(self):
|
||||
ret = napalm_network.lldp()
|
||||
assert ret['out'] == TEST_LLDP_NEIGHBORS
|
||||
|
||||
def test_mac(self):
|
||||
ret = napalm_network.mac()
|
||||
assert ret['out'] == TEST_MAC_TABLE
|
||||
|
||||
def test_config(self):
|
||||
ret = napalm_network.config('running')
|
||||
assert ret['out'] == TEST_RUNNING_CONFIG
|
||||
|
||||
def test_optics(self):
|
||||
ret = napalm_network.optics()
|
||||
assert ret['out'] == TEST_OPTICS
|
||||
|
|
Loading…
Add table
Reference in a new issue