Skip to content

Commit

Permalink
Handle the new db version which mellanox_buffer_migrator isn't intere…
Browse files Browse the repository at this point in the history
…sted (sonic-net#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 <stephens@nvidia.com>
  • Loading branch information
stephenxs committed May 3, 2021
1 parent 08337aa commit 2e09b22
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def check_appl_db(self, result, expected):
for key in keys:
assert expected.get_all(expected.APPL_DB, key) == result.get_all(result.APPL_DB, key)

def advance_version_for_expected_database(self, migrated_db, expected_db):
# In case there are new db versions greater than the latest one that mellanox buffer migrator is interested,
# we just advance the database version in the expected database to make the test pass
expected_dbversion = expected_db.get_entry('VERSIONS', 'DATABASE')
dbmgtr_dbversion = migrated_db.get_entry('VERSIONS', 'DATABASE')
if expected_dbversion and dbmgtr_dbversion:
if expected_dbversion['VERSION'] == self.version_list[-1] and dbmgtr_dbversion['VERSION'] > expected_dbversion['VERSION']:
expected_dbversion['VERSION'] = dbmgtr_dbversion['VERSION']
expected_db.set_entry('VERSIONS', 'DATABASE', expected_dbversion)

@pytest.mark.parametrize('scenario',
['empty-config',
'non-default-config',
Expand All @@ -93,6 +103,7 @@ def test_mellanox_buffer_migrator_negative_cold_reboot(self, scenario):
dbmgtr = db_migrator.DBMigrator(None)
dbmgtr.migrate()
expected_db = self.mock_dedicated_config_db(db_after_migrate)
self.advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb)
self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)
assert not dbmgtr.mellanox_buffer_migrator.is_buffer_config_default

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

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

Expand All @@ -145,6 +157,7 @@ def mellanox_buffer_migrator_warm_reboot_runner(self, input_config_db, input_app
import db_migrator
dbmgtr = db_migrator.DBMigrator(None)
dbmgtr.migrate()
self.advance_version_for_expected_database(dbmgtr.configDB, expected_config_db.cfgdb)
assert dbmgtr.mellanox_buffer_migrator.is_buffer_config_default == is_buffer_config_default_expected
self.check_config_db(dbmgtr.configDB, expected_config_db.cfgdb)
self.check_appl_db(dbmgtr.appDB, expected_appl_db)
Expand Down Expand Up @@ -173,6 +186,7 @@ def test_mellanox_buffer_migrator_for_warm_reboot(self, sku, topo):
self.mellanox_buffer_migrator_warm_reboot_runner(input_db_name, input_db_name, expected_db_name, expected_db_name, True)

def test_mellanox_buffer_migrator_negative_nondefault_for_warm_reboot(self):
device_info.get_sonic_version_info = get_sonic_version_info_mlnx
expected_config_db = 'non-default-config-expected'
expected_appl_db = 'non-default-expected'
input_config_db = 'non-default-config-input'
Expand Down

0 comments on commit 2e09b22

Please sign in to comment.