From 26e530515415b0135fb8165b3dd5cc97eafef889 Mon Sep 17 00:00:00 2001 From: gifrerenom <lluis.gifre@cttc.es> Date: Mon, 23 Dec 2024 18:19:14 +0000 Subject: [PATCH] Device - gNMI OpenConfig Driver: - Added logic to free libyang objects on Interface handler --- .../gnmi_openconfig/handlers/Interface.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py index a52c84691..6b91b1b06 100644 --- a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py +++ b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json, libyang, logging +import json, libyang, logging, queue from typing import Any, Dict, List, Tuple from ._Handler import _Handler from .Tools import get_bool, get_int, get_str @@ -43,30 +43,40 @@ class InterfaceHandler(_Handler): address_prefix = get_int (resource_value, 'address_prefix') # 24 mtu = get_int (resource_value, 'mtu' ) # 1500 + objects_to_free = queue.LifoQueue[libyang.DContainer]() + yang_ifs : libyang.DContainer = yang_handler.get_data_path('/openconfig-interfaces:interfaces') + objects_to_free.put_nowait(yang_ifs) yang_if_path = 'interface[name="{:s}"]'.format(if_name) yang_if : libyang.DContainer = yang_ifs.create_path(yang_if_path) + objects_to_free.put_nowait(yang_if) yang_if.create_path('config/name', if_name ) if enabled is not None: yang_if.create_path('config/enabled', enabled) if mtu is not None: yang_if.create_path('config/mtu', mtu) yang_sifs : libyang.DContainer = yang_if.create_path('subinterfaces') + objects_to_free.put_nowait(yang_sifs) yang_sif_path = 'subinterface[index="{:d}"]'.format(sif_index) yang_sif : libyang.DContainer = yang_sifs.create_path(yang_sif_path) + objects_to_free.put_nowait(yang_sif) yang_sif.create_path('config/index', sif_index) if enabled is not None: yang_sif.create_path('config/enabled', enabled) if vlan_id is not None: yang_subif_vlan : libyang.DContainer = yang_sif.create_path('openconfig-vlan:vlan') + objects_to_free.put_nowait(yang_subif_vlan) yang_subif_vlan.create_path('match/single-tagged/config/vlan-id', vlan_id) yang_ipv4 : libyang.DContainer = yang_sif.create_path('openconfig-if-ip:ipv4') + objects_to_free.put_nowait(yang_ipv4) if enabled is not None: yang_ipv4.create_path('config/enabled', enabled) if address_ip is not None and address_prefix is not None: yang_ipv4_addrs : libyang.DContainer = yang_ipv4.create_path('addresses') + objects_to_free.put_nowait(yang_ipv4_addrs) yang_ipv4_addr_path = 'address[ip="{:s}"]'.format(address_ip) yang_ipv4_addr : libyang.DContainer = yang_ipv4_addrs.create_path(yang_ipv4_addr_path) + objects_to_free.put_nowait(yang_ipv4_addr) yang_ipv4_addr.create_path('config/ip', address_ip) yang_ipv4_addr.create_path('config/prefix-length', address_prefix) @@ -75,6 +85,10 @@ class InterfaceHandler(_Handler): json_data = json.loads(str_data) json_data = json_data['openconfig-interfaces:interface'][0] str_data = json.dumps(json_data) + + while not objects_to_free.empty(): + obj = objects_to_free.get() + obj.free() return str_path, str_data def parse( -- GitLab