forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fabric_cli_and_db.py
More file actions
293 lines (259 loc) · 14.2 KB
/
Copy pathtest_fabric_cli_and_db.py
File metadata and controls
293 lines (259 loc) · 14.2 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import pytest
from tests.common.helpers.assertions import pytest_assert
import logging
import random
logger = logging.getLogger(__name__)
# This test only runs on t2 systems.
pytestmark = [
pytest.mark.topology('t2')
]
# There are 12 asic on Supervisor now.
# Initialize the reference data dictionary for sup.
num_asics = 12
# Set the number of links to test for each test. If all
# links are tested these tests can take almost an hour!
num_links_to_test = 6
# This test iterates over the fabric links on a linecard
# It isolates and unisolates each fabric link. Each time the
# state of the link is changed the state is checked in both
# CONFIG_DB and APPL_DB.
# The values in CONFIG_DB are updated by the fabric CLI commands
# and the values in APPL_DB are updated by the fabric manager
# daemon.
def test_fabric_cli_isolate_linecards(duthosts, enum_frontend_dut_hostname):
"""compare the CLI output with the reference data"""
allPortsList = []
duthost = duthosts[enum_frontend_dut_hostname]
logger.info("duthost: {}".format(duthost.hostname))
# Testing on Linecards
num_asics = duthost.num_asics()
logger.info("num_asics: {}".format(num_asics))
for asic in range(num_asics):
cmd = "show fabric reachability"
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
asicName = "asic{}".format(asic)
logger.info(asicName)
if num_asics > 1:
asicNamespaceOption = "-n {}".format(asicName)
else:
asicNamespaceOption = ""
# Create list of ports
for line in cmd_output:
if not line:
continue
tokens = line.split()
if not tokens[0].isdigit():
continue
# tokens: [localPort, remoteModule, remotLink, localLinkStatus]
localPort = tokens[0]
allPortsList.append(localPort)
# To test a few of the links
portList = []
while len(portList) < num_links_to_test:
randomPort = random.choice(allPortsList)
if randomPort not in portList:
portList.append(randomPort)
# Test each fabric link
for localPort in portList:
logger.info("localPort {}".format(localPort))
# continue
# Get the current isolation status of the port
cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption,
localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
originalIsolateStatus = tokens[0]
pytest_assert(
originalIsolateStatus == "True" or originalIsolateStatus == "False",
"Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort))
# If the port is isolated then temporarily unisolate it
if originalIsolateStatus == "True":
cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)
stderr_output = cmd_output["stderr"]
pytest_assert(
len(stderr_output) <= 0, "command: {} failed, error: {}".format(cmd, stderr_output))
# Check the isolateStatus in CONFIG_DB
cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption,
localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "False",
"Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort))
# Check the isolateStatus in APPL_DB
cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption,
localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
pytest_assert(
len(tokens) > 0, "FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "False",
"Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort))
# Isolate the port
cmd = "sudo config fabric port isolate {} {}".format(localPort, asicNamespaceOption)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)
stderr_output = cmd_output["stderr"]
pytest_assert(
len(stderr_output) <= 0, "command: {} failed, error: {}".format(cmd, stderr_output))
# Check the isolateStatus in CONFIG_DB
cmd = "sonic-db-cli {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicNamespaceOption,
localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB".format(localPort))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "True",
"Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort))
# Check the isolateStatus in APPL_DB
cmd = "sonic-db-cli {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicNamespaceOption,
localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB".format(localPort))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "True",
"Port {} APPL_DB initial isolateStatus is True, expected False".format(localPort))
# If the port was originally not isolsated then restore it
if originalIsolateStatus == "False":
cmd = "sudo config fabric port unisolate {} {}".format(localPort, asicNamespaceOption)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)
stderr_output = cmd_output["stderr"]
pytest_assert(
len(stderr_output) <= 0,
"command: {} failed, error: {}".format(cmd, stderr_output))
# This test iterates over the fabric links on each asic
# on the supervisor.
# It isolates and unisolates each fabric link. Each time the
# state of the link is changed the state is checked in both
# CONFIG_DB and APPL_DB.
# The values in CONFIG_DB are updated by the fabric CLI commands
# and the values in APPL_DB are updated by the fabric manager
# daemon.
def test_fabric_cli_isolate_supervisor(duthosts, enum_supervisor_dut_hostname):
"""compare the CLI output with the reference data for each asic"""
duthost = duthosts[enum_supervisor_dut_hostname]
logger.info("duthost: {}".format(duthost.hostname))
num_asics = duthost.num_asics()
logger.info("num_asics: {}".format(num_asics))
for asic in range(num_asics):
allPortsList = []
portList = []
asicName = "asic{}".format(asic)
logger.info(asicName)
# Create list of ports
cmd = "show fabric reachability -n asic{}".format(asic)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
for line in cmd_output:
if not line:
continue
tokens = line.split()
# (localPort, remoteModule, remotePort, status)
if not tokens[0].isdigit():
continue
localPort = tokens[0]
allPortsList.append(localPort)
# To test a few of the links
portList = []
while len(portList) < num_links_to_test:
randomPort = random.choice(allPortsList)
if randomPort not in portList:
portList.append(randomPort)
# Test each fabric link
for localPort in portList:
logger.info("local port {}".format(localPort))
# continue
# Get the current isolation status of the port
cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
originalIsolateStatus = tokens[0]
pytest_assert(
originalIsolateStatus == "True" or originalIsolateStatus == "False",
"Port {} CONFIG_DB initial isolateStatus is True, expected False".format(localPort))
logger.debug("originalIsolateStatus: {}".format(originalIsolateStatus))
# If the port is isolated then temporarily unisolate it
if originalIsolateStatus == "True":
cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)
stderr_output = cmd_output["stderr"]
pytest_assert(
len(stderr_output) <= 0,
"command: {} failed, error: {}".format(cmd, stderr_output))
# Check the isolateStatus in CONFIG_DB
cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
originalIsolateStatus = tokens[0]
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "False",
"Port {} CONFIG_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus))
# Check the isolateStatus in APPL_DB
cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName,
localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
originalIsolateStatus = tokens[0]
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "False",
"Port {} APPL_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus))
# Isolate the port
cmd = "sudo config fabric port isolate {} -n {}".format(localPort, asicName)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)
stderr_output = cmd_output["stderr"]
pytest_assert(
len(stderr_output) <= 0,
"command: {} failed, error: {}".format(cmd, stderr_output))
# Check the isolateStatus in CONFIG_DB
cmd = "sonic-db-cli -n {} CONFIG_DB hget 'FABRIC_PORT|Fabric{}' isolateStatus".format(asicName, localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
originalIsolateStatus = tokens[0]
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT|Fabric{} isolateStatus not found in CONFIG_DB, {} ".format(localPort, asicName))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "True",
"Port {} CONFIG_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus))
# Check the isolateStatus in APPL_DB
cmd = "sonic-db-cli -n {} APPL_DB hget 'FABRIC_PORT_TABLE:Fabric{}' isolateStatus".format(asicName,
localPort)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)["stdout"].split("\n")
tokens = cmd_output[0].split()
originalIsolateStatus = tokens[0]
pytest_assert(
len(tokens) > 0,
"FABRIC_PORT_TABLE:Fabric{} isolateStatus not found in APPL_DB, {} ".format(localPort, asicName))
isolateStatus = tokens[0]
pytest_assert(
isolateStatus == "True",
"Port {} APPL_DB initial isolateStatus is '{}', expected False".format(localPort, isolateStatus))
# If the port was originally not isolsated then restore it
if originalIsolateStatus == "False":
cmd = "sudo config fabric port unisolate {} -n {}".format(localPort, asicName)
cmd_output = duthost.shell(cmd, module_ignore_errors=True)
stderr_output = cmd_output["stderr"]
pytest_assert(
len(stderr_output) <= 0,
"command: {} failed, error: {}".format(cmd, stderr_output))