Skip to content

Commit 025483a

Browse files
[RouteUpdater]: Fix multi_asic mock function implementation and multi_asic variable name (#186)
[RouteUpdater]: Fix multi_asic mock function implementation. Update multi_asic mock function to return port_table from config_db was returning empty dictionary due to which RouteUpdater class was not completely unit-tested as one of the condition check was never set to true. **- What I did** 1. Fix multi_asic mock function implementation to get port_table information. There was a mistake in mock_get_port_table function due to which port_table was always empty dictionary. 2. Use multi_asic.get_port_table_for_asic() function as we require port_table only of a specific namespace and do not require the entire port_table. 3. Fix the incorrect multi_asic variable name used in RouteUdpater. Provides fix for sonic-net/sonic-snmpagent#188 **- How I did it** 1. Update multi_asic mock_get_port_table_for_asic implementation. 3. Fix the incorrect multi_asic variable name used in RouteUdpater. **- How to verify it** Load updated docker and query 1.3.6.1.2.1.4.24 MIB. Verify the result. "AttributeError: module 'sonic_py_common.multi_asic' has no attribute 'ROLE'" error message should not be seen in syslog .
1 parent 381ae47 commit 025483a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/sonic_ax_impl/mibs/ietf/rfc4292.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def update_data(self):
6363
# For single-asic platform, front_ns will be empty list.
6464
if front_ns and db_conn.namespace not in front_ns:
6565
continue
66-
port_table = multi_asic.get_port_table(db_conn.namespace)
66+
port_table = multi_asic.get_port_table_for_asic(db_conn.namespace)
6767
ent = db_conn.get_all(mibs.APPL_DB, route_str, blocking=False)
6868
if ent is None:
6969
continue
@@ -75,13 +75,15 @@ def update_data(self):
7575
## This is to workaround the bug in current sonic-swss implementation
7676
if ifn == "eth0" or ifn == "lo" or ifn == "docker0":
7777
continue
78+
7879
# Ignore internal asic routes
7980
if multi_asic.is_port_channel_internal(ifn, db_conn.namespace):
8081
continue
8182
if (ifn in port_table and
82-
multi_asic.ROLE in port_table[ifn] and
83-
port_table[ifn][multi_asic.ROLE] == multi_asic.INTERNAL_PORT):
83+
multi_asic.PORT_ROLE in port_table[ifn] and
84+
port_table[ifn][multi_asic.PORT_ROLE] == multi_asic.INTERNAL_PORT):
8485
continue
86+
8587
sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(ipn.netmask) + (self.tos,) + ip2tuple_v4(nh)
8688
self.route_dest_list.append(sub_id)
8789
self.route_dest_map[sub_id] = ipn.network_address.packed

tests/mock_tables/multi_asic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def mock_is_port_channel_internal(port_channel, namespace=None):
3434
else:
3535
return True if port_channel in int_port_channel else False
3636

37-
def mock_get_port_table(namespace=None):
37+
def mock_get_port_table_for_asic(namespace=None):
3838
if namespace is not None:
3939
fname = os.path.join(INPUT_DIR, namespace, 'config_db.json')
4040
else:
@@ -44,7 +44,7 @@ def mock_get_port_table(namespace=None):
4444
with open(fname) as f:
4545
db = json.load(f)
4646
for k in db:
47-
if 'PORT_TABLE' in db:
47+
if 'PORT_TABLE' in k:
4848
new_key = k[len('PORT_TABLE:'):]
4949
port_table[new_key] = db[k]
5050
return port_table
@@ -53,4 +53,4 @@ def mock_get_port_table(namespace=None):
5353
multi_asic.is_multi_asic = mock_is_multi_asic
5454
multi_asic.get_all_namespaces = mock_get_all_namespaces
5555
multi_asic.is_port_channel_internal = mock_is_port_channel_internal
56-
multi_asic.get_port_table = mock_get_port_table
56+
multi_asic.get_port_table_for_asic = mock_get_port_table_for_asic

0 commit comments

Comments
 (0)