Fix to allow netmiko_mod load unless proxy and deltaproxy active

This commit is contained in:
David Murphy 2021-06-15 09:56:32 -06:00 committed by Megan Wilhite
parent 85c0bdeee5
commit 290f8b6fe1
3 changed files with 25 additions and 4 deletions

1
changelog/60061.fixed Normal file
View file

@ -0,0 +1 @@
Allow for Napalm dependency netmiko_mod to load correctly, used by Napalm with Cisco IOS

View file

@ -226,10 +226,13 @@ def __virtual__():
False,
"The netmiko execution module requires netmiko library to be installed.",
)
if salt.utils.platform.is_proxy() and __opts__["proxy"]["proxytype"] != "netmiko":
if (
salt.utils.platform.is_proxy()
and __opts__["proxy"]["proxytype"] == "deltaproxy"
):
return (
False,
"Not a proxy minion of type netmiko.",
"Unsupported proxy minion type.",
)
return __virtualname__

View file

@ -99,15 +99,32 @@ class NetmikoTestCase(TestCase, LoaderModuleMockMixin):
with patch.object(netmiko_mod, "HAS_NETMIKO", True):
ret = netmiko_mod.__virtual__()
self.assertTrue(ret)
self.assertEqual(ret, "netmiko")
_expected = (False, "Not a proxy minion of type netmiko.")
with patch("salt.utils.platform.is_proxy", return_value=True, autospec=True):
with patch.dict(netmiko_mod.__opts__, {"proxy": {"proxytype": "esxi"}}):
with patch.object(netmiko_mod, "HAS_NETMIKO", True):
ret = netmiko_mod.__virtual__()
self.assertEqual(ret, _expected)
self.assertTrue(ret)
self.assertEqual(ret, "netmiko")
with patch("salt.utils.platform.is_proxy", return_value=False, autospec=True):
with patch.object(netmiko_mod, "HAS_NETMIKO", True):
ret = netmiko_mod.__virtual__()
self.assertEqual(ret, "netmiko")
with patch("salt.utils.platform.is_proxy", return_value=True, autospec=True):
with patch.dict(netmiko_mod.__opts__, {"proxy": {"proxytype": "napalm"}}):
with patch.object(netmiko_mod, "HAS_NETMIKO", True):
ret = netmiko_mod.__virtual__()
self.assertTrue(ret)
self.assertEqual(ret, "netmiko")
_expected = (False, "Unsupported proxy minion type.")
with patch("salt.utils.platform.is_proxy", return_value=True, autospec=True):
with patch.dict(
netmiko_mod.__opts__, {"proxy": {"proxytype": "deltaproxy"}}
):
with patch.object(netmiko_mod, "HAS_NETMIKO", True):
ret = netmiko_mod.__virtual__()
self.assertEqual(ret, _expected)