Skip to content

Commit

Permalink
[LLDP]: Update init_db to load global database config (sonic-net#166)
Browse files Browse the repository at this point in the history
[LLDP]: Update init_db to load global database config
before initializing SonicV2Connector class.
LLDPLocManAddrUpdater requires information from host database hence uses init_db() to initialize the host db.
For unit-testing multi-asic code path, there are mock db files provided for global_db and namespace specific dbs.
As init_db did not load global database config, unit-test mock db was not loading global_db database files for LLDPLocManAddrUpdater unit-testing. Fixed this by loading global database config in init_db function. Fixed by:
Loading global database config in init_db()
unit-test: Loading mock db files from "global_db" director for multi-asic platform if namespace is empty or None.
  • Loading branch information
SuvarnaMeenakshi authored Oct 15, 2020
1 parent 6e4a796 commit 764030a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def init_db():
Connects to DB
:return: db_conn
"""
SonicDBConfig.load_sonic_global_db_config()
# SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS.
# Redis PubSub objects (such as those within swsssdk) are NOT thread-safe.
db_conn = SonicV2Connector(**redis_kwargs)
Expand Down
9 changes: 9 additions & 0 deletions tests/mock_tables/asic0/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"lldp_rem_port_id": "Ethernet2",
"lldp_rem_man_addr": "fe80::268a:7ff:fe3f:834c"
},
"LLDP_LOC_CHASSIS": {
"lldp_loc_chassis_id_subtype": "5",
"lldp_loc_chassis_id": "00:11:22:AB:CD:EF",
"lldp_loc_sys_name": "SONiC",
"lldp_loc_sys_desc": "Gotta go Fast!",
"lldp_loc_sys_cap_enabled": "28 00",
"lldp_loc_sys_cap_supported": "28 00",
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
},
"PORT_TABLE:Ethernet0": {
"description": "snowflake",
"alias": "etp1",
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tables/asic1/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lldp_loc_sys_desc": "Gotta go Fast!",
"lldp_loc_sys_cap_enabled": "28 00",
"lldp_loc_sys_cap_supported": "28 00",
"lldp_loc_man_addr": "10.224.25.26,fe80::ce37:abff:feec:de9c"
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
},
"PORT_TABLE:Ethernet8": {
"description": "snowflake",
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tables/asic2/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lldp_loc_sys_desc": "Gotta go Fast!",
"lldp_loc_sys_cap_enabled": "28 00",
"lldp_loc_sys_cap_supported": "28 00",
"lldp_loc_man_addr": "10.224.25.26,fe80::ce37:abff:feec:de9c"
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
},
"PORT_TABLE:Ethernet-BP16": {
"description": "backplane",
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tables/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def connect_SonicV2Connector(self, db_name, retry_on=True):
# In case of multiple namespaces, namespace string passed to
# SonicV2Connector will specify the namespace or can be empty.
# Empty namespace represents global or host namespace.
if len(ns_list) > 1 and self.namespace == "":
if len(ns_list) > 1 and (self.namespace == "" or self.namespace == None):
self.dbintf.redis_kwargs['namespace'] = "global_db"
else:
self.dbintf.redis_kwargs['namespace'] = self.namespace
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tables/global_db/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"lldp_loc_sys_desc": "Gotta go Fast!",
"lldp_loc_sys_cap_enabled": "28 00",
"lldp_loc_sys_cap_supported": "28 00",
"lldp_loc_man_addr": "10.224.25.26,fe80::ce37:abff:feec:de9c"
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
}
}
1 change: 1 addition & 0 deletions tests/namespace/test_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def test_subtype_lldp_loc_man_addr_table(self):

response = get_pdu.make_response(self.lut)
value0 = response.values[0]
self.assertEqual(str(value0.name), str(ObjectIdentifier(13, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, 3, 1, 4, 10, 224, 25, 36))))
self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(value0.data, 5)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_subtype_lldp_loc_man_addr_table(self):

response = get_pdu.make_response(self.lut)
value0 = response.values[0]
self.assertEqual(str(value0.name), str(ObjectIdentifier(13, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 3, 8, 1, 3, 1, 4, 10, 224, 25, 26))))
self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(value0.data, 5)

Expand Down Expand Up @@ -224,4 +225,4 @@ def test_getnextpdu_lldpRemSysCapEnabled(self):
value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.OCTET_STRING)
self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 12, 1, 1))))
self.assertEqual(str(value0.data), "\x28\x00")
self.assertEqual(str(value0.data), "\x28\x00")

0 comments on commit 764030a

Please sign in to comment.