Skip to content
Merged
Changes from 2 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
49 changes: 37 additions & 12 deletions scripts/fast-reboot-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def generate_neighbor_entries(filename, all_available_macs):
}
arp_output.append(obj)

ip_addr = key.split(':')[2]
ip_addr = key.split(':', 2)[2]
if ipaddress.ip_interface(str(ip_addr)).ip.version != 4:
#This is ipv6 address
ip_addr = key.replace(key.split(':')[0] + ':' + key.split(':')[1] + ':', '')
Expand Down Expand Up @@ -80,23 +80,45 @@ def get_bridge_port_id_2_port_id(db):

return bridge_port_id_2_port_id

def get_map_port_id_2_iface_name(db):
def get_lag_by_member(member_name, app_db):
keys = app_db.keys(app_db.APPL_DB, 'LAG_MEMBER_TABLE:*')
keys = [] if keys is None else keys
for key in keys:
_, lag_name, lag_member_name = key.split(":")
if lag_member_name == member_name:
return lag_name
return None

def get_map_port_id_2_iface_name(asic_db, app_db):
port_id_2_iface = {}
keys = db.keys(db.ASIC_DB, 'ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:*')
keys = asic_db.keys(asic_db.ASIC_DB, 'ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:*')
keys = [] if keys is None else keys
for key in keys:
value = db.get_all(db.ASIC_DB, key)
value = asic_db.get_all(asic_db.ASIC_DB, key)
if value['SAI_HOSTIF_ATTR_TYPE'] != 'SAI_HOSTIF_TYPE_NETDEV':
continue
port_id = value['SAI_HOSTIF_ATTR_OBJ_ID']
iface_name = value['SAI_HOSTIF_ATTR_NAME']
port_id_2_iface[port_id] = iface_name

keys = asic_db.keys(asic_db.ASIC_DB, 'ASIC_STATE:SAI_OBJECT_TYPE_LAG_MEMBER:oid:*')
keys = [] if keys is None else keys
for key in keys:
value = asic_db.get_all(asic_db.ASIC_DB, key)
lag_id = value['SAI_LAG_MEMBER_ATTR_LAG_ID']
if lag_id in port_id_2_iface:
continue
member_id = value['SAI_LAG_MEMBER_ATTR_PORT_ID']
member_name = port_id_2_iface[member_id]
lag_name = get_lag_by_member(member_name, app_db)
if lag_name is not None:
port_id_2_iface[lag_id] = lag_name

return port_id_2_iface

def get_map_bridge_port_id_2_iface_name(db):
bridge_port_id_2_port_id = get_bridge_port_id_2_port_id(db)
port_id_2_iface = get_map_port_id_2_iface_name(db)
def get_map_bridge_port_id_2_iface_name(asic_db, app_db):
bridge_port_id_2_port_id = get_bridge_port_id_2_port_id(asic_db)
port_id_2_iface = get_map_port_id_2_iface_name(asic_db, app_db)

bridge_port_id_2_iface_name = {}

Expand Down Expand Up @@ -160,22 +182,25 @@ def get_fdb(db, vlan_name, vlan_id, bridge_id_2_iface):
def generate_fdb_entries(filename):
fdb_entries = []

db = SonicV2Connector(use_unix_socket_path=False)
db.connect(db.ASIC_DB, False) # Make one attempt only
asic_db = swsssdk.SonicV2Connector(host='127.0.0.1')
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Apr 3, 2021

Choose a reason for hiding this comment

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

swsssdk [](start = 14, length = 7)

swsssdk is deprecated and the import change is alreay merged.

I tested the master latest image plus master latest sonic-utilities

admin@str-msn2700-20:~$ show platform summary
Platform: x86_64-mlnx_msn2700-r0
HwSKU: Mellanox-SN2700-D40C8S8
ASIC: mellanox
ASIC Count: 1
admin@str-msn2700-20:~$ sudo fast-reboot
Failed to run fast-reboot-dump.py. Exit code: 2
admin@str-msn2700-20:~$ sudo fast-reboot-dump.py
admin@str-msn2700-20:~$ echo $?
2

Apr  3 21:59:03.838231 str-msn2700-20 ERR fast-reboot-dump: Got an exception name 'swsssdk' is not defined: Traceback: Traceback (most recent call last):#012  File "/usr/local/bin/fast-reboot-dump.py", line 341, in <module>#012    res = main()#012  File "/usr/local/bin/fast-reboot-dump.py", line 331, in main#012    all_available_macs, map_mac_ip_per_vlan = generate_fdb_entries(root_dir + '/fdb.json')#012  File "/usr/local/bin/fast-reboot-dump.py", line 193, in generate_fdb_entries#012    asic_db = swsssdk.SonicV2Connector(host='127.0.0.1')#012NameError: name 'swsssdk' is not defined
Apr  3 21:59:03.850487 str-msn2700-20 NOTICE admin: fast-reboot failure (12) cleanup ...

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.

how can we avoid this in the future? for example, can we remove swsssdk as a build or test dependency so that the unit test will automatically fail?

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.

The test case does not cover the problematic code, so the exception is not triggered.

app_db = swsssdk.SonicV2Connector(host='127.0.0.1')
asic_db.connect(asic_db.ASIC_DB, False) # Make one attempt only
app_db.connect(app_db.APPL_DB, False) # Make one attempt only

bridge_id_2_iface = get_map_bridge_port_id_2_iface_name(db)
bridge_id_2_iface = get_map_bridge_port_id_2_iface_name(asic_db, app_db)

vlan_ifaces = get_vlan_ifaces()

all_available_macs = set()
map_mac_ip_per_vlan = {}
for vlan in vlan_ifaces:
vlan_id = int(vlan.replace('Vlan', ''))
fdb_entry, available_macs, map_mac_ip_per_vlan[vlan] = get_fdb(db, vlan, vlan_id, bridge_id_2_iface)
fdb_entry, available_macs, map_mac_ip_per_vlan[vlan] = get_fdb(asic_db, vlan, vlan_id, bridge_id_2_iface)
all_available_macs |= available_macs
fdb_entries.extend(fdb_entry)

db.close(db.ASIC_DB)
asic_db.close(asic_db.ASIC_DB)
app_db.close(app_db.APPL_DB)

with open(filename, 'w') as fp:
json.dump(fdb_entries, fp, indent=2, separators=(',', ': '))
Expand Down