From f54983ad671c106e58d571f5551b6f2ad059d6f7 Mon Sep 17 00:00:00 2001 From: MUTHU-RAKESH-27 <19cs127@psgitech.ac.in> Date: Tue, 22 Oct 2024 15:25:33 +0530 Subject: [PATCH 1/2] Tested the L2 Handoff and L3 Handoff with SDA Transit --- .../sda_fabric_devices_workflow_manager.py | 95 +++++++++++++++---- 1 file changed, 77 insertions(+), 18 deletions(-) diff --git a/plugins/modules/sda_fabric_devices_workflow_manager.py b/plugins/modules/sda_fabric_devices_workflow_manager.py index 0c9922202c..04de5f77ef 100644 --- a/plugins/modules/sda_fabric_devices_workflow_manager.py +++ b/plugins/modules/sda_fabric_devices_workflow_manager.py @@ -1465,7 +1465,7 @@ def l2_handoff_exists(self, fabric_id, device_id, internal_vlan_id, interface_na if not isinstance(all_l2_handoff_details, dict): self.msg = "Failed to retrieve the L2 Handoff details - Response is not a dictionary" - self.log(self.msg, "CRITICAL") + self.log(str(self.msg), "CRITICAL") self.status = "failed" return self.check_return_status() @@ -1477,9 +1477,12 @@ def l2_handoff_exists(self, fabric_id, device_id, internal_vlan_id, interface_na ) break - l2_handoff_details = next(item for item in all_l2_handoff_details - if item.get("internalVlanId") == internal_vlan_id and - item.get("interfaceName") == interface_name) + l2_handoff_details = None + for item in all_l2_handoff_details: + if item.get("internalVlanId") == internal_vlan_id and item.get("interfaceName") == interface_name: + l2_handoff_details = item + break + l2_handoff_details = get_dict_result(all_l2_handoff_details, "internalVlanId", internal_vlan_id) if l2_handoff_details: self.log( @@ -1862,7 +1865,7 @@ def process_layer2_handoff(self, fabric_devices_info, layer2_handoff, fabric_sit network_device_id, internal_vlan_id, interface_name) - fabric_devices_info.get("l2_handoff_ids").append(l2_handoff_id) + fabric_devices_info.get("l2_handoff_details").append(l2_handoff_id) self.log("Successfully proccessed the L2 Handoff information.", "DEBUG") return fabric_devices_info @@ -2046,7 +2049,7 @@ def get_have_fabric_devices(self, fabric_devices): fabric_devices_info = { "exists": False, "device_details": None, - "l2_handoff_ids": [], + "l2_handoff_details": [], "sda_l3_handoff_details": None, "ip_l3_handoff_details": [], "id": None, @@ -2605,6 +2608,53 @@ def validate_vlan_fields(self, internal_vlan_id, external_vlan_id, device_ip): return None + def check_transit_type(self, transit_id): + """ + Check whether the given transit id is LISP/PUB SUB or LISP/BGP. + + Parameters: + transit_id (str): The id of the transit network. + Returns: + is_transit_pub_sub (bool): Returns True, if the transit type is 'SDA_LISP_PUB_SUB_TRANSIT'. Else, False. + Description: + Call the API 'get_transit_networks' by setting the 'id' and 'type' as field with the + given transit id and 'SDA_LISP_PUB_SUB_TRANSIT'. + If the response is not empty, fetch the Id and return. Else, return None. + """ + + self.log("Starting to get transit type for transit name: '{id}'".format(id=transit_id), "DEBUG") + is_transit_pub_sub = False + try: + transit_details = self.dnac._exec( + family="sda", + function="get_transit_networks", + params={ + "id": transit_id, + "type": "SDA_LISP_PUB_SUB_TRANSIT" + }, + ) + + # If the SDK returns no response, then the transit doesnot exist with type 'SDA_LISP_PUB_SUB_TRANSIT' + transit_details = transit_details.get("response") + if not transit_details: + self.log( + "There is no transit network with the id '{id}' with transit type 'SDA_LISP_PUB_SUB_TRANSIT'." + .format(id=transit_id), "DEBUG" + ) + return is_transit_pub_sub + + is_transit_pub_sub = True + except Exception as msg: + self.msg = ( + "Exception occured while running the API 'get_transit_networks': {msg}" + .format(msg=msg) + ) + self.log(self.msg, "CRITICAL") + self.status = "failed" + return self.check_return_status() + + return is_transit_pub_sub + def get_l2_handoff_params(self, fabric_id, network_id, device_details, device_config_index): """ Get the L2 Handoff of the SDA fabric devices information from playbook. @@ -2764,20 +2814,26 @@ def get_sda_l3_handoff_params(self, fabric_id, network_id, device_details, devic "Transit ID for the transit name {name}: {id}" .format(name=transit_name, id=transit_id) ) + + is_transit_pub_sub = self.check_transit_type(transit_id) + self.log( + "The transit type is 'LISP/PUB SUB': {is_transit_pub_sub}" + .format(is_transit_pub_sub=is_transit_pub_sub) + ) connected_to_internet = layer3_handoff_sda_transit.get("connected_to_internet") - if not connected_to_internet: + if connected_to_internet is None: if is_sda_l3_handoff_exists: connected_to_internet = have_sda_l3_handoff.get("connectedToInternet") else: connected_to_internet = False - self.log( - "Connected to internet for device IP {device_ip}: {connected_to_internet}" - .format(device_ip=device_ip, connected_to_internet=connected_to_internet), "DEBUG" - ) + self.log( + "Connected to internet for device IP {device_ip}: {connected_to_internet}" + .format(device_ip=device_ip, connected_to_internet=connected_to_internet), "DEBUG" + ) is_multicast_over_transit_enabled = layer3_handoff_sda_transit.get("is_multicast_over_transit_enabled") - if not is_multicast_over_transit_enabled: + if is_multicast_over_transit_enabled is None: if is_sda_l3_handoff_exists: is_multicast_over_transit_enabled = have_sda_l3_handoff.get("isMulticastOverTransitEnabled") else: @@ -2860,13 +2916,17 @@ def get_sda_l3_handoff_params(self, fabric_id, network_id, device_details, devic return self.check_return_status() sda_l3_handoff_info.update({ - "interfaceName": transit_id, - "affinityIdPrime": affinity_id_prime, - "affinityIdDecider": affinity_id_decider, + "transitNetworkId": transit_id, "connectedToInternet": connected_to_internet, - "isMulticastOverTransitEnabled": is_multicast_over_transit_enabled, }) + if is_transit_pub_sub: + sda_l3_handoff_info.update({ + "affinityIdPrime": affinity_id_prime, + "affinityIdDecider": affinity_id_decider, + "isMulticastOverTransitEnabled": is_multicast_over_transit_enabled, + }) + self.log( "Successfully retrieved L3 handoff parameters for device IP: {device_ip}" .format(device_ip=device_ip) @@ -4003,8 +4063,7 @@ def delete_l2_handoff(self, have_l2_handoff, device_ip, "Non-existing L2 Handoffs: {non_existing_list}" .format(non_existing_list=non_existing_l2_handoff), "DEBUG" ) - for item in delete_l2_handoff: - id = item.get("id") + for id in delete_l2_handoff: try: payload = {"id": id} task_name = "delete_fabric_device_layer2_handoff_by_id" From 36afef3f78be470219c46d7f8427cef0e8fdca08 Mon Sep 17 00:00:00 2001 From: MUTHU-RAKESH-27 <19cs127@psgitech.ac.in> Date: Wed, 23 Oct 2024 15:23:51 +0530 Subject: [PATCH 2/2] Addressed the review comments --- .../modules/sda_fabric_devices_workflow_manager.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/modules/sda_fabric_devices_workflow_manager.py b/plugins/modules/sda_fabric_devices_workflow_manager.py index 04de5f77ef..0d00aad621 100644 --- a/plugins/modules/sda_fabric_devices_workflow_manager.py +++ b/plugins/modules/sda_fabric_devices_workflow_manager.py @@ -1483,7 +1483,6 @@ def l2_handoff_exists(self, fabric_id, device_id, internal_vlan_id, interface_na l2_handoff_details = item break - l2_handoff_details = get_dict_result(all_l2_handoff_details, "internalVlanId", internal_vlan_id) if l2_handoff_details: self.log( "The L2 handoff details with the internal VLAN Id: {details}" @@ -2617,12 +2616,12 @@ def check_transit_type(self, transit_id): Returns: is_transit_pub_sub (bool): Returns True, if the transit type is 'SDA_LISP_PUB_SUB_TRANSIT'. Else, False. Description: - Call the API 'get_transit_networks' by setting the 'id' and 'type' as field with the - given transit id and 'SDA_LISP_PUB_SUB_TRANSIT'. - If the response is not empty, fetch the Id and return. Else, return None. + Calls the 'get_transit_networks' API by setting the 'id' and 'type' fields + with the given transit id and 'SDA_LISP_PUB_SUB_TRANSIT'. + If the response is valid, fetch the Id and return True, otherwise False. """ - self.log("Starting to get transit type for transit name: '{id}'".format(id=transit_id), "DEBUG") + self.log("Fetching transit type for transit ID: '{id}'".format(id=transit_id), "DEBUG") is_transit_pub_sub = False try: transit_details = self.dnac._exec( @@ -2643,6 +2642,10 @@ def check_transit_type(self, transit_id): ) return is_transit_pub_sub + self.log( + "Transit network found with ID: '{id}' and type 'SDA_LISP_PUB_SUB_TRANSIT'." + .format(id=transit_id), "DEBUG" + ) is_transit_pub_sub = True except Exception as msg: self.msg = (