Skip to content

Commit 2cdadb5

Browse files
authored
[config]: Create portchannel with LACP key (#1473)
What I did Fix issue - sonic-net/sonic-buildimage#4009 Change the LACP key to be generated from the Port Channel name instead of always being 0. When upgrading without warm-reboot update old port channels to use the new default. How I did it When adding a new port-channel add by default the key lacp_key with the value 'auto' to the port-channel table, this is done to change the port-channel LACP key to be generated from the Port Channel name instead of always being 0. When upgrading without warm-reboot, also update old port channels to use the new default. This is not done on warm-reboot to avoid the link from going down.
1 parent 6f74ba5 commit 2cdadb5

File tree

5 files changed

+114
-3
lines changed

5 files changed

+114
-3
lines changed

config/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,8 @@ def add_portchannel(ctx, portchannel_name, min_links, fallback):
15021502
ctx.fail("{} already exists!".format(portchannel_name))
15031503

15041504
fvs = {'admin_status': 'up',
1505-
'mtu': '9100'}
1505+
'mtu': '9100',
1506+
'lacp_key': 'auto'}
15061507
if min_links != 0:
15071508
fvs['min_links'] = str(min_links)
15081509
if fallback != 'false':

scripts/db_migrator.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, namespace, socket=None):
4444
none-zero values.
4545
build: sequentially increase within a minor version domain.
4646
"""
47-
self.CURRENT_VERSION = 'version_2_0_0'
47+
self.CURRENT_VERSION = 'version_2_0_2'
4848

4949
self.TABLE_NAME = 'VERSIONS'
5050
self.TABLE_KEY = 'DATABASE'
@@ -527,9 +527,24 @@ def version_2_0_0(self):
527527

528528
def version_2_0_1(self):
529529
"""
530-
Current latest version. Nothing to do here.
530+
Version 2_0_1.
531531
"""
532532
log.log_info('Handling version_2_0_1')
533+
warmreboot_state = self.stateDB.get(self.stateDB.STATE_DB, 'WARM_RESTART_ENABLE_TABLE|system', 'enable')
534+
535+
if warmreboot_state != 'true':
536+
portchannel_table = self.configDB.get_table('PORTCHANNEL')
537+
for name, data in portchannel_table.items():
538+
data['lacp_key'] = 'auto'
539+
self.configDB.set_entry('PORTCHANNEL', name, data)
540+
self.set_version('version_2_0_2')
541+
return 'version_2_0_2'
542+
543+
def version_2_0_2(self):
544+
"""
545+
Current latest version. Nothing to do here.
546+
"""
547+
log.log_info('Handling version_2_0_2')
533548
return None
534549

535550
def get_version(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"PORTCHANNEL|PortChannel0": {
3+
"admin_status": "up",
4+
"members@": "Ethernet0,Ethernet4",
5+
"min_links": "2",
6+
"mtu": "9100",
7+
"lacp_key": "auto"
8+
},
9+
"PORTCHANNEL|PortChannel1": {
10+
"admin_status": "up",
11+
"members@": "Ethernet8,Ethernet12",
12+
"min_links": "2",
13+
"mtu": "9100",
14+
"lacp_key": "auto"
15+
},
16+
"PORTCHANNEL|PortChannel0123": {
17+
"admin_status": "up",
18+
"members@": "Ethernet16",
19+
"min_links": "1",
20+
"mtu": "9100",
21+
"lacp_key": "auto"
22+
},
23+
"PORTCHANNEL|PortChannel0011": {
24+
"admin_status": "up",
25+
"members@": "Ethernet20,Ethernet24",
26+
"min_links": "2",
27+
"mtu": "9100",
28+
"lacp_key": "auto"
29+
},
30+
"PORTCHANNEL|PortChannel9999": {
31+
"admin_status": "up",
32+
"mtu": "9100",
33+
"lacp_key": "auto"
34+
},
35+
"VERSIONS|DATABASE": {
36+
"VERSION": "version_2_0_2"
37+
}
38+
}
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"PORTCHANNEL|PortChannel0": {
3+
"admin_status": "up",
4+
"members@": "Ethernet0,Ethernet4",
5+
"min_links": "2",
6+
"mtu": "9100"
7+
},
8+
"PORTCHANNEL|PortChannel1": {
9+
"admin_status": "up",
10+
"members@": "Ethernet8,Ethernet12",
11+
"min_links": "2",
12+
"mtu": "9100"
13+
},
14+
"PORTCHANNEL|PortChannel0123": {
15+
"admin_status": "up",
16+
"members@": "Ethernet16",
17+
"min_links": "1",
18+
"mtu": "9100"
19+
},
20+
"PORTCHANNEL|PortChannel0011": {
21+
"admin_status": "up",
22+
"members@": "Ethernet20,Ethernet24",
23+
"min_links": "2",
24+
"mtu": "9100"
25+
},
26+
"PORTCHANNEL|PortChannel9999": {
27+
"admin_status": "up",
28+
"mtu": "9100"
29+
},
30+
"VERSIONS|DATABASE": {
31+
"VERSION": "version_2_0_1"
32+
}
33+
}

tests/db_migrator_test.py

+23
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,26 @@ def test_init_config_feature_migration(self):
247247
assert not diff
248248

249249
assert not expected_db.cfgdb.get_table('CONTAINER_FEATURE')
250+
251+
252+
class TestLacpKeyMigrator(object):
253+
@classmethod
254+
def setup_class(cls):
255+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
256+
257+
@classmethod
258+
def teardown_class(cls):
259+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
260+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
261+
262+
def test_lacp_key_migrator(self):
263+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'portchannel-input')
264+
import db_migrator
265+
dbmgtr = db_migrator.DBMigrator(None)
266+
dbmgtr.migrate()
267+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'portchannel-expected')
268+
expected_db = Db()
269+
advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb, 'version_2_0_2')
270+
271+
assert dbmgtr.configDB.get_table('PORTCHANNEL') == expected_db.cfgdb.get_table('PORTCHANNEL')
272+
assert dbmgtr.configDB.get_table('VERSIONS') == expected_db.cfgdb.get_table('VERSIONS')

0 commit comments

Comments
 (0)