|
5 | 5 | import argparse
|
6 | 6 | import syslog
|
7 | 7 | from swsssdk import ConfigDBConnector
|
| 8 | +import sonic_device_util |
| 9 | +import os |
| 10 | +import subprocess |
| 11 | +import json |
8 | 12 |
|
9 | 13 |
|
10 | 14 | SYSLOG_IDENTIFIER = 'db_migrator'
|
@@ -35,7 +39,7 @@ def __init__(self, socket=None):
|
35 | 39 | none-zero values.
|
36 | 40 | build: sequentially increase within a minor version domain.
|
37 | 41 | """
|
38 |
| - self.CURRENT_VERSION = 'version_1_0_2' |
| 42 | + self.CURRENT_VERSION = 'version_1_0_3' |
39 | 43 |
|
40 | 44 | self.TABLE_NAME = 'VERSIONS'
|
41 | 45 | self.TABLE_KEY = 'DATABASE'
|
@@ -96,6 +100,100 @@ def migrate_interface_table(self):
|
96 | 100 | self.configDB.set_entry(table, key[0], data[key])
|
97 | 101 | if_db.append(key[0])
|
98 | 102 |
|
| 103 | + def mlnx_migrate_buffer_pool_size(self): |
| 104 | + """ |
| 105 | + On Mellanox platform the buffer pool size changed since |
| 106 | + version with new SDK 4.3.3052, SONiC to SONiC update |
| 107 | + from version with old SDK will be broken without migration. |
| 108 | + This migration is specifically for Mellanox platform. |
| 109 | + """ |
| 110 | + # Buffer pools defined in version 1_0_2 |
| 111 | + buffer_pools = ['ingress_lossless_pool', 'egress_lossless_pool', 'ingress_lossy_pool', 'egress_lossy_pool'] |
| 112 | + |
| 113 | + # Old default buffer pool values on Mellanox platform |
| 114 | + spc1_t0_default_value = [{'ingress_lossless_pool': '4194304'}, {'egress_lossless_pool': '16777152'}, {'ingress_lossy_pool': '7340032'}, {'egress_lossy_pool': '7340032'}] |
| 115 | + spc1_t1_default_value = [{'ingress_lossless_pool': '2097152'}, {'egress_lossless_pool': '16777152'}, {'ingress_lossy_pool': '5242880'}, {'egress_lossy_pool': '5242880'}] |
| 116 | + spc2_t0_default_value = [{'ingress_lossless_pool': '8224768'}, {'egress_lossless_pool': '35966016'}, {'ingress_lossy_pool': '8224768'}, {'egress_lossy_pool': '8224768'}] |
| 117 | + spc2_t1_default_value = [{'ingress_lossless_pool': '12042240'}, {'egress_lossless_pool': '35966016'}, {'ingress_lossy_pool': '12042240'}, {'egress_lossy_pool': '12042240'}] |
| 118 | + |
| 119 | + # New default buffer pool configuration on Mellanox platform |
| 120 | + spc1_t0_default_config = {"ingress_lossless_pool": { "size": "5029836", "type": "ingress", "mode": "dynamic" }, |
| 121 | + "ingress_lossy_pool": { "size": "5029836", "type": "ingress", "mode": "dynamic" }, |
| 122 | + "egress_lossless_pool": { "size": "14024599", "type": "egress", "mode": "dynamic" }, |
| 123 | + "egress_lossy_pool": {"size": "5029836", "type": "egress", "mode": "dynamic" } } |
| 124 | + spc1_t1_default_config = {"ingress_lossless_pool": { "size": "2097100", "type": "ingress", "mode": "dynamic" }, |
| 125 | + "ingress_lossy_pool": { "size": "2097100", "type": "ingress", "mode": "dynamic" }, |
| 126 | + "egress_lossless_pool": { "size": "14024599", "type": "egress", "mode": "dynamic" }, |
| 127 | + "egress_lossy_pool": {"size": "2097100", "type": "egress", "mode": "dynamic" } } |
| 128 | + spc2_t0_default_config = {"ingress_lossless_pool": { "size": "14983147", "type": "ingress", "mode": "dynamic" }, |
| 129 | + "ingress_lossy_pool": { "size": "14983147", "type": "ingress", "mode": "dynamic" }, |
| 130 | + "egress_lossless_pool": { "size": "34340822", "type": "egress", "mode": "dynamic" }, |
| 131 | + "egress_lossy_pool": {"size": "14983147", "type": "egress", "mode": "dynamic" } } |
| 132 | + spc2_t1_default_config = {"ingress_lossless_pool": { "size": "9158635", "type": "ingress", "mode": "dynamic" }, |
| 133 | + "ingress_lossy_pool": { "size": "9158635", "type": "ingress", "mode": "dynamic" }, |
| 134 | + "egress_lossless_pool": { "size": "34340822", "type": "egress", "mode": "dynamic" }, |
| 135 | + "egress_lossy_pool": {"size": "9158635", "type": "egress", "mode": "dynamic" } } |
| 136 | + # 3800 platform has gearbox installed so the buffer pool size is different with other Spectrum2 platform |
| 137 | + spc2_3800_t0_default_config = {"ingress_lossless_pool": { "size": "28196784", "type": "ingress", "mode": "dynamic" }, |
| 138 | + "ingress_lossy_pool": { "size": "28196784", "type": "ingress", "mode": "dynamic" }, |
| 139 | + "egress_lossless_pool": { "size": "34340832", "type": "egress", "mode": "dynamic" }, |
| 140 | + "egress_lossy_pool": {"size": "28196784", "type": "egress", "mode": "dynamic" } } |
| 141 | + spc2_3800_t1_default_config = {"ingress_lossless_pool": { "size": "17891280", "type": "ingress", "mode": "dynamic" }, |
| 142 | + "ingress_lossy_pool": { "size": "17891280", "type": "ingress", "mode": "dynamic" }, |
| 143 | + "egress_lossless_pool": { "size": "34340832", "type": "egress", "mode": "dynamic" }, |
| 144 | + "egress_lossy_pool": {"size": "17891280", "type": "egress", "mode": "dynamic" } } |
| 145 | + |
| 146 | + # Try to get related info from DB |
| 147 | + buffer_pool_conf = {} |
| 148 | + device_data = self.configDB.get_table('DEVICE_METADATA') |
| 149 | + if 'localhost' in device_data.keys(): |
| 150 | + hwsku = device_data['localhost']['hwsku'] |
| 151 | + platform = device_data['localhost']['platform'] |
| 152 | + else: |
| 153 | + log_error("Trying to get DEVICE_METADATA from DB but doesn't exist, skip migration") |
| 154 | + return False |
| 155 | + buffer_pool_conf = self.configDB.get_table('BUFFER_POOL') |
| 156 | + |
| 157 | + # Get current buffer pool configuration, only migrate configuration which |
| 158 | + # with default values, if it's not default, leave it as is. |
| 159 | + pool_size_in_db_list = [] |
| 160 | + pools_in_db = buffer_pool_conf.keys() |
| 161 | + |
| 162 | + # Buffer pool numbers is different with default, don't need migrate |
| 163 | + if len(pools_in_db) != len(buffer_pools): |
| 164 | + return True |
| 165 | + |
| 166 | + # If some buffer pool is not default ones, don't need migrate |
| 167 | + for buffer_pool in buffer_pools: |
| 168 | + if buffer_pool not in pools_in_db: |
| 169 | + return True |
| 170 | + pool_size_in_db_list.append({buffer_pool: buffer_pool_conf[buffer_pool]['size']}) |
| 171 | + |
| 172 | + # To check if the buffer pool size is equal to old default values |
| 173 | + new_buffer_pool_conf = None |
| 174 | + if pool_size_in_db_list == spc1_t0_default_value: |
| 175 | + new_buffer_pool_conf = spc1_t0_default_config |
| 176 | + elif pool_size_in_db_list == spc1_t1_default_value: |
| 177 | + new_buffer_pool_conf = spc1_t1_default_config |
| 178 | + elif pool_size_in_db_list == spc2_t0_default_value: |
| 179 | + if platform == 'x86_64-mlnx_msn3800-r0': |
| 180 | + new_buffer_pool_conf = spc2_3800_t0_default_config |
| 181 | + else: |
| 182 | + new_buffer_pool_conf = spc2_t0_default_config |
| 183 | + elif pool_size_in_db_list == spc2_t1_default_value: |
| 184 | + if platform == 'x86_64-mlnx_msn3800-r0': |
| 185 | + new_buffer_pool_conf = spc2_3800_t1_default_config |
| 186 | + else: |
| 187 | + new_buffer_pool_conf = spc2_t1_default_config |
| 188 | + else: |
| 189 | + # It's not using default buffer pool configuration, no migration needed. |
| 190 | + log_info("buffer pool size is not old default value, no need to migrate") |
| 191 | + return True |
| 192 | + # Migrate old buffer conf to latest. |
| 193 | + for pool in buffer_pools: |
| 194 | + self.configDB.set_entry('BUFFER_POOL', pool, new_buffer_pool_conf[pool]) |
| 195 | + log_info("Successfully migrate mlnx buffer pool size to the latest.") |
| 196 | + return True |
99 | 197 |
|
100 | 198 | def version_unknown(self):
|
101 | 199 | """
|
@@ -127,13 +225,27 @@ def version_1_0_1(self):
|
127 | 225 |
|
128 | 226 | self.migrate_interface_table()
|
129 | 227 | self.set_version('version_1_0_2')
|
130 |
| - return None |
| 228 | + return 'version_1_0_2' |
131 | 229 |
|
132 | 230 | def version_1_0_2(self):
|
133 | 231 | """
|
134 |
| - Current latest version. Nothing to do here. |
| 232 | + Version 1_0_2. |
135 | 233 | """
|
136 | 234 | log_info('Handling version_1_0_2')
|
| 235 | + # Check ASIC type, if Mellanox platform then need DB migration |
| 236 | + version_info = sonic_device_util.get_sonic_version_info() |
| 237 | + if version_info['asic_type'] == "mellanox": |
| 238 | + if self.mlnx_migrate_buffer_pool_size(): |
| 239 | + self.set_version('version_1_0_3') |
| 240 | + else: |
| 241 | + self.set_version('version_1_0_3') |
| 242 | + return None |
| 243 | + |
| 244 | + def version_1_0_3(self): |
| 245 | + """ |
| 246 | + Current latest version. Nothing to do here. |
| 247 | + """ |
| 248 | + log_info('Handling version_1_0_3') |
137 | 249 |
|
138 | 250 | return None
|
139 | 251 |
|
|
0 commit comments