From 0c630597e1df5e56c2872e2c3bf4ea880659ddf1 Mon Sep 17 00:00:00 2001 From: efenian Date: Fri, 31 Jan 2025 22:47:51 -0500 Subject: [PATCH 1/4] send session_close RPC only if connection is alive Connection can be lost from control plane reset or device restart. meta: reset_connection task wll attempt to send a session_close RPC to a dead connection and ncclient will raise an exception preventing the connection socket_path from being closed out. --- plugins/connection/netconf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/connection/netconf.py b/plugins/connection/netconf.py index 0fc3184e0..6da8f0625 100644 --- a/plugins/connection/netconf.py +++ b/plugins/connection/netconf.py @@ -430,6 +430,6 @@ def _connect(self): ) def close(self): - if self._manager: + if self._manager.connected: self._manager.close_session() super(Connection, self).close() From f67e7266b31247cebaba7553164292e5d3cc5ba9 Mon Sep 17 00:00:00 2001 From: efenian Date: Sat, 1 Feb 2025 01:43:41 -0500 Subject: [PATCH 2/4] Test both cases manager exists and is connected --- plugins/connection/netconf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/connection/netconf.py b/plugins/connection/netconf.py index 6da8f0625..0c8b54def 100644 --- a/plugins/connection/netconf.py +++ b/plugins/connection/netconf.py @@ -430,6 +430,6 @@ def _connect(self): ) def close(self): - if self._manager.connected: + if self._manager and self._manager.connected: self._manager.close_session() super(Connection, self).close() From 80f8ac7fb68a719c112db4b4c6df1929fda3b018 Mon Sep 17 00:00:00 2001 From: efenian Date: Wed, 5 Feb 2025 22:50:36 -0500 Subject: [PATCH 3/4] Create netconf_reset_connection.yaml --- changelogs/netconf_reset_connection.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelogs/netconf_reset_connection.yaml diff --git a/changelogs/netconf_reset_connection.yaml b/changelogs/netconf_reset_connection.yaml new file mode 100644 index 000000000..a5c13fe65 --- /dev/null +++ b/changelogs/netconf_reset_connection.yaml @@ -0,0 +1,7 @@ +--- +bugfixes: + - "Connection can be lost from control plane reset or device restart. meta: + reset_connection task wll attempt to send a session_close RPC to a dead + connection and ncclient will raise an exception preventing the connection + socket_path from being closed out. + (https://github.com/ansible-collections/ansible.netcommon/issues/348)" From f5aae577848b68dabded42781f9ac92a6771e2a0 Mon Sep 17 00:00:00 2001 From: efenian Date: Thu, 6 Feb 2025 20:48:51 -0500 Subject: [PATCH 4/4] Update netconf_reset_connection.yaml --- changelogs/netconf_reset_connection.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/netconf_reset_connection.yaml b/changelogs/netconf_reset_connection.yaml index a5c13fe65..199b1f977 100644 --- a/changelogs/netconf_reset_connection.yaml +++ b/changelogs/netconf_reset_connection.yaml @@ -1,7 +1,7 @@ --- bugfixes: - "Connection can be lost from control plane reset or device restart. meta: - reset_connection task wll attempt to send a session_close RPC to a dead + reset_connection task will attempt to send a session_close RPC to a dead connection and ncclient will raise an exception preventing the connection socket_path from being closed out. (https://github.com/ansible-collections/ansible.netcommon/issues/348)"