Skip to content

Commit

Permalink
Merge pull request #1340 from dineshbaburam91/bind_addr_change
Browse files Browse the repository at this point in the history
Added bind_addr parameter in Device() API
  • Loading branch information
chidanandpujar authored Oct 21, 2024
2 parents 006ec44 + cf87f03 commit 4828e32
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/jnpr/junos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,10 @@ def __init__(self, *vargs, **kvargs):
*OPTIONAL* To disable public key authentication.
default is ``None``.
:param str bind_addr:
*OPTIONAL* To use (local) source IP address.
default is ``None``.
:param bool hostkey_verify:
*OPTIONAL* To enable ssh_known hostkey verify
default is ``False``.
Expand All @@ -1239,6 +1243,7 @@ def __init__(self, *vargs, **kvargs):
self._huge_tree = kvargs.get("huge_tree", False)
self._conn_open_timeout = kvargs.get("conn_open_timeout", 30)
self._look_for_keys = kvargs.get("look_for_keys", None)
self._bind_addr = kvargs.get("bind_addr", None)
self._hostkey_verify = kvargs.get("hostkey_verify", False)
if self._fact_style != "new":
warnings.warn(
Expand Down Expand Up @@ -1393,6 +1398,7 @@ def open(self, *vargs, **kvargs):
allow_agent=allow_agent,
look_for_keys=look_for_keys,
ssh_config=self._sshconf_lkup(),
bind_addr=self._bind_addr,
timeout=self._conn_open_timeout,
device_params={
"name": "junos",
Expand Down
23 changes: 22 additions & 1 deletion tests/unit/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,23 @@ def test_device_open(self, mock_connect, mock_execute):
self.dev2.open()
self.assertEqual(self.dev2.connected, True)

@patch("ncclient.manager.connect")
@patch("jnpr.junos.Device.execute")
def test_device_open_with_bind_addr(self, mock_connect, mock_execute):
with patch("jnpr.junos.utils.fs.FS.cat") as mock_cat:
mock_cat.return_value = """
domain jls.net
"""
mock_connect.side_effect = self._mock_manager
mock_execute.side_effect = self._mock_manager
self.dev2 = Device(
host="2.2.2.2", user="test", password="password123", bind_addr="1.1.1.1"
)
self.dev2.open()
self.assertEqual(self.dev2.connected, True)

@patch("ncclient.manager.connect")
@patch("jnpr.junos.Device.execute")
def test_device_open_with_look_for_keys_False(self, mock_connect, mock_execute):
Expand Down Expand Up @@ -496,6 +513,7 @@ def test_device_open_with_look_for_keys_True(self, mock_connect, mock_execute):
)
self.dev2.open()
self.assertEqual(self.dev2.connected, True)

@patch("ncclient.manager.connect")
@patch("jnpr.junos.Device.execute")
def test_device_open_with_hostkey_verify_True(self, mock_connect, mock_execute):
Expand Down Expand Up @@ -525,7 +543,10 @@ def test_device_open_with_hostkey_verify_False(self, mock_connect, mock_execute)
mock_connect.side_effect = self._mock_manager
mock_execute.side_effect = self._mock_manager
self.dev2 = Device(
host="2.2.2.2", user="test", password="password123", hostkey_verify=False
host="2.2.2.2",
user="test",
password="password123",
hostkey_verify=False,
)
self.dev2.open()
self.assertEqual(self.dev2.connected, True)
Expand Down

0 comments on commit 4828e32

Please sign in to comment.