Skip to content

Commit

Permalink
[202311][db_migrator] add db migrator version space for 202311 branch
Browse files Browse the repository at this point in the history
Signed-off-by: Ying Xie <ying.xie@microsoft.com>
  • Loading branch information
yxieca committed Dec 16, 2023
1 parent 1b1402f commit 0c70af1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
14 changes: 12 additions & 2 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, namespace, socket=None):
none-zero values.
build: sequentially increase within a minor version domain.
"""
self.CURRENT_VERSION = 'version_4_0_5'
self.CURRENT_VERSION = 'version_master_0'

self.TABLE_NAME = 'VERSIONS'
self.TABLE_KEY = 'DATABASE'
Expand Down Expand Up @@ -1095,9 +1095,19 @@ def version_4_0_4(self):
def version_4_0_5(self):
"""
Version 4_0_5.
This is the latest version for master branch
This is the latest version for 202305
"""
log.log_info('Handling version_4_0_5')
self.set_version('version_202311_1')
return 'version_202311_1'

def version_202311_1(self):
"""
Version 202311_1.
This is current last erversion for 202311 branch
"""
log.log_info('Handling version_202311_1')
self.set_version('version_202311_1')
return None

def get_version(self):
Expand Down
34 changes: 32 additions & 2 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,44 @@
def get_sonic_version_info_mlnx():
return {'asic_type': 'mellanox'}

def version_greater_than(v1, v2):
# Return True when v1 is later than v2. Otherwise return False.
if 'master' in v1:
if 'master' in v2:
# both are master versions, directly compare.
return v1 > v2

# v1 is master verson and v2 is not, v1 is higher
return True

if 'master' in v2:
# v2 is master version and v1 is not.
return False

s1 = v1.split('-')
s2 = v2.split('-')
if len(s1) == 3:
# new format version_<barnch>_<ver>
if len(s2) == 3:
# Both are new format version string
return v1 > v2
return True

if len(s2) == 3:
# v2 is new format and v1 is old format.
return False

# Both are old format version_a_b_c
return v1 > v2


def advance_version_for_expected_database(migrated_db, expected_db, last_interested_version):
# 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'] == last_interested_version and dbmgtr_dbversion['VERSION'] > expected_dbversion['VERSION']:
if expected_dbversion['VERSION'] == last_interested_version and version_greater_than(dbmgtr_dbversion['VERSION'], expected_dbversion['VERSION']):
expected_dbversion['VERSION'] = dbmgtr_dbversion['VERSION']
expected_db.set_entry('VERSIONS', 'DATABASE', expected_dbversion)

Expand Down Expand Up @@ -739,7 +769,7 @@ def test_fast_reboot_upgrade_to_4_0_3(self):
expected_db = self.mock_dedicated_config_db(db_after_migrate)
advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb, 'version_4_0_3')
assert not self.check_config_db(dbmgtr.configDB, expected_db.cfgdb)
assert dbmgtr.CURRENT_VERSION == expected_db.cfgdb.get_entry('VERSIONS', 'DATABASE')['VERSION']
assert dbmgtr.CURRENT_VERSION == expected_db.cfgdb.get_entry('VERSIONS', 'DATABASE')['VERSION'], '{} {}'.format(dbmgtr.CURRENT_VERSION, dbmgtr.get_version())

class TestSflowSampleDirectionMigrator(object):
@classmethod
Expand Down

0 comments on commit 0c70af1

Please sign in to comment.