Skip to content

Commit

Permalink
[RouteUpdater]: Fix multi_asic mock function implementation and multi…
Browse files Browse the repository at this point in the history
…_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 #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 .
  • Loading branch information
SuvarnaMeenakshi authored and abdosi committed Dec 31, 2020
1 parent 583265e commit a4f39ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/sonic_ax_impl/mibs/ietf/rfc4292.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def update_data(self):
# For single-asic platform, front_ns will be empty list.
if front_ns and db_conn.namespace not in front_ns:
continue
port_table = multi_asic.get_port_table(db_conn.namespace)
port_table = multi_asic.get_port_table_for_asic(db_conn.namespace)
ent = db_conn.get_all(mibs.APPL_DB, route_str, blocking=False)
if ent is None:
continue
Expand All @@ -76,13 +76,15 @@ def update_data(self):
## This is to workaround the bug in current sonic-swss implementation
if ifn == "eth0" or ifn == "lo" or ifn == "docker0":
continue

# Ignore internal asic routes
if multi_asic.is_port_channel_internal(ifn, db_conn.namespace):
continue
if (ifn in port_table and
multi_asic.ROLE in port_table[ifn] and
port_table[ifn][multi_asic.ROLE] == multi_asic.INTERNAL_PORT):
multi_asic.PORT_ROLE in port_table[ifn] and
port_table[ifn][multi_asic.PORT_ROLE] == multi_asic.INTERNAL_PORT):
continue

sub_id = ip2tuple_v4(ipn.network_address) + ip2tuple_v4(ipn.netmask) + (self.tos,) + ip2tuple_v4(nh)
self.route_dest_list.append(sub_id)
self.route_dest_map[sub_id] = ipn.network_address.packed
Expand Down
6 changes: 3 additions & 3 deletions tests/mock_tables/multi_asic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def mock_is_port_channel_internal(port_channel, namespace=None):
else:
return True if port_channel in int_port_channel else False

def mock_get_port_table(namespace=None):
def mock_get_port_table_for_asic(namespace=None):
if namespace is not None:
fname = os.path.join(INPUT_DIR, namespace, 'config_db.json')
else:
Expand All @@ -44,7 +44,7 @@ def mock_get_port_table(namespace=None):
with open(fname) as f:
db = json.load(f)
for k in db:
if 'PORT_TABLE' in db:
if 'PORT_TABLE' in k:
new_key = k[len('PORT_TABLE:'):]
port_table[new_key] = db[k]
return port_table
Expand All @@ -53,4 +53,4 @@ def mock_get_port_table(namespace=None):
multi_asic.is_multi_asic = mock_is_multi_asic
multi_asic.get_all_namespaces = mock_get_all_namespaces
multi_asic.is_port_channel_internal = mock_is_port_channel_internal
multi_asic.get_port_table = mock_get_port_table
multi_asic.get_port_table_for_asic = mock_get_port_table_for_asic

0 comments on commit a4f39ac

Please sign in to comment.