forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintfutil_test.py
234 lines (198 loc) · 11.5 KB
/
intfutil_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
227
228
229
230
231
232
233
234
import os
import sys
from click.testing import CliRunner
from unittest import TestCase
import subprocess
import show.main as show
root_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(root_path)
scripts_path = os.path.join(modules_path, "scripts")
show_interface_status_output="""\
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- --------------- ------- ----- ----- --------- --------------- ------ ------- --------------- ----------
Ethernet0 0 25G 9100 rs Ethernet0 routed down up QSFP28 or later off
Ethernet32 13,14,15,16 40G 9100 rs etp9 PortChannel1001 up up N/A off
Ethernet112 93,94,95,96 40G 9100 rs etp29 PortChannel0001 up up N/A off
Ethernet116 89,90,91,92 40G 9100 rs etp30 PortChannel0002 up up N/A off
Ethernet120 101,102,103,104 40G 9100 rs etp31 PortChannel0003 up up N/A off
Ethernet124 97,98,99,100 40G 9100 rs etp32 PortChannel0004 up up N/A off
PortChannel0001 N/A 40G 9100 N/A N/A routed down up N/A N/A
PortChannel0002 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel0003 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel0004 N/A 40G 9100 N/A N/A routed up up N/A N/A
PortChannel1001 N/A 40G 9100 N/A N/A routed N/A N/A N/A N/A
"""
show_interface_status_Ethernet32_output="""\
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
----------- ----------- ------- ----- ----- ------- --------------- ------ ------- ------ ----------
Ethernet32 13,14,15,16 40G 9100 rs etp9 PortChannel1001 up up N/A off
"""
show_interface_description_output="""\
Interface Oper Admin Alias Description
----------- ------ ------- --------- --------------------
Ethernet0 down up Ethernet0 ARISTA01T2:Ethernet1
Ethernet32 up up etp9 Servers7:eth0
Ethernet112 up up etp29 ARISTA01T1:Ethernet1
Ethernet116 up up etp30 ARISTA02T1:Ethernet1
Ethernet120 up up etp31 ARISTA03T1:Ethernet1
Ethernet124 up up etp32 ARISTA04T1:Ethernet1
"""
show_interface_description_Ethernet0_output="""\
Interface Oper Admin Alias Description
----------- ------ ------- --------- --------------------
Ethernet0 down up Ethernet0 ARISTA01T2:Ethernet1
"""
show_interface_description_Ethernet0_verbose_output="""\
Running command: intfutil -c description -i Ethernet0
Interface Oper Admin Alias Description
----------- ------ ------- --------- --------------------
Ethernet0 down up Ethernet0 ARISTA01T2:Ethernet1
"""
show_interface_description_eth9_output="""\
Interface Oper Admin Alias Description
----------- ------ ------- ------- -------------
Ethernet32 up up etp9 Servers7:eth0
"""
class TestIntfutil(TestCase):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ["PATH"] += os.pathsep + scripts_path
os.environ["UTILITIES_UNIT_TESTING"] = "2"
def setUp(self):
self.runner = CliRunner()
# Test 'show interfaces status' / 'intfutil status'
def test_intf_status(self):
# Test 'show interfaces status'
result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], [])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interface_status_output
# Test 'intfutil status'
output = subprocess.check_output('intfutil -c status', stderr=subprocess.STDOUT, shell=True)
print(output)
assert result.output == show_interface_status_output
# Test 'show interfaces status --verbose'
def test_intf_status_verbose(self):
result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], ["--verbose"])
assert result.exit_code == 0
print(result.exit_code)
print(result.output)
expected_output = "Running command: intfutil -c status -d all"
assert result.output.split('\n')[0] == expected_output
def test_intf_status_Ethernet32(self):
result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], ["Ethernet32"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interface_status_Ethernet32_output
def test_intf_status_etp9(self):
os.environ["SONIC_CLI_IFACE_MODE"] = "alias"
result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], ["etp9"])
os.environ["SONIC_CLI_IFACE_MODE"] = "default"
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interface_status_Ethernet32_output
def test_show_interfaces_description(self):
result = self.runner.invoke(show.cli.commands["interfaces"].commands["description"], [])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interface_description_output
def test_show_interfaces_description_Ethernet0(self):
result = self.runner.invoke(show.cli.commands["interfaces"].commands["description"], ["Ethernet0"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interface_description_Ethernet0_output
def test_show_interfaces_description_etp9_in_alias_mode(self):
os.environ["SONIC_CLI_IFACE_MODE"] = "alias"
result = self.runner.invoke(show.cli.commands["interfaces"].commands["description"], ["etp9"])
os.environ["SONIC_CLI_IFACE_MODE"] = "default"
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interface_description_eth9_output
def test_show_interfaces_description_etp33_in_alias_mode(self):
os.environ["SONIC_CLI_IFACE_MODE"] = "alias"
result = self.runner.invoke(show.cli.commands["interfaces"].commands["description"], ["etp33"])
os.environ["SONIC_CLI_IFACE_MODE"] = "default"
print(result.exit_code)
print(result.output)
assert result.exit_code != 0
assert "Error: cannot find interface name for alias etp33" in result.output
def test_show_interfaces_description_Ethernet0_verbose(self):
result = self.runner.invoke(show.cli.commands["interfaces"].commands["description"], ["Ethernet0", "--verbose"])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
assert result.output == show_interface_description_Ethernet0_verbose_output
# Test 'show subinterfaces status' / 'intfutil status subport'
def test_subintf_status(self):
# Test 'show subinterfaces status'
result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], [])
print >> sys.stderr, result.output
expected_output = (
"Sub port interface Speed MTU Vlan Admin Type\n"
"-------------------- ------- ----- ------ ------- --------------------\n"
" Ethernet0.10 25G 9100 10 up 802.1q-encapsulation"
)
self.assertEqual(result.output.strip(), expected_output)
# Test 'intfutil status subport'
output = subprocess.check_output('intfutil -c status -i subport', stderr=subprocess.STDOUT, shell=True)
print >> sys.stderr, output
self.assertEqual(output.strip(), expected_output)
# Test 'show subinterfaces status --verbose'
def test_subintf_status_verbose(self):
result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["--verbose"])
print >> sys.stderr, result.output
expected_output = "Command: intfutil -c status -i subport"
self.assertEqual(result.output.split('\n')[0], expected_output)
# Test single sub interface status
def test_single_subintf_status(self):
# Test 'show subinterfaces status Ethernet0.10'
result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["Ethernet0.10"])
print >> sys.stderr, result.output
expected_output = (
"Sub port interface Speed MTU Vlan Admin Type\n"
"-------------------- ------- ----- ------ ------- --------------------\n"
" Ethernet0.10 25G 9100 10 up 802.1q-encapsulation"
)
self.assertEqual(result.output.strip(), expected_output)
# Test 'intfutil status Ethernet0.10'
output = subprocess.check_output('intfutil -c status -i Ethernet0.10', stderr=subprocess.STDOUT, shell=True)
print >> sys.stderr, output
self.assertEqual(output.strip(), expected_output)
# Test '--verbose' status of single sub interface
def test_single_subintf_status_verbose(self):
result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["Ethernet0.10", "--verbose"])
print >> sys.stderr, result.output
expected_output = "Command: intfutil -c status -i Ethernet0.10"
self.assertEqual(result.output.split('\n')[0], expected_output)
# Test status of single sub interface in alias naming mode
def test_single_subintf_status_alias_mode(self):
os.environ["SONIC_CLI_IFACE_MODE"] = "alias"
result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["etp1.10"])
print >> sys.stderr, result.output
expected_output = (
"Sub port interface Speed MTU Vlan Admin Type\n"
"-------------------- ------- ----- ------ ------- --------------------\n"
" Ethernet0.10 25G 9100 10 up 802.1q-encapsulation"
)
self.assertEqual(result.output.strip(), expected_output)
os.environ["SONIC_CLI_IFACE_MODE"] = "default"
# Test '--verbose' status of single sub interface in alias naming mode
def test_single_subintf_status_alias_mode_verbose(self):
os.environ["SONIC_CLI_IFACE_MODE"] = "alias"
result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["etp1.10", "--verbose"])
print >> sys.stderr, result.output
expected_output = "Command: intfutil -c status -i Ethernet0.10"
self.assertEqual(result.output.split('\n')[0], expected_output)
os.environ["SONIC_CLI_IFACE_MODE"] = "default"
@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"