-
Notifications
You must be signed in to change notification settings - Fork 661
/
mpls_test.py
226 lines (196 loc) · 7.01 KB
/
mpls_test.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import os
import importlib
import sys
import traceback
from unittest import mock
from click.testing import CliRunner
from .mock_tables import dbconnector
import config.main as config
import show.main as show
from utilities_common.db import Db
show_interfaces_mpls_output_frontend="""\
Interface MPLS State
----------- ------------
Ethernet0 enable
Ethernet4 enable
Ethernet8 disable
Ethernet12 disable
Ethernet16 disable
Ethernet20 enable
"""
show_interfaces_mpls_masic_output_frontend="""\
Interface MPLS State
----------- ------------
Ethernet0 enable
Ethernet4 disable
"""
show_interfaces_mpls_masic_output_all="""\
Interface MPLS State
-------------- ------------
Ethernet0 enable
Ethernet4 disable
Ethernet64 enable
Ethernet-BP0 enable
Ethernet-BP4 disable
Ethernet-BP256 disable
Ethernet-BP260 enable
"""
show_interfaces_mpls_masic_output_asic_all="""\
Interface MPLS State
------------ ------------
Ethernet0 enable
Ethernet4 disable
Ethernet-BP0 enable
Ethernet-BP4 disable
"""
modules_path = os.path.join(os.path.dirname(__file__), "..")
test_path = os.path.join(modules_path, "tests")
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, modules_path)
mock_db_path = os.path.join(test_path, "mpls_input")
class TestMpls(object):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ['UTILITIES_UNIT_TESTING'] = "1"
jsonfile = os.path.join(mock_db_path, 'appl_db')
dbconnector.dedicated_dbs['APPL_DB'] = jsonfile
def test_config_mpls_add(self):
runner = CliRunner()
db = Db()
obj = {'config_db':db.cfgdb}
result = runner.invoke(
config.config.commands["interface"].commands["mpls"].commands["add"],
["Ethernet8"], obj=obj
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert db.cfgdb.get_entry("INTERFACE", "Ethernet8") == {"mpls": "enable"}
def test_show_interfaces_mpls_frontend(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["interfaces"].commands["mpls"],
["-dfrontend"]
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interfaces_mpls_output_frontend
def test_show_interfaces_mpls(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["interfaces"].commands["mpls"], []
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interfaces_mpls_output_frontend
def test_show_interfaces_mpls_dall(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["interfaces"].commands["mpls"],
["-dall"]
)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interfaces_mpls_output_frontend
def test_config_mpls_remove(self):
runner = CliRunner()
db = Db()
obj = {'config_db':db.cfgdb}
result = runner.invoke(
config.config.commands["interface"].commands["mpls"].commands["remove"],
["Ethernet8"], obj=obj
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert db.cfgdb.get_entry("INTERFACE", "Ethernet8") == {"mpls": "disable"}
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ['UTILITIES_UNIT_TESTING'] = "0"
from .mock_tables import mock_single_asic
importlib.reload(mock_single_asic)
from .mock_tables import dbconnector
dbconnector.load_database_config()
dbconnector.dedicated_dbs['APPL_DB'] = {}
class TestMplsMasic(object):
@classmethod
def setup_class(cls):
print("SETUP")
from .mock_tables import mock_multi_asic
importlib.reload(mock_multi_asic)
from .mock_tables import dbconnector
dbconnector.load_namespace_config()
def test_config_mpls_masic_add(self):
runner = CliRunner()
db = Db()
obj = {'config_db':db.cfgdb, 'namespace':'asic0'}
result = runner.invoke(
config.config.commands["interface"].commands["mpls"].commands["add"],
["Ethernet8"], obj=obj
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert db.cfgdb.get_entry("INTERFACE", "Ethernet8") == {"mpls": "enable"}
def test_show_interfaces_mpls_masic_frontend(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["interfaces"].commands["mpls"],
["-dfrontend"]
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interfaces_mpls_masic_output_frontend
def test_show_interfaces_mpls_masic_all(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["interfaces"].commands["mpls"],
["-dall"]
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interfaces_mpls_masic_output_all
def test_show_interfaces_mpls_masic_asic(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["interfaces"].commands["mpls"],
["-nasic0"]
)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interfaces_mpls_masic_output_frontend
def test_show_interfaces_mpls_masic_asic_all(self):
runner = CliRunner()
result = runner.invoke(
show.cli.commands["interfaces"].commands["mpls"],
["-nasic0", "-dall"]
)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interfaces_mpls_masic_output_asic_all
def test_config_mpls_masic_remove(self):
runner = CliRunner()
db = Db()
obj = {'config_db':db.cfgdb, 'namespace':'asic0'}
result = runner.invoke(
config.config.commands["interface"].commands["mpls"].commands["remove"],
["Ethernet8"], obj=obj
)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert db.cfgdb.get_entry("INTERFACE", "Ethernet8") == {"mpls": "disable"}
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ['UTILITIES_UNIT_TESTING'] = "0"
from .mock_tables import mock_single_asic
importlib.reload(mock_single_asic)
from .mock_tables import dbconnector
dbconnector.load_database_config()