Skip to content

Commit

Permalink
Add support for specifying port with EOS (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcgill298 authored Nov 13, 2020
1 parent 124be5b commit e0b278c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pyntc/devices/eos_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ class EOSDevice(BaseDevice):

vendor = "arista"

def __init__(self, host, username, password, transport="http", timeout=60, **kwargs):
def __init__(self, host, username, password, transport="http", port=None, timeout=None, **kwargs):
super().__init__(host, username, password, device_type="arista_eos_eapi")
self.transport = transport
self.port = port
self.timeout = timeout
self.connection = eos_connect(transport, host=host, username=username, password=password, timeout=timeout)
eapi_args = {
"transport": transport,
"host": host,
"username": username,
"password": password,
}
optional_args = ("port", "timeout")
for arg in optional_args:
value = getattr(self, arg)
if value is not None:
eapi_args[arg] = value
self.connection = eos_connect(**eapi_args)
self.native = EOSNative(self.connection)
# _connected indicates Netmiko ssh connection
self._connected = False
Expand Down
36 changes: 36 additions & 0 deletions test/unit/test_devices/test_eos_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,39 @@ def test_starting_config(self):

if __name__ == "__main__":
unittest.main()


@mock.patch("pyntc.devices.eos_device.eos_connect")
def test_init_no_transport(mock_eos_connect):
EOSDevice("host", "username", "password")
mock_eos_connect.assert_called_with(host="host", username="username", password="password", transport="http")


@mock.patch("pyntc.devices.eos_device.eos_connect")
def test_init_https_transport(mock_eos_connect):
EOSDevice("host", "username", "password", transport="https")
mock_eos_connect.assert_called_with(host="host", username="username", password="password", transport="https")


@mock.patch("pyntc.devices.eos_device.eos_connect")
def test_init_pass_port(mock_eos_connect):
EOSDevice("host", "username", "password", port=8080)
mock_eos_connect.assert_called_with(
host="host", username="username", password="password", transport="http", port=8080
)


@mock.patch("pyntc.devices.eos_device.eos_connect")
def test_init_pass_timeout(mock_eos_connect):
EOSDevice("host", "username", "password", timeout=30)
mock_eos_connect.assert_called_with(
host="host", username="username", password="password", transport="http", timeout=30
)


@mock.patch("pyntc.devices.eos_device.eos_connect")
def test_init_pass_port_and_timeout(mock_eos_connect):
EOSDevice("host", "username", "password", port=8080, timeout=30)
mock_eos_connect.assert_called_with(
host="host", username="username", password="password", transport="http", port=8080, timeout=30
)

0 comments on commit e0b278c

Please sign in to comment.