Skip to content

Commit d5a6da3

Browse files
authored
Do not configure physical attributes on port channels in portconfig (sonic-net#2456)
- What I did portconfig is a utility designed to configure various attributes on a physical port or a port channel. It should reject the operation that a user wants to configure an attribute that will be inserted into CONFIG_DB.PORT table on a port channel. Otherwise, it will generate an entry for the port channel, which causes orchagent to be aborted. Eg. the following commands will cause an error admin@sonic:~$ sudo config portchannel add PortChannel0001 admin@sonic:~$ sudo config interface speed PortChannel0001 100000 After the fix, configuring physical attributes on a port channel will be rejected - How I did it - How to verify it Unit test Signed-off-by: Stephen Sun <[email protected]>
1 parent 48ee772 commit d5a6da3

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

scripts/portconfig

+29-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class portconfig(object):
118118
print(port_tables[port])
119119

120120
def set_speed(self, port, speed):
121+
if self.is_lag:
122+
raise Exception("Invalid port %s" % (port))
123+
121124
if self.verbose:
122125
print("Setting speed %s on port %s" % (speed, port))
123126
supported_speeds_str = self.get_supported_speeds(port) or ''
@@ -129,6 +132,9 @@ class portconfig(object):
129132
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_SPEED_CONFIG_FIELD_NAME: speed})
130133

131134
def set_fec(self, port, fec):
135+
if self.is_lag:
136+
raise Exception("Invalid port %s" % (port))
137+
132138
if self.verbose:
133139
print("Setting fec %s on port %s" % (fec, port))
134140
supported_fecs = self.get_supported_fecs(port)
@@ -141,14 +147,17 @@ class portconfig(object):
141147
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_FEC_CONFIG_FIELD_NAME: fec})
142148

143149
def set_mtu(self, port, mtu):
144-
port_tables = self.db.get_table(PORT_TABLE_NAME)
145-
if port not in port_tables:
150+
if self.is_lag:
146151
raise Exception("Invalid port %s" % (port))
152+
147153
if self.verbose:
148154
print("Setting mtu %s on port %s" % (mtu, port))
149155
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_MTU_CONFIG_FIELD_NAME: mtu})
150156

151157
def set_link_training(self, port, mode):
158+
if self.is_lag:
159+
raise Exception("Invalid port %s" % (port))
160+
152161
if self.verbose:
153162
print("Setting link-training %s on port %s" % (mode, port))
154163
lt_modes = ['on', 'off']
@@ -159,20 +168,32 @@ class portconfig(object):
159168
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_LINK_TRAINING_CONFIG_FIELD_NAME: mode})
160169

161170
def set_autoneg(self, port, mode):
171+
if self.is_lag:
172+
raise Exception("Invalid port %s" % (port))
173+
162174
if self.verbose:
163175
print("Setting autoneg %s on port %s" % (mode, port))
164176
mode = 'on' if mode == 'enabled' else 'off'
165177
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_AUTONEG_CONFIG_FIELD_NAME: mode})
166178

167179
def set_tx_power(self, port, tx_power):
180+
if self.is_lag:
181+
raise Exception("Invalid port %s" % (port))
182+
168183
print("Setting target Tx output power to %s dBm on port %s" % (tx_power, port))
169184
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_XCVR_TX_POWER_FIELD_NAME: tx_power})
170185

171186
def set_laser_freq(self, port, laser_freq):
187+
if self.is_lag:
188+
raise Exception("Invalid port %s" % (port))
189+
172190
print("Setting laser frequency to %s GHz on port %s" % (laser_freq, port))
173191
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_XCVR_LASER_FREQ_FIELD_NAME: laser_freq})
174192

175193
def set_adv_speeds(self, port, adv_speeds):
194+
if self.is_lag:
195+
raise Exception("Invalid port %s" % (port))
196+
176197
if self.verbose:
177198
print("Setting adv_speeds %s on port %s" % (adv_speeds, port))
178199

@@ -194,6 +215,9 @@ class portconfig(object):
194215
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_ADV_SPEEDS_CONFIG_FIELD_NAME: adv_speeds})
195216

196217
def set_interface_type(self, port, interface_type):
218+
if self.is_lag:
219+
raise Exception("Invalid port %s" % (port))
220+
197221
if self.is_rj45_port:
198222
print("Setting RJ45 ports' type is not supported")
199223
exit(1)
@@ -206,6 +230,9 @@ class portconfig(object):
206230
self.db.mod_entry(PORT_TABLE_NAME, port, {PORT_INTERFACE_TYPE_CONFIG_FIELD_NAME: interface_type})
207231

208232
def set_adv_interface_types(self, port, adv_interface_types):
233+
if self.is_lag:
234+
raise Exception("Invalid port %s" % (port))
235+
209236
if self.is_rj45_port:
210237
print("Setting RJ45 ports' advertised types is not supported")
211238
exit(1)

tests/config_an_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def test_config_autoneg(self, ctx):
3333
self.basic_check("autoneg", ["Ethernet0", "disabled"], ctx)
3434
self.basic_check("autoneg", ["Invalid", "enabled"], ctx, operator.ne)
3535
self.basic_check("autoneg", ["Ethernet0", "invalid"], ctx, operator.ne)
36+
# Setting auto negotiation on a port channel is not supported
37+
result = self.basic_check("autoneg", ["PortChannel0001", "enabled"], ctx, operator.ne)
38+
assert 'Invalid port PortChannel0001' in result.output
3639

3740
def test_config_speed(self, ctx):
3841
self.basic_check("speed", ["Ethernet0", "40000"], ctx)
@@ -42,6 +45,9 @@ def test_config_speed(self, ctx):
4245
assert 'Invalid speed' in result.output
4346
assert 'Valid speeds:' in result.output
4447
self.basic_check("speed", ["Ethernet0", "invalid"], ctx, operator.ne)
48+
# Setting speed on a port channel is not supported
49+
result = self.basic_check("speed", ["PortChannel0001", "100000"], ctx, operator.ne)
50+
assert 'Invalid port PortChannel0001' in result.output
4551

4652
def test_config_adv_speeds(self, ctx):
4753
self.basic_check("advertised-speeds", ["Ethernet0", "40000,100000"], ctx)
@@ -53,6 +59,9 @@ def test_config_adv_speeds(self, ctx):
5359
result = self.basic_check("advertised-speeds", ["Ethernet0", "50000,50000"], ctx, operator.ne)
5460
assert 'Invalid speed' in result.output
5561
assert 'duplicate' in result.output
62+
# Setting advertised speeds on a port channel is not supported
63+
result = self.basic_check("advertised-speeds", ["PortChannel0001", "40000,100000"], ctx, operator.ne)
64+
assert 'Invalid port PortChannel0001' in result.output
5665

5766
def test_config_type(self, ctx):
5867
self.basic_check("type", ["Ethernet0", "CR4"], ctx)
@@ -64,6 +73,9 @@ def test_config_type(self, ctx):
6473
assert 'Valid interface types:' in result.output
6574
result = self.basic_check("type", ["Ethernet16", "Invalid"], ctx, operator.ne)
6675
assert "Setting RJ45 ports' type is not supported" in result.output
76+
# Setting type on a port channel is not supported
77+
result = self.basic_check("type", ["PortChannel0001", "CR4"], ctx, operator.ne)
78+
assert 'Invalid port PortChannel0001' in result.output
6779

6880
def test_config_adv_types(self, ctx):
6981
self.basic_check("advertised-types", ["Ethernet0", "CR4,KR4"], ctx)
@@ -78,6 +90,9 @@ def test_config_adv_types(self, ctx):
7890
self.basic_check("advertised-types", ["Ethernet0", ""], ctx, operator.ne)
7991
result = self.basic_check("advertised-types", ["Ethernet16", "Invalid"], ctx, operator.ne)
8092
assert "Setting RJ45 ports' advertised types is not supported" in result.output
93+
# Setting advertised types on a port channel is not supported
94+
result = self.basic_check("advertised-types", ["PortChannel0001", "CR4,KR4"], ctx, operator.ne)
95+
assert 'Invalid port PortChannel0001' in result.output
8196

8297
def test_config_mtu(self, ctx):
8398
self.basic_check("mtu", ["Ethernet0", "1514"], ctx)
@@ -99,6 +114,9 @@ def test_config_fec(self, ctx):
99114
# Negative case: set a fec mode on a port where setting fec is not supported
100115
result = self.basic_check("fec", ["Ethernet112", "test"], ctx, operator.ne)
101116
assert "Setting fec is not supported" in result.output
117+
# Negative case: set a fec mode on a port channel is not supported
118+
result = self.basic_check("fec", ["PortChannel0001", "none"], ctx, operator.ne)
119+
assert 'Invalid port PortChannel0001' in result.output
102120

103121
def basic_check(self, command_name, para_list, ctx, op=operator.eq, expect_result=0):
104122
runner = CliRunner()

tests/config_lt_test.py

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def test_config_link_training(self, ctx):
3434
self.basic_check("link-training", ["Invalid", "on"], ctx, operator.ne)
3535
self.basic_check("link-training", ["Invalid", "off"], ctx, operator.ne)
3636
self.basic_check("link-training", ["Ethernet0", "invalid"], ctx, operator.ne)
37+
# Setting link training on a port channel is not supported
38+
result = self.basic_check("link-training", ["PortChannel0001", "on"], ctx, operator.ne)
39+
assert 'Invalid port PortChannel0001' in result.output
3740

3841
def basic_check(self, command_name, para_list, ctx, op=operator.eq, expect_result=0):
3942
runner = CliRunner()

tests/config_xcvr_test.py

+6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ def test_config_laser_frequency(self, ctx):
3434
assert "Setting laser frequency" in result.output
3535
result = self.basic_check("frequency", ["Ethernet0", "--", "-1"], ctx, op=operator.ne)
3636
assert "Error: Frequency must be > 0" in result.output
37+
# Setting laser frequency on a port channel is not supported
38+
result = self.basic_check("frequency", ["PortChannel0001", "191300"], ctx, operator.ne)
39+
assert 'Invalid port PortChannel0001' in result.output
3740

3841
def test_config_tx_power(self, ctx):
3942
result = self.basic_check("tx_power", ["Ethernet0", "11.3"], ctx)
4043
assert "Setting target Tx output power" in result.output
4144
result = self.basic_check("tx_power", ["Ethernet0", "11.34"], ctx, op=operator.ne)
4245
assert "Error: tx power must be with single decimal place" in result.output
46+
# Setting tx power on a port channel is not supported
47+
result = self.basic_check("tx_power", ["PortChannel0001", "11.3"], ctx, operator.ne)
48+
assert 'Invalid port PortChannel0001' in result.output
4349

4450
def basic_check(self, command_name, para_list, ctx, op=operator.eq, expect_result=0):
4551
runner = CliRunner()

0 commit comments

Comments
 (0)