Skip to content

Commit ce4a029

Browse files
shenglongtranquysjmcgill298
authored
Linked to issue #242 Install mode issue (#243)
* Fixed ios device install mode run command * updated changelog * added netmiko args to show() function since the way install mode invokes show, expects it to take netmiko args * updated version for __init__ and pyproject * Add test cases for ios show Co-authored-by: Sheng <sheng-nong.tran_quyen@roche.com> Co-authored-by: Jacob McGill <jacob.mcgill@networktocode.com>
1 parent 991b046 commit ce4a029

6 files changed

Lines changed: 76 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/)
1212
### Fixed
1313
### Security
1414

15+
## [0.20.2]
16+
17+
### Fixed
18+
19+
- Fixed ios device install mode run command.
20+
1521
## [0.20.1]
1622

1723
### Fixed

pyntc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
except ImportError:
1212
from ConfigParser import SafeConfigParser
1313

14-
__version__ = "0.20.1"
14+
__version__ = "0.20.2"
1515

1616
LIB_PATH_ENV_VAR = "PYNTC_CONF"
1717
LIB_PATH_DEFAULT = "~/.ntc.conf"

pyntc/devices/ios_device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def set_boot_options(self, image_name, **vendor_specifics):
989989
message="Setting boot command did not yield expected results, found {0}".format(new_boot_options),
990990
)
991991

992-
def show(self, command, expect_string=None):
992+
def show(self, command, expect_string=None, **netmiko_args):
993993
"""Run command on device.
994994
995995
Args:
@@ -1000,7 +1000,7 @@ def show(self, command, expect_string=None):
10001000
str: Output of command.
10011001
"""
10021002
self.enable()
1003-
return self._send_command(command, expect_string=expect_string)
1003+
return self._send_command(command, expect_string=expect_string, **netmiko_args)
10041004

10051005
def show_list(self, commands):
10061006
"""Run a list of commands on device.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"
44

55
[tool.poetry]
66
name = "pyntc"
7-
version = "0.20.1"
7+
version = "0.20.2"
88
description = "SDK to simplify common workflows for Network Devices."
99
authors = ["NTC <info@networktocode.com>"]
1010
readme = "README.md"

test/unit/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def ios_redundancy_self():
325325

326326

327327
@pytest.fixture
328-
def ios_send_command(ios_device, ios_mock_path):
328+
def ios_native_send_command(ios_device, ios_mock_path):
329329
def _mock(side_effects, existing_device=None, device=ios_device):
330330
if existing_device is not None:
331331
device = existing_device
@@ -336,7 +336,7 @@ def _mock(side_effects, existing_device=None, device=ios_device):
336336

337337

338338
@pytest.fixture
339-
def ios_send_command_timing(ios_device, ios_mock_path):
339+
def ios_native_send_command_timing(ios_device, ios_mock_path):
340340
def _mock(side_effects, existing_device=None, device=ios_device):
341341
if existing_device is not None:
342342
device = existing_device
@@ -346,6 +346,19 @@ def _mock(side_effects, existing_device=None, device=ios_device):
346346
return _mock
347347

348348

349+
@pytest.fixture
350+
def ios_send_command(ios_device, ios_mock_path):
351+
def _mock(side_effects, existing_device=None, device=ios_device):
352+
if existing_device is not None:
353+
device = existing_device
354+
with mock.patch.object(IOSDevice, "_send_command") as mock_send_command:
355+
mock_send_command.side_effect = get_side_effects(ios_mock_path, side_effects)
356+
device._send_command = mock_send_command
357+
return device
358+
359+
return _mock
360+
361+
349362
@pytest.fixture
350363
def ios_show(ios_device, ios_mock_path):
351364
def _mock(side_effects, existing_device=None, device=ios_device):

test/unit/test_devices/test_ios_device.py

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -791,24 +791,24 @@ def test_get_file_system_raise_error(mock_hostname, ios_show):
791791
device.show.assert_has_calls([mock.call("dir")] * 5)
792792

793793

794-
def test_send_command_error(ios_send_command):
794+
def test_send_command_error(ios_native_send_command):
795795
command = "send_command_error"
796-
device = ios_send_command([f"{command}.txt"])
796+
device = ios_native_send_command([f"{command}.txt"])
797797
with pytest.raises(ios_module.CommandError):
798798
device._send_command(command)
799799
device.native.send_command.assert_called()
800800

801801

802-
def test_send_command_expect(ios_send_command):
802+
def test_send_command_expect(ios_native_send_command):
803803
command = "send_command_expect"
804-
device = ios_send_command([f"{command}.txt"])
804+
device = ios_native_send_command([f"{command}.txt"])
805805
device._send_command(command, expect_string="Continue?")
806806
device.native.send_command.assert_called_with(command_string="send_command_expect", expect_string="Continue?")
807807

808808

809-
def test_send_command_timing(ios_send_command_timing):
809+
def test_send_command_timing(ios_native_send_command_timing):
810810
command = "send_command_timing"
811-
device = ios_send_command_timing([f"{command}.txt"])
811+
device = ios_native_send_command_timing([f"{command}.txt"])
812812
device.native.send_command_timing(command)
813813
device.native.send_command_timing.assert_called()
814814
device.native.send_command_timing.assert_called_with(command)
@@ -1197,13 +1197,52 @@ def test_show(ios_send_command):
11971197
command = "show_ip_arp"
11981198
device = ios_send_command([f"{command}.txt"])
11991199
device.show(command)
1200-
device.native.send_command.assert_called_with(command_string="show_ip_arp")
1201-
device.native.send_command.assert_called_once()
1200+
device._send_command.assert_called_with(
1201+
"show_ip_arp",
1202+
expect_string=None,
1203+
)
1204+
device._send_command.assert_called_once()
1205+
1206+
1207+
def test_show_expect(ios_send_command):
1208+
command = "show_ip_arp"
1209+
expect = "this string"
1210+
device = ios_send_command([f"{command}.txt"])
1211+
device.show(command, expect)
1212+
device._send_command.assert_called_with(
1213+
"show_ip_arp",
1214+
expect_string=expect,
1215+
)
1216+
1217+
1218+
def test_show_expect_netmiko_args(ios_send_command):
1219+
command = "show_ip_arp"
1220+
expect = "this string"
1221+
netmiko_args = {"some_flag": "passed"}
1222+
device = ios_send_command([f"{command}.txt"])
1223+
device.show(command, expect, **netmiko_args)
1224+
device._send_command.assert_called_with(
1225+
"show_ip_arp",
1226+
expect_string=expect,
1227+
**netmiko_args,
1228+
)
1229+
1230+
1231+
def test_show_netmiko_args(ios_send_command):
1232+
command = "show_ip_arp"
1233+
netmiko_args = {"some_flag": "passed"}
1234+
device = ios_send_command([f"{command}.txt"])
1235+
device.show(command, **netmiko_args)
1236+
device._send_command.assert_called_with(
1237+
"show_ip_arp",
1238+
expect_string=None,
1239+
**netmiko_args,
1240+
)
12021241

12031242

1204-
def test_show_list(ios_send_command):
1243+
def test_show_list(ios_native_send_command):
12051244
commands = ["show_version", "show_ip_arp"]
1206-
device = ios_send_command([f"{commands[0]}.txt", f"{commands[1]}"])
1245+
device = ios_native_send_command([f"{commands[0]}.txt", f"{commands[1]}"])
12071246
device.show_list(commands)
12081247
device.native.send_command.assert_has_calls(
12091248
[mock.call(command_string="show_version"), mock.call(command_string="show_ip_arp")]
@@ -1222,9 +1261,9 @@ def test_vlans(mock_show_vlan, mock_model, ios_show):
12221261

12231262
@pytest.mark.parametrize("show_boot_out", (SHOW_BOOT_VARIABLE, SHOW_BOOT_PATH_LIST), ids=("bootvar", "bootpath"))
12241263
@mock.patch.object(IOSDevice, "_get_file_system", return_value="flash:")
1225-
def test_boot_options_show_boot(mock_boot, show_boot_out, ios_send_command):
1264+
def test_boot_options_show_boot(mock_boot, show_boot_out, ios_native_send_command):
12261265
results = [ios_module.CommandError("show bootvar", "fail"), show_boot_out]
1227-
device = ios_send_command(results)
1266+
device = ios_native_send_command(results)
12281267
boot_options = device.boot_options
12291268
assert boot_options == {"sys": BOOT_IMAGE}
12301269
device.native.send_command.assert_called_with(command_string="show boot")

0 commit comments

Comments
 (0)