-
Notifications
You must be signed in to change notification settings - Fork 711
[db_migrator] Fix migration of Loopback data: handle all Loopback interfaces #2560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,24 +178,33 @@ def migrate_intf_table(self): | |
if self.appDB is None: | ||
return | ||
|
||
data = self.appDB.keys(self.appDB.APPL_DB, "INTF_TABLE:*") | ||
|
||
if data is None: | ||
# Get Lo interface corresponding to IP(v4/v6) address from CONFIG_DB. | ||
configdb_data = self.configDB.get_keys('LOOPBACK_INTERFACE') | ||
lo_addr_to_int = dict() | ||
for int_data in configdb_data: | ||
if type(int_data) == tuple and len(int_data) > 1: | ||
intf_name = int_data[0] | ||
intf_addr = int_data[1] | ||
lo_addr_to_int.update({intf_addr: intf_name}) | ||
|
||
lo_data = self.appDB.keys(self.appDB.APPL_DB, "INTF_TABLE:lo*") | ||
if lo_data is None: | ||
return | ||
for lo_row in lo_data: | ||
# Example of lo_row: 'INTF_TABLE:lo:10.1.0.32/32' | ||
# Example of lo_dict: {'family': 'IPv4', 'scope': 'global'} | ||
lo_dict = self.appDB.get_all(self.appDB.APPL_DB, lo_row) | ||
lo_addr = lo_row.split('INTF_TABLE:lo:')[1] | ||
lo_name = lo_addr_to_int.get(lo_addr) | ||
lo_table = "INTF_TABLE:" + lo_name + ":" + lo_addr | ||
for key, value in lo_dict.items(): | ||
log.log_notice("Set table {} with field {} and value {}".format( | ||
lo_table, key, value)) | ||
self.appDB.set(self.appDB.APPL_DB, lo_table, key, value) | ||
# delete the old row with name as 'lo' as new row has been added | ||
self.appDB.delete(self.appDB.APPL_DB, lo_row) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are deleting the iterating element in the loop. Not sure if it can cause issues. Why don't we use the same logic as before and just replace the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this in latest - removed the inner loop (handling of field, value). In the updated logic, only name |
||
|
||
if_db = [] | ||
for key in data: | ||
if_name = key.split(":")[1] | ||
if if_name == "lo": | ||
self.appDB.delete(self.appDB.APPL_DB, key) | ||
key = key.replace(if_name, "Loopback0") | ||
log.log_info('Migrating lo entry to ' + key) | ||
self.appDB.set(self.appDB.APPL_DB, key, 'NULL', 'NULL') | ||
|
||
if '/' not in key: | ||
if_db.append(key.split(":")[1]) | ||
continue | ||
|
||
data = self.appDB.keys(self.appDB.APPL_DB, "INTF_TABLE:*") | ||
for key in data: | ||
if_name = key.split(":")[1] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"INTF_TABLE:Loopback0" : {"NULL": "NULL"}, | ||
"INTF_TABLE:Loopback0:10.1.0.32/32" : { | ||
"scope": "global", | ||
"family": "IPv4" | ||
}, | ||
"INTF_TABLE:Loopback0:FC00:1::32/128" : { | ||
"scope": "global", | ||
"family": "IPv6" | ||
}, | ||
"INTF_TABLE:Loopback1" : {"NULL": "NULL"}, | ||
"INTF_TABLE:Loopback1:10.20.8.199/32" : { | ||
"scope": "global", | ||
"family": "IPv4" | ||
}, | ||
"INTF_TABLE:Loopback1:2001:506:28:500::1/128" : { | ||
"scope": "global", | ||
"family": "IPv6" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"INTF_TABLE:lo:10.1.0.32/32" : { | ||
"scope": "global", | ||
"family": "IPv4" | ||
}, | ||
"INTF_TABLE:lo:FC00:1::32/128" : { | ||
"scope": "global", | ||
"family": "IPv6" | ||
}, | ||
"INTF_TABLE:lo:10.20.8.199/32" : { | ||
"scope": "global", | ||
"family": "IPv4" | ||
}, | ||
"INTF_TABLE:lo:2001:506:28:500::1/128" : { | ||
"scope": "global", | ||
"family": "IPv6" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"LOOPBACK_INTERFACE|Loopback0" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback0|10.1.0.32/32" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback0|FC00:1::32/128" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback1" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback1|10.20.8.199/32" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback1|2001:506:28:500::1/128" : {"NULL": "NULL"} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"LOOPBACK_INTERFACE|Loopback0|10.1.0.32/32" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback0|FC00:1::32/128" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback1|10.20.8.199/32" : {"NULL": "NULL"}, | ||
"LOOPBACK_INTERFACE|Loopback1|2001:506:28:500::1/128" : {"NULL": "NULL"}, | ||
"VERSIONS|DATABASE": {"VERSION": "version_1_0_1"} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A logical difference from previous implementation is that, if config_db data is empty, previously we hardcode to 'Loopback0' whereas here it will come as empty which can cause swss crash. For safe side, I suggest if 'lo_name' is empty use the previous logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, addressed this in latest.