Skip to content

Commit

Permalink
New ifclass "mirror" on dist devices which copies settings from
Browse files Browse the repository at this point in the history
interface on mgmtdomain peer device
  • Loading branch information
indy-independence committed Dec 5, 2024
1 parent 6c3b298 commit 976fb97
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/cnaas_nms/db/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ def canonical_mac(mac):
return str(na_mac)


def find_mgmtdomain_one_device(session, device0: Device) -> Optional[Mgmtdomain]:
def find_mgmtdomain_peer(session, device0: Device) -> Device:
"""Find the peer device in a mgmtdomain for a given device"""
mgmtdomain: Mgmtdomain = find_mgmtdomain_one_device(session, device0)
if mgmtdomain.device_a == device0:
return mgmtdomain.device_b
else:
return mgmtdomain.device_a

Check warning on line 27 in src/cnaas_nms/db/helper.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/db/helper.py#L27

Added line #L27 was not covered by tests


def find_mgmtdomain_one_device(session, device0: Device) -> Mgmtdomain:
if device0.device_type == DeviceType.DIST:
mgmtdomain = (
session.query(Mgmtdomain)
Expand All @@ -38,7 +47,7 @@ def find_mgmtdomain_one_device(session, device0: Device) -> Optional[Mgmtdomain]
return mgmtdomain


def find_mgmtdomain_two_devices(session, device0: Device, device1: Device) -> Optional[Mgmtdomain]:
def find_mgmtdomain_two_devices(session, device0: Device, device1: Device) -> Mgmtdomain:
if device0.device_type != device1.device_type:
raise ValueError(
"Both uplink devices must be of same device type: {}, {}".format(device0.hostname, device1.hostname)
Expand Down Expand Up @@ -89,7 +98,7 @@ def find_mgmtdomain_two_devices(session, device0: Device, device1: Device) -> Op
return mgmtdomain


def find_mgmtdomain(session, hostnames: List[str]) -> Optional[Mgmtdomain]:
def find_mgmtdomain(session, hostnames: List[str]) -> Mgmtdomain:
"""Find the corresponding management domain for a pair of
distribution switches.
Expand Down
7 changes: 7 additions & 0 deletions src/cnaas_nms/db/tests/test_mgmtdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def test_find_mgmtdomain_invalid(self):
self.assertRaises(ValueError, cnaas_nms.db.helper.find_mgmtdomain, session, [])
self.assertRaises(ValueError, cnaas_nms.db.helper.find_mgmtdomain, session, [1, 2, 3])

def test_find_mgmtdomain_peer_device(self):
with sqla_session() as session: # type: ignore
d_a = session.query(Device).filter(Device.hostname == "mgmtdomaintest1").one()
d_b = session.query(Device).filter(Device.hostname == "mgmtdomaintest2").one()
found_peer: Device = cnaas_nms.db.helper.find_mgmtdomain_peer(session, d_a)
self.assertEqual(d_b, found_peer, "Peer device not found")

def test_find_mgmtdomain_twodist(self):
with sqla_session() as session: # type: ignore
mgmtdomain = cnaas_nms.db.helper.find_mgmtdomain(session, ["eosdist1", "eosdist2"])
Expand Down
15 changes: 15 additions & 0 deletions src/cnaas_nms/devicehandler/sync_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ def populate_device_vars(
"peer_asn": None,
}
)
elif intf["ifclass"] == "mirror":
# Copy interface settings from mgmtdomain peer device
if_dict = {"indexnum": ifindexnum}
peer_device = cnaas_nms.db.helper.find_mgmtdomain_peer(session, dev)
peer_settings, _ = get_settings(peer_device.hostname, devtype, peer_device.model)
if "interfaces" in peer_settings and peer_settings["interfaces"]:
for peer_intf in peer_settings["interfaces"]:
if peer_intf["name"] == intf["name"]:
for extra_key_name, value in peer_intf.items():
if_dict[extra_key_name] = value
break

Check warning on line 332 in src/cnaas_nms/devicehandler/sync_devices.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/devicehandler/sync_devices.py#L324-L332

Added lines #L324 - L332 were not covered by tests
# Description can be set separately from mirrored interface
if "description" in intf:
if_dict["description"] = intf["description"]
fabric_device_variables["interfaces"].append(if_dict)

Check warning on line 336 in src/cnaas_nms/devicehandler/sync_devices.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/devicehandler/sync_devices.py#L334-L336

Added lines #L334 - L336 were not covered by tests
else:
if_dict = {"indexnum": ifindexnum}
for extra_key_name, value in intf.items():
Expand Down

0 comments on commit 976fb97

Please sign in to comment.