Skip to content

Commit 764030a

Browse files
[LLDP]: Update init_db to load global database config (sonic-net#166)
[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.
1 parent 6e4a796 commit 764030a

File tree

8 files changed

+17
-5
lines changed

8 files changed

+17
-5
lines changed

src/sonic_ax_impl/mibs/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def init_db():
181181
Connects to DB
182182
:return: db_conn
183183
"""
184+
SonicDBConfig.load_sonic_global_db_config()
184185
# SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS.
185186
# Redis PubSub objects (such as those within swsssdk) are NOT thread-safe.
186187
db_conn = SonicV2Connector(**redis_kwargs)

tests/mock_tables/asic0/appl_db.json

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
"lldp_rem_port_id": "Ethernet2",
2828
"lldp_rem_man_addr": "fe80::268a:7ff:fe3f:834c"
2929
},
30+
"LLDP_LOC_CHASSIS": {
31+
"lldp_loc_chassis_id_subtype": "5",
32+
"lldp_loc_chassis_id": "00:11:22:AB:CD:EF",
33+
"lldp_loc_sys_name": "SONiC",
34+
"lldp_loc_sys_desc": "Gotta go Fast!",
35+
"lldp_loc_sys_cap_enabled": "28 00",
36+
"lldp_loc_sys_cap_supported": "28 00",
37+
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
38+
},
3039
"PORT_TABLE:Ethernet0": {
3140
"description": "snowflake",
3241
"alias": "etp1",

tests/mock_tables/asic1/appl_db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"lldp_loc_sys_desc": "Gotta go Fast!",
3535
"lldp_loc_sys_cap_enabled": "28 00",
3636
"lldp_loc_sys_cap_supported": "28 00",
37-
"lldp_loc_man_addr": "10.224.25.26,fe80::ce37:abff:feec:de9c"
37+
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
3838
},
3939
"PORT_TABLE:Ethernet8": {
4040
"description": "snowflake",

tests/mock_tables/asic2/appl_db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"lldp_loc_sys_desc": "Gotta go Fast!",
77
"lldp_loc_sys_cap_enabled": "28 00",
88
"lldp_loc_sys_cap_supported": "28 00",
9-
"lldp_loc_man_addr": "10.224.25.26,fe80::ce37:abff:feec:de9c"
9+
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
1010
},
1111
"PORT_TABLE:Ethernet-BP16": {
1212
"description": "backplane",

tests/mock_tables/dbconnector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def connect_SonicV2Connector(self, db_name, retry_on=True):
4646
# In case of multiple namespaces, namespace string passed to
4747
# SonicV2Connector will specify the namespace or can be empty.
4848
# Empty namespace represents global or host namespace.
49-
if len(ns_list) > 1 and self.namespace == "":
49+
if len(ns_list) > 1 and (self.namespace == "" or self.namespace == None):
5050
self.dbintf.redis_kwargs['namespace'] = "global_db"
5151
else:
5252
self.dbintf.redis_kwargs['namespace'] = self.namespace

tests/mock_tables/global_db/appl_db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
"lldp_loc_sys_desc": "Gotta go Fast!",
2121
"lldp_loc_sys_cap_enabled": "28 00",
2222
"lldp_loc_sys_cap_supported": "28 00",
23-
"lldp_loc_man_addr": "10.224.25.26,fe80::ce37:abff:feec:de9c"
23+
"lldp_loc_man_addr": "10.224.25.36,fe80::ce37:abff:feec:de9c"
2424
}
2525
}

tests/namespace/test_lldp.py

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def test_subtype_lldp_loc_man_addr_table(self):
118118

119119
response = get_pdu.make_response(self.lut)
120120
value0 = response.values[0]
121+
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))))
121122
self.assertEqual(value0.type_, ValueType.INTEGER)
122123
self.assertEqual(value0.data, 5)
123124

tests/test_lldp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_subtype_lldp_loc_man_addr_table(self):
9797

9898
response = get_pdu.make_response(self.lut)
9999
value0 = response.values[0]
100+
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))))
100101
self.assertEqual(value0.type_, ValueType.INTEGER)
101102
self.assertEqual(value0.data, 5)
102103

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

0 commit comments

Comments
 (0)