Skip to content

Commit aa7a3a3

Browse files
vaibhavhdMuhammad Danish
authored and
Muhammad Danish
committed
Port 202012 DB migration changes to newer branches (sonic-net#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 3c8b7d7 commit aa7a3a3

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

@@ -489,6 +491,61 @@ def migrate_qos_fieldval_reference_format(self):
489491
self.migrate_qos_db_fieldval_reference_remove(qos_table_list, self.configDB, self.configDB.CONFIG_DB, '|')
490492
return True
491493

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

652709
def version_2_0_1(self):
653710
"""
654-
Version 2_0_1.
655-
This is the latest version for 202012 branch
711+
Handle and migrate missing config that results from cross branch upgrade to
712+
202012 as target.
656713
"""
657714
log.log_info('Handling version_2_0_1')
715+
self.migrate_vxlan_config()
716+
self.migrate_restapi()
717+
self.migrate_telemetry()
718+
self.migrate_console_switch()
719+
self.migrate_device_metadata()
720+
721+
self.set_version('version_2_0_2')
722+
return 'version_2_0_2'
723+
724+
def version_2_0_2(self):
725+
"""
726+
Version 2_0_2
727+
This is the latest version for 202012 branch
728+
"""
729+
log.log_info('Handling version_2_0_2')
658730
self.set_version('version_3_0_0')
659731
return 'version_3_0_0'
660732

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)