Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 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_3'
self.CURRENT_VERSION = 'version_4_0_4'

self.TABLE_NAME = 'VERSIONS'
self.TABLE_KEY = 'DATABASE'
Expand Down Expand Up @@ -636,6 +636,18 @@ def migrate_route_table(self):
if 'protocol' not in route_attr:
self.appDB.set(self.appDB.APPL_DB, route_key, 'protocol', '')

def migrate_dns_nameserver(self):
"""
Handle DNS_NAMESERVER table migration. Migrations handled:
If there's no DNS_NAMESERVER in config_DB, load DNS_NAMESERVER from minigraph
"""
if not self.minigraph_data or 'DNS_NAMESERVER' not in self.minigraph_data:
return
dns_table = self.configDB.get_table('DNS_NAMESERVER')
if not dns_table:
for addr, config in self.minigraph_data['DNS_NAMESERVER'].items():
self.configDB.set_entry('DNS_NAMESERVER', addr, config)

def update_edgezone_aggregator_config(self):
"""
Update cable length configuration in ConfigDB for T0 neighbor interfaces
Expand Down Expand Up @@ -1004,9 +1016,19 @@ def version_4_0_2(self):
def version_4_0_3(self):
"""
Version 4_0_3.
This is the latest version for master branch
"""
log.log_info('Handling version_4_0_3')
self.set_version('version_4_0_4')
return 'version_4_0_4'

def version_4_0_4(self):
"""
Version 4_0_4.
This is the latest version for master branch
"""
log.log_info('Handling version_4_0_4')
# Updating DNS nameserver
self.migrate_dns_nameserver()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You updated the existing version, but did not create a new version.

Please add new version handler here as a placeholder.

Also, when you do that please also update the self.CURRENT_VERSION to the new version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

return None

def get_version(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/db_migrator_input/config_db/dns-nameserver-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"DNS_NAMESERVER|1.1.1.1": {
"state": "enabled"
},
"DNS_NAMESERVER|2001:1001:110:1001::1": {
"state": "enabled"
},
"VERSIONS|DATABASE": {
"VERSION": "version_4_0_4"
}
}
5 changes: 5 additions & 0 deletions tests/db_migrator_input/config_db/dns-nameserver-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"VERSIONS|DATABASE": {
"VERSION": "version_4_0_3"
}
}
32 changes: 32 additions & 0 deletions tests/db_migrator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,37 @@ def test_lacp_key_migrator(self):
assert dbmgtr.configDB.get_table('PORTCHANNEL') == expected_db.cfgdb.get_table('PORTCHANNEL')
assert dbmgtr.configDB.get_table('VERSIONS') == expected_db.cfgdb.get_table('VERSIONS')

class TestDnsNameserverMigrator(object):
@classmethod
def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "2"

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
dbconnector.dedicated_dbs['CONFIG_DB'] = None

def test_dns_nameserver_migrator(self):
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'dns-nameserver-input')
import db_migrator
dbmgtr = db_migrator.DBMigrator(None)
# Set minigraph_data to DNS_NAMESERVERS
dbmgtr.minigraph_data = {
'DNS_NAMESERVER': {
'1.1.1.1': {},
'2001:1001:110:1001::1': {}
}
}
dbmgtr.migrate()
dbconnector.dedicated_dbs['CONFIG_DB'] = os.path.join(mock_db_path, 'config_db', 'dns-nameserver-expected')
expected_db = Db()
advance_version_for_expected_database(dbmgtr.configDB, expected_db.cfgdb, 'version_4_0_4')
resulting_keys = dbmgtr.configDB.keys(dbmgtr.configDB.CONFIG_DB, 'DNS_NAMESERVER*')
expected_keys = expected_db.cfgdb.keys(expected_db.cfgdb.CONFIG_DB, 'DNS_NAMESERVER*')

diff = DeepDiff(resulting_keys, expected_keys, ignore_order=True)
assert not diff

class TestQosDBFieldValueReferenceRemoveMigrator(object):
@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -674,5 +705,6 @@ def test_fast_reboot_upgrade_to_4_0_3(self):
dbmgtr = db_migrator.DBMigrator(None)
dbmgtr.migrate()
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']