Skip to content

Commit

Permalink
Merge pull request #20 from datacenter/samiib/no-description-fix
Browse files Browse the repository at this point in the history
Fix #19
  • Loading branch information
samiib authored Oct 8, 2022
2 parents 6d53a3f + 01265fe commit 41ba9e4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ def add_neighbour(self, node, neighbour):

#Vmare esxi puts the port name vmnic in the chassisIdV while linux put the port name in the portDesc
lldp_port_id_class = 'portDesc'
if 'VMware' in neighbour_description:
if neighbour_description and 'VMware' in neighbour_description:
lldp_port_id_class = 'chassisIdV'
# UCS Uses the portIdV
if 'Cisco' in neighbour_description:
if neighbour_description and 'Cisco' in neighbour_description:
lldp_port_id_class = 'portIdV'

neighbour_adj_port = getattr(neighbour_adj,lldp_port_id_class, None)
Expand Down
36 changes: 34 additions & 2 deletions unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ def __init__(self, ip, mac, pathtDn) -> None:
self.fvRsCEpToPathEp[0].tDn = pathtDn


def create_lldp_neighbour(on: bool = True):
def create_lldp_neighbour(on: bool = True, desc: bool = True):
n = Expando()
n.operTxSt = n.operRxSt = "down"
if (on):
n.operTxSt = n.operRxSt = "up"
n.lldpAdjEp = [Expando()]
n.lldpAdjEp[0].sysName = "esxi4.cam.ciscolabs.com"
n.lldpAdjEp[0].chassisIdV = "vmxnic1"
n.lldpAdjEp[0].sysDesc = "VMware version 123"
if desc:
n.lldpAdjEp[0].sysDesc = "VMware version 123"
n.sysDesc = n.dn = "topology/pod-1/node-204"
n.id = "eth1/1"
return n
Expand Down Expand Up @@ -265,6 +266,37 @@ def test_valid_topology_no_neighbours(self):
self.assertEqual(build.aci_vrf, "uni/tn-Ciscolive/ctx-vrf-01")


def test_valid_topology_no_desc_neighbour(self):
"""Test that a neighbour with no description will not crash"""
# Arrange
expected = {'nodes': {'1234abc': {'bgp_peers': {'leaf-204': {'prefix_count': 2}},
'labels': {'app': 'redis'},
'mac': 'MOCKMO1C',
'neighbours': {'esxi4.cam.ciscolabs.com': {'Description': '',
'switches': {'leaf-204': set()}}},
'node_ip': '192.168.1.2',
'pods': {'dateformat': {'ip': '192.158.1.3',
'labels': {'guest': 'frontend'},
'ns': 'dockerimage'}}}},
'services': {'appx': [{'cluster_ip': '192.168.25.5',
'external_i_ps': ['192.168.5.1'],
'labels': {'app': 'guestbook'},
'name': 'example service',
'prefix': '192.168.5.1/32'}]}}

mock = ApicMethodsMock()
mock.lldps = [create_lldp_neighbour(desc=False)]
mock.cdpns = []
build = VkaciBuilTopology(
VkaciEnvVariables(self.vars), mock)
# Act
result = build.update()
print(result)
# Assert
self.assertDictEqual(result, expected)
self.assertEqual(build.aci_vrf, "uni/tn-Ciscolive/ctx-vrf-01")


def test_leaf_table(self):
"""Test that a leaf table is correctly created"""
# Arrange
Expand Down

0 comments on commit 41ba9e4

Please sign in to comment.