-
Notifications
You must be signed in to change notification settings - Fork 46
/
test_plugin_slxos.py
75 lines (61 loc) · 2.68 KB
/
test_plugin_slxos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'''
Author: Fabio Pessoa Nunes
Contact: https://www.linkedin.com/in/fpessoanunes/
'''
import os
import yaml
import unittest
from unittest.mock import patch
from unicon import Connection
from unicon.mock.mock_device import mockdata_path
with open(os.path.join(mockdata_path, 'slxos/slxos_mock_data.yaml'), 'rb') as datafile:
mock_data = yaml.safe_load(datafile.read())
class TestSlxosPluginConnect(unittest.TestCase):
def test_login_connect_ssh(self):
hostname = "SLX"
c = Connection(hostname=hostname,
start=['mock_device_cli --os slxos --state connect_ssh --hostname {hostname}'
.format(hostname=hostname)],
os='slxos',
credentials={'default': {'username': 'admin','password': 'password'}})
c.connect()
self.assertIn("{hostname}#".format(hostname=hostname), c.spawn.match.match_output)
c.disconnect()
class TestSlxosPluginExecute(unittest.TestCase):
def test_execute_show_feature(self):
hostname = "SLX"
c = Connection(hostname=hostname,
start=['mock_device_cli --os slxos --state exec --hostname {hostname}'
.format(hostname=hostname)],
os='slxos',
credentials={'default': {'username': 'admin','password': 'password'}},
init_exec_commands=[],
init_config_commands=[]
)
c.connect()
cmd = 'show ip interface brief'
expected_response = mock_data['exec']['commands'][cmd].strip()
ret = c.execute(cmd).replace('\r', '')
self.assertIn(expected_response, ret)
c.disconnect()
class TestSlxosPluginConfigure(unittest.TestCase):
def test_execute_configure(self):
hostname = "SLX"
c = Connection(hostname=hostname,
start=['mock_device_cli --os slxos --state exec --hostname {hostname}'
.format(hostname=hostname)],
os='slxos',
credentials={'default': {'username': 'admin','password': 'password'}},
init_exec_commands=[],
init_config_commands=[]
)
c.connect()
cmd = 'configure'
c.execute(cmd).replace('\r', '')
self.assertIn("{hostname}(config)#".format(hostname=hostname), c.spawn.match.match_output)
cmd = 'end'
c.execute(cmd).replace('\r', '')
self.assertIn("{hostname}#".format(hostname=hostname), c.spawn.match.match_output)
c.disconnect()
if __name__ == "__main__":
unittest.main()