Skip to content

Commit 2e09b22

Browse files
authored
Handle the new db version which mellanox_buffer_migrator isn't interested (#1566)
Enhancement: handle the case that no buffer change in the latest database version Current, the following two versions are the same: - The latest version changed by mellanox_buffer_migrator - The latest version in CONFIG_DB That won't be true if another part in CONFIG_DB is updated. In that case, the latest version in CONFIG_DB will be greater than the latest version in mellanox_buffer_migrator. However, this can break the buffer migrator unit test: - The db_migrator will always migrate the database to the latest version - The config database version check will fail in case the latest version in the config database doesn't match that defined in the buffer migrator. This is to support this case. Signed-off-by: Stephen Sun <[email protected]>
1 parent 08337aa commit 2e09b22

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tests/db_migrator_test.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ def check_appl_db(self, result, expected):
7676
for key in keys:
7777
assert expected.get_all(expected.APPL_DB, key) == result.get_all(result.APPL_DB, key)
7878

79+
def advance_version_for_expected_database(self, migrated_db, expected_db):
80+
# In case there are new db versions greater than the latest one that mellanox buffer migrator is interested,
81+
# we just advance the database version in the expected database to make the test pass
82+
expected_dbversion = expected_db.get_entry('VERSIONS', 'DATABASE')
83+
dbmgtr_dbversion = migrated_db.get_entry('VERSIONS', 'DATABASE')
84+
if expected_dbversion and dbmgtr_dbversion:
85+
if expected_dbversion['VERSION'] == self.version_list[-1] and dbmgtr_dbversion['VERSION'] > expected_dbversion['VERSION']:
86+
expected_dbversion['VERSION'] = dbmgtr_dbversion['VERSION']
87+
expected_db.set_entry('VERSIONS', 'DATABASE', expected_dbversion)
88+
7989
@pytest.mark.parametrize('scenario',
8090
['empty-config',
8191
'non-default-config',
@@ -93,6 +103,7 @@ def test_mellanox_buffer_migrator_negative_cold_reboot(self, scenario):
93103
dbmgtr = db_migrator.DBMigrator(None)
94104
dbmgtr.migrate()
95105
expected_db = self.mock_dedicated_config_db(db_after_migrate)
106+
self.advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb)
96107
self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)
97108
assert not dbmgtr.mellanox_buffer_migrator.is_buffer_config_default
98109

@@ -119,8 +130,6 @@ def test_mellanox_buffer_migrator_for_cold_reboot(self, sku_version, topo):
119130
sku, start_version = sku_version
120131
version = start_version
121132
start_index = self.version_list.index(start_version)
122-
# Eventually, the config db should be migrated to the latest version
123-
expected_db = self.mock_dedicated_config_db(self.make_db_name_by_sku_topo_version(sku, topo, self.version_list[-1]))
124133

125134
# start_version represents the database version from which the SKU is supported
126135
# For each SKU,
@@ -130,6 +139,9 @@ def test_mellanox_buffer_migrator_for_cold_reboot(self, sku_version, topo):
130139
import db_migrator
131140
dbmgtr = db_migrator.DBMigrator(None)
132141
dbmgtr.migrate()
142+
# Eventually, the config db should be migrated to the latest version
143+
expected_db = self.mock_dedicated_config_db(self.make_db_name_by_sku_topo_version(sku, topo, self.version_list[-1]))
144+
self.advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb)
133145
self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)
134146
assert dbmgtr.mellanox_buffer_migrator.is_buffer_config_default
135147

@@ -145,6 +157,7 @@ def mellanox_buffer_migrator_warm_reboot_runner(self, input_config_db, input_app
145157
import db_migrator
146158
dbmgtr = db_migrator.DBMigrator(None)
147159
dbmgtr.migrate()
160+
self.advance_version_for_expected_database(dbmgtr.configDB, expected_config_db.cfgdb)
148161
assert dbmgtr.mellanox_buffer_migrator.is_buffer_config_default == is_buffer_config_default_expected
149162
self.check_config_db(dbmgtr.configDB, expected_config_db.cfgdb)
150163
self.check_appl_db(dbmgtr.appDB, expected_appl_db)
@@ -173,6 +186,7 @@ def test_mellanox_buffer_migrator_for_warm_reboot(self, sku, topo):
173186
self.mellanox_buffer_migrator_warm_reboot_runner(input_db_name, input_db_name, expected_db_name, expected_db_name, True)
174187

175188
def test_mellanox_buffer_migrator_negative_nondefault_for_warm_reboot(self):
189+
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
176190
expected_config_db = 'non-default-config-expected'
177191
expected_appl_db = 'non-default-expected'
178192
input_config_db = 'non-default-config-input'

0 commit comments

Comments
 (0)