Skip to content

Commit 1563769

Browse files
committed
Add unit test for the db_migrator
1 parent ca00de5 commit 1563769

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_3_0_6"
4+
},
5+
"LOGGER|orchagent": {
6+
"LOGLEVEL": "INFO",
7+
"LOGOUTPUT": "SYSLOG"
8+
},
9+
"LOGGER|SAI_API_BUFFER": {
10+
"LOGLEVEL": "SAI_LOG_LEVEL_NOTICE",
11+
"LOGOUTPUT": "SYSLOG"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"VERSIONS|DATABASE": {
3+
"VERSION": "version_3_0_5"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"orchagent:orchagent": {
3+
"LOGLEVEL": "INFO",
4+
"LOGOUTPUT": "SYSLOG"
5+
},
6+
"SAI_API_BUFFER:SAI_API_BUFFER": {
7+
"LOGLEVEL": "SAI_LOG_LEVEL_NOTICE",
8+
"LOGOUTPUT": "SYSLOG"
9+
},
10+
"JINJA2_CACHE": {}
11+
}

tests/db_migrator_test.py

+38
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,42 @@ def test_global_dscp_to_tc_map_migrator(self):
409409
dbmgtr_mlnx.migrate()
410410
resulting_table = dbmgtr_mlnx.configDB.get_table('PORT_QOS_MAP')
411411
assert resulting_table == {}
412+
413+
class TestMoveLoggerTablesInWarmUpgrade(object):
414+
@classmethod
415+
def setup_class(cls):
416+
os.environ['UTILITIES_UNIT_TESTING'] = "2"
417+
418+
@classmethod
419+
def teardown_class(cls):
420+
os.environ['UTILITIES_UNIT_TESTING'] = "0"
421+
dbconnector.dedicated_dbs['CONFIG_DB'] = None
422+
dbconnector.dedicated_dbs['LOGLEVEL_DB'] = None
423+
def mock_dedicated_loglevel_db(self, filename):
424+
jsonfile = os.path.join(mock_db_path, 'loglevel_db', filename)
425+
dbconnector.dedicated_dbs['LOGLEVEL_DB'] = jsonfile
426+
loglevel_db = SonicV2Connector(host='127.0.0.1')
427+
loglevel_db.connect(loglevel_db.LOGLEVEL_DB)
428+
return loglevel_db
429+
430+
def test_move_logger_tables_in_warm_upgrade(self):
431+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'logger_tables_input')
432+
dbconnector.dedicated_dbs['LOGLEVEL_DB'] = os.path.join(mock_db_path, 'loglevel_db', 'logger_tables_input')
433+
import db_migrator
434+
dbmgtr = db_migrator.DBMigrator(None)
435+
dbmgtr.migrate()
436+
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'logger_tables_expected')
437+
dbconnector.dedicated_dbs['LOGLEVEL_DB'] = os.path.join(mock_db_path, 'loglevel_db', 'logger_tables_expected')
438+
439+
expected_db = Db()
440+
441+
resulting_table = dbmgtr.configDB.get_table('LOGGER')
442+
expected_table = expected_db.cfgdb.get_table('LOGGER')
443+
444+
diff = DeepDiff(resulting_table, expected_table, ignore_order=True)
445+
assert not diff
446+
447+
448+
449+
412450

0 commit comments

Comments
 (0)