Skip to content

Commit e013b00

Browse files
richardyu-mschrispsommers
authored andcommitted
[SAI Test] Add Mac generate method and retry when turnning up port (opencomputeproject#1546)
* move the mac generate method to util Signed-off-by: richardyu-ms <richard.yu@microsoft.com> * [SAI Test] Add Mac generate method and retry when turnning up port Add mac method for generating MAC address Retry when tunning up ports Test done: Test on DUT Signed-off-by: richardyu-ms <richard.yu@microsoft.com> Signed-off-by: Chris Sommers <chrispsommers@gmail.com>
1 parent b63111c commit e013b00

4 files changed

Lines changed: 68 additions & 49 deletions

File tree

test/sai_test/config/fdb_configer.py

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,31 @@ def t0_fdb_config_helper(test_obj, is_create_fdb=True):
2828
Set the configuration in test directly.
2929
3030
Set the following test_obj attributes:
31-
list: local_server_mac_list
3231
list: default_vlan_fdb_list
3332
list: vlan_10_fdb_list
3433
list: vlan_20_fdb_list
3534
3635
"""
3736
configer = FdbConfiger(test_obj)
38-
local_server_mac_list = []
39-
mac_list_temp = []
4037

41-
mac_list_temp = configer.generate_mac_address_list(
42-
FDB_SERVER_NUM, 0, range(0, 1))
43-
local_server_mac_list.extend(mac_list_temp)
44-
mac_list_temp = configer.generate_mac_address_list(
45-
FDB_SERVER_NUM, 1, range(1, 9))
46-
local_server_mac_list.extend(mac_list_temp)
47-
mac_list_temp = configer.generate_mac_address_list(
48-
FDB_SERVER_NUM, 2, range(9, 17))
49-
local_server_mac_list.extend(mac_list_temp)
5038
if is_create_fdb:
5139
test_obj.default_vlan_fdb_list = configer.create_fdb_entries(
5240
switch_id=test_obj.switch_id,
53-
mac_list=local_server_mac_list[0:1],
41+
mac_list=test_obj.local_server_mac_list[0:1],
5442
port_oids=test_obj.bridge_port_list[0:1],
5543
vlan_oid=test_obj.default_vlan_id)
5644
test_obj.vlan_10_fdb_list = configer.create_fdb_entries(
5745
switch_id=test_obj.switch_id,
58-
mac_list=local_server_mac_list[1:9],
46+
mac_list=test_obj.local_server_mac_list[1:9],
5947
port_oids=test_obj.bridge_port_list[1:9],
6048
vlan_oid=test_obj.vlans[10].vlan_oid)
6149
test_obj.vlan_20_fdb_list = configer.create_fdb_entries(
6250
switch_id=test_obj.switch_id,
63-
mac_list=local_server_mac_list[9:17],
51+
mac_list=test_obj.local_server_mac_list[9:17],
6452
port_oids=test_obj.bridge_port_list[9:17],
6553
vlan_oid=test_obj.vlans[20].vlan_oid)
6654
# Todo dynamic use the vlan_member_port_map to add data to fdb
67-
test_obj.local_server_mac_list = local_server_mac_list
55+
6856

6957
def t0_fdb_tear_down_helper(test_obj):
7058
'''
@@ -133,23 +121,3 @@ def create_fdb_entries(self,
133121
wait_sec))
134122
time.sleep(wait_sec)
135123
return fdb_list
136-
137-
def generate_mac_address_list(self, role, group, indexes):
138-
"""
139-
Generate mac addresses.
140-
141-
Args:
142-
role: Role which is represented by the mac address(base on test plan config)
143-
group: group number for the mac address(base on test plan config)
144-
indexes: mac indexes
145-
146-
Returns:
147-
default_1q_bridge_id
148-
"""
149-
print("Generate MAC ...")
150-
mac_list = []
151-
for index in indexes:
152-
mac = FDB_MAC_PREFIX + ':' + role + ':' + \
153-
'{:02d}'.format(group) + ':' + '{:02d}'.format(index)
154-
mac_list.append(mac)
155-
return mac_list

test/sai_test/config/port_configer.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -396,26 +396,33 @@ def turn_up_and_check_ports(self, port_list):
396396

397397
# For brcm devices, need to init and setup the ports at once after start the switch.
398398
retries = 10
399-
for num_of_tries in range(retries):
400-
all_ports_are_up = True
401-
time.sleep(1)
402-
for port_id in port_list:
403-
port_attr = sai_thrift_get_port_attribute(self.client, port_id, oper_status=True)
404-
if port_attr['oper_status'] != SAI_PORT_OPER_STATUS_UP:
405-
all_ports_are_up = False
399+
down_port_list = []
400+
port_index = 0
401+
for port_id in port_list:
402+
port_attr = sai_thrift_get_port_attribute(self.client, port_id, oper_status=True)
403+
print("Turn up port {}".format(port_index))
404+
port_up = True
405+
if port_attr['oper_status'] != SAI_PORT_OPER_STATUS_UP:
406+
port_up = False
407+
for num_of_tries in range(retries):
408+
port_attr = sai_thrift_get_port_attribute(self.client, port_id, oper_status=True)
409+
if port_attr['oper_status'] == SAI_PORT_OPER_STATUS_UP:
410+
port_up = True
411+
break
406412
time.sleep(3)
407-
print("port {} is down, status: {}. Reset Admin State.".format(port_id, port_attr['oper_status']))
413+
print("port {} id {} is not up, status: {}. Retry. Reset Admin State.".format(port_index, port_id, port_attr['oper_status']))
408414
sai_thrift_set_port_attribute(
409415
self.client,
410416
port_oid=port_id,
411417
mtu=self.get_mtu(),
412418
admin_state=True,
413419
fec_mode=self.get_fec_mode())
414-
if all_ports_are_up:
415-
print("Retry {} times turn up port.".format(num_of_tries))
416-
break
417-
if not all_ports_are_up:
418-
print("Not all the ports are up after {} rounds of retries.".format(retries))
420+
if not port_up:
421+
down_port_list.append(port_index)
422+
port_index = port_index + 1
423+
if down_port_list:
424+
print("Ports {} are down after retries.".format(down_port_list))
425+
419426

420427

421428
def get_fec_mode(self):

test/sai_test/sai_test_base.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class T0TestBase(ThriftInterfaceDataPlane):
199199
self.port_list - list of all active port objects
200200
self.portX objects for all active ports (where X is a port number)
201201
self.lagX objects for all lag
202+
self.local_server_mac_list for all the local server mac
202203
"""
203204

204205
def setUp(self,
@@ -213,6 +214,8 @@ def setUp(self,
213214
is_create_route_for_lag=True,
214215
wait_sec=5):
215216
super(T0TestBase, self).setUp()
217+
self.create_server_mac_list()
218+
216219
self.port_configer = PortConfiger(self)
217220
self.switch_configer = SwitchConfiger(self)
218221
self.fdb_configer = FdbConfiger(self)
@@ -259,6 +262,26 @@ def start_shell():
259262
thread = Thread(target=start_shell)
260263
thread.start()
261264

265+
def create_server_mac_list(self):
266+
"""
267+
Create server mac list.
268+
269+
Add those following attribute to this class:
270+
self.local_server_mac_list for all the local server mac
271+
"""
272+
local_server_mac_list = []
273+
mac_list_temp = []
274+
mac_list_temp = generate_mac_address_list(
275+
FDB_SERVER_NUM, 0, range(0, 1))
276+
local_server_mac_list.extend(mac_list_temp)
277+
mac_list_temp = generate_mac_address_list(
278+
FDB_SERVER_NUM, 1, range(1, 9))
279+
local_server_mac_list.extend(mac_list_temp)
280+
mac_list_temp = generate_mac_address_list(
281+
FDB_SERVER_NUM, 2, range(9, 17))
282+
local_server_mac_list.extend(mac_list_temp)
283+
self.local_server_mac_list = local_server_mac_list
284+
262285
@staticmethod
263286
def status():
264287
"""

test/sai_test/sai_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,24 @@ def sai_ipaddress(addr_str):
137137
ip_addr = sai_thrift_ip_address_t(addr_family=family, addr=addr)
138138

139139
return ip_addr
140+
141+
142+
def generate_mac_address_list(role, group, indexes):
143+
"""
144+
Generate mac addresses.
145+
146+
Args:
147+
role: Role which is represented by the mac address(base on test plan config)
148+
group: group number for the mac address(base on test plan config)
149+
indexes: mac indexes
150+
151+
Returns:
152+
default_1q_bridge_id
153+
"""
154+
print("Generate MAC ...")
155+
mac_list = []
156+
for index in indexes:
157+
mac = FDB_MAC_PREFIX + ':' + role + ':' + \
158+
'{:02d}'.format(group) + ':' + '{:02d}'.format(index)
159+
mac_list.append(mac)
160+
return mac_list

0 commit comments

Comments
 (0)