Skip to content

Commit 0dea91c

Browse files
committed
[test_virtual_chassis]: use wait_for function to improve test robustness
Signed-off-by: Guohan Lu <lguohan@gmail.com>
1 parent 3f11a50 commit 0dea91c

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

tests/test_virtual_chassis.py

+35-32
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def test_connectivity(self, vct):
3030

3131
def test_voq_switch(self, vct):
3232
"""Test VOQ switch objects configuration.
33-
33+
3434
This test validates configuration of switch creation objects required for
3535
VOQ switches. The switch_type, max_cores and switch_id attributes configuration
36-
are verified. For the System port config list, it is verified that all the
36+
are verified. For the System port config list, it is verified that all the
3737
configured system ports are avaiable in the asic db by checking the count.
3838
"""
3939

@@ -54,58 +54,58 @@ def test_voq_switch(self, vct):
5454

5555
cfg_max_cores = metatbl.get("max_cores")
5656
assert cfg_max_cores != "", "Got error in getting max_cores from CONFIG_DB DEVICE_METADATA"
57-
57+
5858
cfgspkeys = config_db.get_keys("SYSTEM_PORT")
5959
sp_count = len(cfgspkeys)
6060

6161
asic_db = dvs.get_asic_db()
6262
keys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_SWITCH")
6363
switch_oid_key = keys[0]
64-
64+
6565
switch_entry = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_SWITCH", switch_oid_key)
6666

6767
value = switch_entry.get("SAI_SWITCH_ATTR_TYPE")
6868
assert value == "SAI_SWITCH_TYPE_VOQ", "Switch type is not VOQ"
69-
69+
7070
value = switch_entry.get("SAI_SWITCH_ATTR_SWITCH_ID")
7171
assert value == cfg_switch_id, "VOQ switch id is invalid"
72-
72+
7373
value = switch_entry.get("SAI_SWITCH_ATTR_MAX_SYSTEM_CORES")
7474
assert value == cfg_max_cores, "Max system cores is invalid"
75-
75+
7676
value = switch_entry.get("SAI_SWITCH_ATTR_SYSTEM_PORT_CONFIG_LIST")
7777
assert value != "", "Empty system port config list"
7878
# Convert the spcfg string to dictionary
7979
spcfg = ast.literal_eval(value)
8080
assert spcfg['count'] == sp_count, "Number of systems ports configured is invalid"
81-
81+
8282
def test_chassis_app_db_sync(self, vct):
8383
"""Test chassis app db syncing.
84-
84+
8585
This test is for verifying the database sync mechanism. With the virtual chassis
8686
setup, it is verified that at least one database entry is synced from line card to
8787
supervisor card. An interface entry is used as sample database entry for verification
8888
of syncing mechanism.
8989
"""
90-
90+
9191
dvss = vct.dvss
9292
for name in dvss.keys():
9393
if name.startswith("supervisor"):
9494
dvs = dvss[name]
9595
chassis_app_db = DVSDatabase(swsscommon.CHASSIS_APP_DB, dvs.redis_chassis_sock)
9696
keys = chassis_app_db.get_keys("SYSTEM_INTERFACE")
9797
assert len(keys), "No chassis app db syncing is done"
98-
98+
9999
def test_chassis_system_interface(self, vct):
100100
"""Test RIF record creation in ASIC_DB for remote interfaces.
101-
101+
102102
This test verifies RIF programming in ASIC_DB for remote interface. The orchagent
103103
creates RIF record for system port interfaces from other line cards. It is verified
104104
by retrieving a RIF record from local ASIC_DB that corresponds to a remote system port
105-
and checking that the switch id of that remote system port does not match the local asic
105+
and checking that the switch id of that remote system port does not match the local asic
106106
switch id.
107107
"""
108-
108+
109109
dvss = vct.dvss
110110
for name in dvss.keys():
111111
dvs = dvss[name]
@@ -116,11 +116,11 @@ def test_chassis_system_interface(self, vct):
116116
cfg_switch_type = metatbl.get("switch_type")
117117

118118
# Test only for line cards
119-
if cfg_switch_type == "voq":
119+
if cfg_switch_type == "voq":
120120
lc_switch_id = metatbl.get("switch_id")
121121
assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA"
122122
if lc_switch_id == "0":
123-
# Testing in Linecard1, In Linecard1 there will be RIF for Ethernet12 from Linecard3
123+
# Testing in Linecard1, In Linecard1 there will be RIF for Ethernet12 from Linecard3
124124
# Note: Tesing can be done in any linecard for RIF of any system port interface.
125125
# Here testing is done on linecard with switch id 0
126126
asic_db = dvs.get_asic_db()
@@ -151,14 +151,15 @@ def test_chassis_system_interface(self, vct):
151151

152152
def test_chassis_system_neigh(self, vct):
153153
"""Test neigh record creation and syncing to chassis app db.
154-
154+
155155
This test validates that:
156156
(i) Local neighbor entry is created with encap index
157157
(ii) Local neighbor is synced to chassis ap db with assigned encap index
158158
TODO: (iii) Remote neighbor entry is created in ASIC_DB with received encap index
159159
"""
160160

161161
dvss = vct.dvss
162+
print("name {}".format(dvss.keys()))
162163
for name in dvss.keys():
163164
dvs = dvss[name]
164165

@@ -168,61 +169,63 @@ def test_chassis_system_neigh(self, vct):
168169
cfg_switch_type = metatbl.get("switch_type")
169170

170171
# Neighbor record verifiation done in line card
171-
if cfg_switch_type == "voq":
172+
if cfg_switch_type == "voq":
172173
lc_switch_id = metatbl.get("switch_id")
173174
assert lc_switch_id != "", "Got error in getting switch_id from CONFIG_DB DEVICE_METADATA"
174175
if lc_switch_id == "0":
175176

176177
# Add a static neighbor
178+
_, res = dvs.runcmd(['sh', "-c", "ip neigh show"])
177179
_, res = dvs.runcmd(['sh', "-c", "ip neigh add 10.8.101.2 lladdr 00:01:02:03:04:05 dev Ethernet0"])
178180
assert res == "", "Error configuring static neigh"
179181

180182
asic_db = dvs.get_asic_db()
181183
neighkeys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY")
182184
assert len(neighkeys), "No neigh entries in ASIC_DB"
183-
185+
184186
# Check for presence of the neighbor in ASIC_DB
185187
test_neigh = ""
186188
for nkey in neighkeys:
187189
ne = ast.literal_eval(nkey)
188190
if ne['ip'] == '10.8.101.2':
189191
test_neigh = nkey
190192
break
191-
193+
192194
assert test_neigh != "", "Neigh not found in ASIC_DB"
193-
195+
194196
# Check for presence of encap index, retrieve and store it for sync verification
195-
test_neigh_entry = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh)
197+
test_neigh_entry = asic_db.wait_for_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY", test_neigh)
196198
encap_index = test_neigh_entry.get("SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX")
197199
assert encap_index != "", "VOQ encap index is not programmed in ASIC_DB"
198-
200+
199201
break
200-
201-
# Verify neighbor record syncing with encap index
202+
203+
# Verify neighbor record syncing with encap index
202204
dvss = vct.dvss
203205
for name in dvss.keys():
204206
if name.startswith("supervisor"):
205207
dvs = dvss[name]
206208
chassis_app_db = DVSDatabase(swsscommon.CHASSIS_APP_DB, dvs.redis_chassis_sock)
209+
chassis_app_db.wait_for_n_keys("SYSTEM_NEIGH", 1)
207210
sysneighkeys = chassis_app_db.get_keys("SYSTEM_NEIGH")
208-
assert len(sysneighkeys), "No system neighbor entries in chassis app db"
209-
211+
212+
print(sysneighkeys)
210213
test_sysneigh = ""
211214
for sysnk in sysneighkeys:
212215
sysnk_tok = sysnk.split("|")
213216
assert len(sysnk_tok) == 3, "Invalid system neigh key in chassis app db"
214217
if sysnk_tok[2] == "10.8.101.2":
215218
test_sysneigh = sysnk
216219
break
217-
220+
218221
assert test_sysneigh != "", "Neigh is not sync-ed to chassis app db"
219-
220-
test_sysneigh_entry = chassis_app_db.get_entry("SYSTEM_NEIGH", test_sysneigh)
222+
223+
test_sysneigh_entry = chassis_app_db.get_entry("SYSTEM_NEIGH", test_sysneigh)
221224
sys_neigh_encap_index = test_sysneigh_entry.get("encap_index")
222225
assert sys_neigh_encap_index != "", "System neigh in chassis app db does not have encap index"
223-
226+
224227
assert encap_index == sys_neigh_encap_index, "Encap index not sync-ed correctly"
225-
228+
226229
break
227230

228231
# Add Dummy always-pass test at end as workaroud

0 commit comments

Comments
 (0)