Skip to content

Commit 67466cb

Browse files
[port] Fix port speed set (sonic-net#1952)
What I did Wrong port speed is set if included as a substring in a speed literal. For example if we have a valid supported speeds for a port with 4 lanes: 40000 and 100000. Then if we try to set 4000. sudo config interface speed Ethernet0 4000 As a result, we will get a wrong set speed 4G: dut:~$ show interfaces status Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC --------- ------ ------ ---- ---- -------- ----- ----- ------ ----------- ----- Ethernet0 0,1,2,3 4G 9100 rs Ethernet1/1 routed up up QSFP28 or later off How I did it Fixed finding the target (set) speed in the supported speeds list. How to verify it Set the wrong speed, which included as a substring in a speed literal. For example, for a speed 40000 it is 4000. If the wrong speed is set, an error message should appear: admin@sonic:~$ sudo config interface speed Ethernet0 4000 Invalid speed specified: 4000 Valid speeds:40000,100000 Only speeds from the list of "Valid speeds" have been successfully set. sudo config interface speed Ethernet0 40000 Signed-off-by: Mykola Gerasymenko <[email protected]>
1 parent 5172972 commit 67466cb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/portconfig

+6-6
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ class portconfig(object):
109109
def set_speed(self, port, speed):
110110
if self.verbose:
111111
print("Setting speed %s on port %s" % (speed, port))
112-
supported_speeds_str = self.get_supported_speeds(port)
113-
if supported_speeds_str:
114-
if supported_speeds_str.find(str(speed)) == -1:
115-
print('Invalid speed specified: {}'.format(speed))
116-
print('Valid speeds:{}'.format(supported_speeds_str))
117-
exit(1)
112+
supported_speeds_str = self.get_supported_speeds(port) or ''
113+
supported_speeds = [int(s) for s in supported_speeds_str.split(',') if s]
114+
if supported_speeds and int(speed) not in supported_speeds:
115+
print('Invalid speed specified: {}'.format(speed))
116+
print('Valid speeds:{}'.format(supported_speeds_str))
117+
exit(1)
118118
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_SPEED_CONFIG_FIELD_NAME: speed})
119119

120120
def set_fec(self, port, fec):

0 commit comments

Comments
 (0)