Skip to content

Commit

Permalink
Fix issue #14 lldp-syncd throws exception from get_sys_capability_list (
Browse files Browse the repository at this point in the history
#22)

* Fix issue #14 accton-as5712-54x: lldp-syncd throws exception from get_sys_capability_list
The get_sys_capability_list() shall consider the system name of remote device is null case.
* To correct vlan format in new json file.
  • Loading branch information
chenkelly authored and qiluo-msft committed May 10, 2019
1 parent 50e9419 commit 282ed87
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def get_sys_capability_list(self, if_attributes):
"""
try:
# [{'enabled': ..., 'type': 'capability1'}, {'enabled': ..., 'type': 'capability2'}]
capability_list = if_attributes['chassis'].values()[0]['capability']
if 'capability' in if_attributes['chassis']:
capability_list = if_attributes['chassis']['capability']
else:
capability_list = if_attributes['chassis'].values()[0]['capability']
# {'enabled': ..., 'type': 'capability'}
if isinstance(capability_list, dict):
capability_list = [capability_list]
Expand Down
86 changes: 86 additions & 0 deletions tests/subproc_outputs/interface_only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"lldp": {
"interface": [
{
"Ethernet0": {
"rid": "1",
"port": {
"id": {
"type": "ifname",
"value": "Ethernet1"
},
"mfs": "9236"
},
"via": "LLDP",
"chassis": {
"mgmt-ip": "10.3.147.196",
"id": {
"type": "mac",
"value": "00:11:22:33:44:55"
},
"ttl": "120",
"descr": "I'm a little teapot.",
"capability": [
{
"type": "Bridge",
"enabled": true
},
{
"type": "Router",
"enabled": true
}
]
},
"age": "0 day, 05:09:05",
"vlan": [
{
"vlan-id": "101",
"pvid": true
}
]
}
},
{
"Ethernet100": {
"rid": "1",
"port": {
"id": {
"type": "ifname",
"value": "Ethernet26"
},
"mfs": "9236"
},
"via": "LLDP",
"chassis": {
"switch13": {
"mgmt-ip": "10.3.147.196",
"id": {
"type": "mac",
"value": "00:11:22:33:44:55"
},
"ttl": "120",
"descr": "I'm a little teapot.",
"capability": [
{
"type": "Bridge",
"enabled": true
},
{
"type": "Router",
"enabled": true
}
]
}
},
"age": "0 day, 05:09:04",
"vlan": [
{
"vlan-id": "126",
"pvid": true
}
]
}
}
]
}
}
10 changes: 10 additions & 0 deletions tests/test_lldpSyncDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def setUp(self):
with open(os.path.join(INPUT_DIR, 'lldpctl_single_loc_mgmt_ip.json')) as f:
self._single_loc_mgmt_ip = json.load(f)

with open(os.path.join(INPUT_DIR, 'interface_only.json')) as f:
self._interface_only = json.load(f)

self.daemon = lldp_syncd.LldpSyncDaemon()

def test_parse_json(self):
Expand Down Expand Up @@ -121,3 +124,10 @@ def test_loc_chassis(self):
db = create_dbconnector()
db_loc_chassis_data = db.get_all(db.APPL_DB, 'LLDP_LOC_CHASSIS')
self.assertEquals(parsed_loc_chassis, db_loc_chassis_data)

def test_remote_sys_capability_list(self):
interface_list = self._interface_only['lldp'].get('interface')
for interface in interface_list:
(if_name, if_attributes), = interface.items()
capability_list = self.daemon.get_sys_capability_list(if_attributes)
self.assertNotEqual(capability_list, [])

0 comments on commit 282ed87

Please sign in to comment.