From 9f3dc8c80ed3a365f29c44d0ec3a9c2eeddde32a Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Tue, 2 Aug 2022 14:19:45 -0700 Subject: [PATCH 1/3] need to check the version of Netmiko python library and then import the exceptions from different locations depending on the result. --- salt/proxy/netmiko_px.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/salt/proxy/netmiko_px.py b/salt/proxy/netmiko_px.py index 206d01789d87..6179884b5b83 100644 --- a/salt/proxy/netmiko_px.py +++ b/salt/proxy/netmiko_px.py @@ -187,11 +187,22 @@ import time import salt.utils.args +from salt.utils.versions import LooseVersion as _LooseVersion try: from netmiko import ConnectHandler - from netmiko.ssh_exception import NetMikoTimeoutException - from netmiko.ssh_exception import NetMikoAuthenticationException + from netmiko import __version__ as found_netmiko_version + + if _LooseVersion(found_netmiko_version) <= _LooseVersion("3.4.0"): + from netmiko.ssh_exception import ( + NetMikoTimeoutException, + NetMikoAuthenticationException, + ) + else: + from netmiko import ( + NetMikoAuthenticationException, + NetMikoTimeoutException, + ) HAS_NETMIKO = True except ImportError: From 14ffd5941bf8978e1bf8e1d03da9b15323df97eb Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 3 Aug 2022 09:07:37 -0700 Subject: [PATCH 2/3] Adding changelog. --- changelog/62405.fixed | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/62405.fixed diff --git a/changelog/62405.fixed b/changelog/62405.fixed new file mode 100644 index 000000000000..a8077992fe1e --- /dev/null +++ b/changelog/62405.fixed @@ -0,0 +1 @@ +Due to changes in the Netmiko library for the exception paths, need to check the version of Netmiko python library and then import the exceptions from different locations depending on the result. From f28351a0387279248f8c97582f4e1920b87bb7a9 Mon Sep 17 00:00:00 2001 From: "Gareth J. Greenaway" Date: Wed, 3 Aug 2022 10:34:12 -0700 Subject: [PATCH 3/3] swap out if...else for double try...except. --- salt/proxy/netmiko_px.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/salt/proxy/netmiko_px.py b/salt/proxy/netmiko_px.py index 6179884b5b83..a926853304a7 100644 --- a/salt/proxy/netmiko_px.py +++ b/salt/proxy/netmiko_px.py @@ -187,22 +187,20 @@ import time import salt.utils.args -from salt.utils.versions import LooseVersion as _LooseVersion try: from netmiko import ConnectHandler - from netmiko import __version__ as found_netmiko_version - if _LooseVersion(found_netmiko_version) <= _LooseVersion("3.4.0"): - from netmiko.ssh_exception import ( - NetMikoTimeoutException, - NetMikoAuthenticationException, - ) - else: + try: from netmiko import ( NetMikoAuthenticationException, NetMikoTimeoutException, ) + except ImportError: + from netmiko.ssh_exception import ( + NetMikoTimeoutException, + NetMikoAuthenticationException, + ) HAS_NETMIKO = True except ImportError: