Skip to content

Commit

Permalink
[202311][db_migrator] add db migrator version space for 202305/202311…
Browse files Browse the repository at this point in the history
… branch

Signed-off-by: Ying Xie <ying.xie@microsoft.com>
  • Loading branch information
yxieca committed Dec 16, 2023
1 parent 1b1402f commit 004aeb7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
31 changes: 28 additions & 3 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
class DBMigrator():
def __init__(self, namespace, socket=None):
"""
Version string format:
Version string format (202305 and above):
version_<branch>_<build>
branch: master, 202311, 202305, etc.
build: sequentially increase with leading 0 to make it 2 digits.
because the minor number has been removed to make it different
from the old format, adding a leading 0 to make sure that we
have double digit version number spaces.
Version string format (before 202305):
version_<major>_<minor>_<build>
major: starting from 1, sequentially incrementing in master
branch.
Expand All @@ -47,7 +54,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_202311_01'

self.TABLE_NAME = 'VERSIONS'
self.TABLE_KEY = 'DATABASE'
Expand Down Expand Up @@ -1095,9 +1102,27 @@ 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_202305_01')
return 'version_202305_01'

def version_202305_01(self):
"""
Version 202305_01.
This is current last erversion for 202305 branch
"""
log.log_info('Handling version_202305_01')
self.set_version('version_202311_01')
return 'version_202311_01'

def version_202311_01(self):
"""
Version 202311_01.
This is current last erversion for 202311 branch
"""
log.log_info('Handling version_202311_01')
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 004aeb7

Please sign in to comment.