Skip to content

Commit 8a78cf4

Browse files
vaibhavhdyxieca
authored andcommitted
Port 202012 DB migration changes to newer branches (#2515)
Fixes sonic-net/sonic-buildimage#12643 Version on 202012 branch is missing in master and 202205 branch. This caused failures in upgrade from 202012 to newer branch images, where db_migrator experienced crash. This commit fixes the issue, and ports the version handling for 202012 to newer branches.
1 parent 0157086 commit 8a78cf4

File tree

194 files changed

+422
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+422
-72
lines changed

scripts/db_migrator.py

+74-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import re
99

1010
from sonic_py_common import device_info, logger
11+
from swsssdk import ConfigDBConnector, SonicDBConfig
1112
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig
13+
from db_migrator_constants import RESTAPI, TELEMETRY, CONSOLE_SWITCH
1214

1315
INIT_CFG_FILE = '/etc/sonic/init_cfg.json'
1416

@@ -485,6 +487,61 @@ def migrate_qos_fieldval_reference_format(self):
485487
self.migrate_qos_db_fieldval_reference_remove(qos_table_list, self.configDB, self.configDB.CONFIG_DB, '|')
486488
return True
487489

490+
def migrate_vxlan_config(self):
491+
log.log_notice('Migrate VXLAN table config')
492+
# Collect VXLAN data from config DB
493+
vxlan_data = self.configDB.keys(self.configDB.CONFIG_DB, "VXLAN_TUNNEL*")
494+
if not vxlan_data:
495+
# do nothing if vxlan entries are not present in configdb
496+
return
497+
for vxlan_table in vxlan_data:
498+
vxlan_map_mapping = self.configDB.get_all(self.configDB.CONFIG_DB, vxlan_table)
499+
tunnel_keys = vxlan_table.split(self.configDB.KEY_SEPARATOR)
500+
tunnel_keys[0] = tunnel_keys[0] + "_TABLE"
501+
vxlan_table = self.appDB.get_db_separator(self.appDB.APPL_DB).join(tunnel_keys)
502+
for field, value in vxlan_map_mapping.items():
503+
# add entries from configdb to appdb only when they are missing
504+
if not self.appDB.hexists(self.appDB.APPL_DB, vxlan_table, field):
505+
log.log_notice('Copying vxlan entries from configdb to appdb: updated {} with {}:{}'.format(
506+
vxlan_table, field, value))
507+
self.appDB.set(self.appDB.APPL_DB, vxlan_table, field, value)
508+
509+
def migrate_restapi(self):
510+
# RESTAPI - add missing key
511+
log.log_notice('Migrate RESTAPI configuration')
512+
config = self.configDB.get_entry('RESTAPI', 'config')
513+
if not config:
514+
self.configDB.set_entry("RESTAPI", "config", RESTAPI.get("config"))
515+
certs = self.configDB.get_entry('RESTAPI', 'certs')
516+
if not certs:
517+
self.configDB.set_entry("RESTAPI", "certs", RESTAPI.get("certs"))
518+
519+
def migrate_telemetry(self):
520+
# TELEMETRY - add missing key
521+
log.log_notice('Migrate TELEMETRY configuration')
522+
gnmi = self.configDB.get_entry('TELEMETRY', 'gnmi')
523+
if not gnmi:
524+
self.configDB.set_entry("TELEMETRY", "gnmi", TELEMETRY.get("gnmi"))
525+
certs = self.configDB.get_entry('TELEMETRY', 'certs')
526+
if not certs:
527+
self.configDB.set_entry("TELEMETRY", "certs", TELEMETRY.get("certs"))
528+
529+
def migrate_console_switch(self):
530+
# CONSOLE_SWITCH - add missing key
531+
log.log_notice('Migrate CONSOLE_SWITCH configuration')
532+
console_mgmt = self.configDB.get_entry('CONSOLE_SWITCH', 'console_mgmt')
533+
if not console_mgmt:
534+
self.configDB.set_entry("CONSOLE_SWITCH", "console_mgmt",
535+
CONSOLE_SWITCH.get("console_mgmt"))
536+
537+
def migrate_device_metadata(self):
538+
# DEVICE_METADATA - synchronous_mode entry
539+
log.log_notice('Migrate DEVICE_METADATA missing configuration (synchronous_mode=enable)')
540+
metadata = self.configDB.get_entry('DEVICE_METADATA', 'localhost')
541+
if 'synchronous_mode' not in metadata:
542+
metadata['synchronous_mode'] = 'enable'
543+
self.configDB.set_entry('DEVICE_METADATA', 'localhost', metadata)
544+
488545
def migrate_port_qos_map_global(self):
489546
"""
490547
Generate dscp_to_tc_map for switch.
@@ -647,10 +704,25 @@ def version_2_0_0(self):
647704

648705
def version_2_0_1(self):
649706
"""
650-
Version 2_0_1.
651-
This is the latest version for 202012 branch
707+
Handle and migrate missing config that results from cross branch upgrade to
708+
202012 as target.
652709
"""
653710
log.log_info('Handling version_2_0_1')
711+
self.migrate_vxlan_config()
712+
self.migrate_restapi()
713+
self.migrate_telemetry()
714+
self.migrate_console_switch()
715+
self.migrate_device_metadata()
716+
717+
self.set_version('version_2_0_2')
718+
return 'version_2_0_2'
719+
720+
def version_2_0_2(self):
721+
"""
722+
Version 2_0_2
723+
This is the latest version for 202012 branch
724+
"""
725+
log.log_info('Handling version_2_0_2')
654726
self.set_version('version_3_0_0')
655727
return 'version_3_0_0'
656728

scripts/db_migrator_constants.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
RESTAPI = {
2+
"config": {
3+
"client_auth": "true",
4+
"log_level": "info",
5+
"allow_insecure": "false"
6+
},
7+
"certs": {
8+
"server_key": "/etc/sonic/credentials/restapiserver.key",
9+
"ca_crt": "/etc/sonic/credentials/AME_ROOT_CERTIFICATE.pem",
10+
"server_crt": "/etc/sonic/credentials/restapiserver.crt",
11+
"client_crt_cname": "client.restapi.sonic.gbl"
12+
}
13+
}
14+
15+
TELEMETRY = {
16+
"gnmi": {
17+
"client_auth": "true",
18+
"log_level": "2",
19+
"port": "50051"
20+
},
21+
"certs": {
22+
"server_key": "/etc/sonic/telemetry/streamingtelemetryserver.key",
23+
"ca_crt": "/etc/sonic/telemetry/dsmsroot.cer",
24+
"server_crt": "/etc/sonic/telemetry/streamingtelemetryserver.cer"
25+
}
26+
}
27+
28+
CONSOLE_SWITCH = {
29+
"console_mgmt": {
30+
"enabled": "no"
31+
}
32+
}

tests/db_migrator_input/config_db/acs-msn2700-t0-version_1_0_1.json

+1
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@
731731
"hwsku": "ACS-MSN2700",
732732
"default_bgp_status": "up",
733733
"type": "ToRRouter",
734+
"synchronous_mode": "enable",
734735
"hostname": "sonic",
735736
"platform": "x86_64-mlnx_msn2700-r0",
736737
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t0-version_1_0_2.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@
737737
"default_pfcwd_status": "disable",
738738
"bgp_asn": "65100",
739739
"deployment_id": "1",
740-
"type": "ToRRouter"
740+
"type": "ToRRouter",
741+
"synchronous_mode": "enable"
741742
},
742743
"PORT|Ethernet0": {
743744
"lanes": "0,1,2,3",

tests/db_migrator_input/config_db/acs-msn2700-t0-version_1_0_3.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@
737737
"default_pfcwd_status": "disable",
738738
"bgp_asn": "65100",
739739
"deployment_id": "1",
740-
"type": "ToRRouter"
740+
"type": "ToRRouter",
741+
"synchronous_mode": "enable"
741742
},
742743
"PORT|Ethernet0": {
743744
"lanes": "0,1,2,3",

tests/db_migrator_input/config_db/acs-msn2700-t0-version_1_0_4.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@
737737
"default_pfcwd_status": "disable",
738738
"bgp_asn": "65100",
739739
"deployment_id": "1",
740-
"type": "ToRRouter"
740+
"type": "ToRRouter",
741+
"synchronous_mode": "enable"
741742
},
742743
"PORT|Ethernet0": {
743744
"lanes": "0,1,2,3",

tests/db_migrator_input/config_db/acs-msn2700-t0-version_1_0_5.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@
737737
"default_pfcwd_status": "disable",
738738
"bgp_asn": "65100",
739739
"deployment_id": "1",
740-
"type": "ToRRouter"
740+
"type": "ToRRouter",
741+
"synchronous_mode": "enable"
741742
},
742743
"PORT|Ethernet0": {
743744
"lanes": "0,1,2,3",

tests/db_migrator_input/config_db/acs-msn2700-t0-version_1_0_6.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@
737737
"default_pfcwd_status": "disable",
738738
"bgp_asn": "65100",
739739
"deployment_id": "1",
740-
"type": "ToRRouter"
740+
"type": "ToRRouter",
741+
"synchronous_mode": "enable"
741742
},
742743
"PORT|Ethernet0": {
743744
"lanes": "0,1,2,3",

tests/db_migrator_input/config_db/acs-msn2700-t0-version_3_0_0.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@
689689
"bgp_asn": "65100",
690690
"buffer_model": "dynamic",
691691
"deployment_id": "1",
692-
"type": "ToRRouter"
692+
"type": "ToRRouter",
693+
"synchronous_mode": "enable"
693694
},
694695
"LOSSLESS_TRAFFIC_PATTERN|AZURE": {
695696
"small_packet_percentage": "100",

tests/db_migrator_input/config_db/acs-msn2700-t0-version_3_0_3.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@
689689
"bgp_asn": "65100",
690690
"buffer_model": "dynamic",
691691
"deployment_id": "1",
692-
"type": "ToRRouter"
692+
"type": "ToRRouter",
693+
"synchronous_mode": "enable"
693694
},
694695
"LOSSLESS_TRAFFIC_PATTERN|AZURE": {
695696
"small_packet_percentage": "100",
@@ -1016,4 +1017,4 @@
10161017
"VERSIONS|DATABASE": {
10171018
"VERSION": "version_3_0_3"
10181019
}
1019-
}
1020+
}

tests/db_migrator_input/config_db/acs-msn2700-t1-version_1_0_1.json

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@
824824
"hwsku": "ACS-MSN2700",
825825
"default_bgp_status": "up",
826826
"type": "LeafRouter",
827+
"synchronous_mode": "enable",
827828
"hostname": "sonic",
828829
"platform": "x86_64-mlnx_msn2700-r0",
829830
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t1-version_1_0_2.json

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@
824824
"hwsku": "ACS-MSN2700",
825825
"default_bgp_status": "up",
826826
"type": "LeafRouter",
827+
"synchronous_mode": "enable",
827828
"hostname": "sonic",
828829
"platform": "x86_64-mlnx_msn2700-r0",
829830
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t1-version_1_0_3.json

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@
824824
"hwsku": "ACS-MSN2700",
825825
"default_bgp_status": "up",
826826
"type": "LeafRouter",
827+
"synchronous_mode": "enable",
827828
"hostname": "sonic",
828829
"platform": "x86_64-mlnx_msn2700-r0",
829830
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t1-version_1_0_4.json

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@
824824
"hwsku": "ACS-MSN2700",
825825
"default_bgp_status": "up",
826826
"type": "LeafRouter",
827+
"synchronous_mode": "enable",
827828
"hostname": "sonic",
828829
"platform": "x86_64-mlnx_msn2700-r0",
829830
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t1-version_1_0_5.json

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@
824824
"hwsku": "ACS-MSN2700",
825825
"default_bgp_status": "up",
826826
"type": "LeafRouter",
827+
"synchronous_mode": "enable",
827828
"hostname": "sonic",
828829
"platform": "x86_64-mlnx_msn2700-r0",
829830
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t1-version_1_0_6.json

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@
824824
"hwsku": "ACS-MSN2700",
825825
"default_bgp_status": "up",
826826
"type": "LeafRouter",
827+
"synchronous_mode": "enable",
827828
"hostname": "sonic",
828829
"platform": "x86_64-mlnx_msn2700-r0",
829830
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t1-version_3_0_0.json

+1
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@
754754
"hwsku": "ACS-MSN2700",
755755
"default_bgp_status": "up",
756756
"type": "LeafRouter",
757+
"synchronous_mode": "enable",
757758
"hostname": "sonic",
758759
"platform": "x86_64-mlnx_msn2700-r0",
759760
"mac": "00:01:02:03:04:00",

tests/db_migrator_input/config_db/acs-msn2700-t1-version_3_0_3.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@
761761
"bgp_asn": "65100",
762762
"buffer_model": "dynamic",
763763
"deployment_id": "1",
764-
"docker_routing_config_mode": "unified"
764+
"docker_routing_config_mode": "unified",
765+
"synchronous_mode": "enable"
765766
},
766767
"LOSSLESS_TRAFFIC_PATTERN|AZURE": {
767768
"small_packet_percentage": "100",
@@ -1088,4 +1089,4 @@
10881089
"VERSIONS|DATABASE": {
10891090
"VERSION": "version_3_0_3"
10901091
}
1091-
}
1092+
}

tests/db_migrator_input/config_db/acs-msn3700-t0-version_1_0_2.json

+1
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@
738738
"hwsku": "ACS-MSN3700",
739739
"default_bgp_status": "up",
740740
"type": "ToRRouter",
741+
"synchronous_mode": "enable",
741742
"region": "None",
742743
"hostname": "sonic",
743744
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t0-version_1_0_3.json

+1
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@
864864
"hwsku": "ACS-MSN3700",
865865
"default_bgp_status": "up",
866866
"type": "ToRRouter",
867+
"synchronous_mode": "enable",
867868
"region": "None",
868869
"hostname": "sonic",
869870
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t0-version_1_0_4.json

+1
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@
864864
"hwsku": "ACS-MSN3700",
865865
"default_bgp_status": "up",
866866
"type": "ToRRouter",
867+
"synchronous_mode": "enable",
867868
"region": "None",
868869
"hostname": "sonic",
869870
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t0-version_1_0_5.json

+1
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@
864864
"hwsku": "ACS-MSN3700",
865865
"default_bgp_status": "up",
866866
"type": "ToRRouter",
867+
"synchronous_mode": "enable",
867868
"region": "None",
868869
"hostname": "sonic",
869870
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t0-version_1_0_6.json

+1
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@
864864
"hwsku": "ACS-MSN3700",
865865
"default_bgp_status": "up",
866866
"type": "ToRRouter",
867+
"synchronous_mode": "enable",
867868
"region": "None",
868869
"hostname": "sonic",
869870
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t0-version_3_0_0.json

+1
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@
808808
"hwsku": "ACS-MSN3700",
809809
"default_bgp_status": "up",
810810
"type": "ToRRouter",
811+
"synchronous_mode": "enable",
811812
"region": "None",
812813
"hostname": "sonic",
813814
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t0-version_3_0_3.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,8 @@
817817
"buffer_model": "dynamic",
818818
"deployment_id": "1",
819819
"docker_routing_config_mode": "separated",
820-
"cloudtype": "None"
820+
"cloudtype": "None",
821+
"synchronous_mode": "enable"
821822
},
822823
"LOSSLESS_TRAFFIC_PATTERN|AZURE": {
823824
"small_packet_percentage": "100",
@@ -1902,4 +1903,4 @@
19021903
"VERSIONS|DATABASE": {
19031904
"VERSION": "version_3_0_3"
19041905
}
1905-
}
1906+
}

tests/db_migrator_input/config_db/acs-msn3700-t1-version_1_0_2.json

+1
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@
838838
"hwsku": "ACS-MSN3700",
839839
"default_bgp_status": "up",
840840
"type": "LeafRouter",
841+
"synchronous_mode": "enable",
841842
"region": "None",
842843
"hostname": "sonic",
843844
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t1-version_1_0_3.json

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@
940940
"hwsku": "ACS-MSN3700",
941941
"default_bgp_status": "up",
942942
"type": "LeafRouter",
943+
"synchronous_mode": "enable",
943944
"region": "None",
944945
"hostname": "sonic",
945946
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t1-version_1_0_4.json

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@
940940
"hwsku": "ACS-MSN3700",
941941
"default_bgp_status": "up",
942942
"type": "LeafRouter",
943+
"synchronous_mode": "enable",
943944
"region": "None",
944945
"hostname": "sonic",
945946
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t1-version_1_0_5.json

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@
940940
"hwsku": "ACS-MSN3700",
941941
"default_bgp_status": "up",
942942
"type": "LeafRouter",
943+
"synchronous_mode": "enable",
943944
"region": "None",
944945
"hostname": "sonic",
945946
"platform": "x86_64-mlnx_msn3700-r0",

tests/db_migrator_input/config_db/acs-msn3700-t1-version_1_0_6.json

+1
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@
940940
"hwsku": "ACS-MSN3700",
941941
"default_bgp_status": "up",
942942
"type": "LeafRouter",
943+
"synchronous_mode": "enable",
943944
"region": "None",
944945
"hostname": "sonic",
945946
"platform": "x86_64-mlnx_msn3700-r0",

0 commit comments

Comments
 (0)