Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyntc/devices/ios_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,10 @@ def install_os(self, image_name, install_mode=False, read_timeout=2000, **vendor
)
# Set a higher read_timeout and send it in
try:
self.show(command, read_timeout=read_timeout)
install_message = self.show(command, read_timeout=read_timeout)
if install_message.startswith("FAILED:"):
log.error("Host %s: OS install error for image %s", self.host, image_name)
raise OSInstallError(hostname=self.hostname, desired_boot=image_name)
except IOError:
log.error("Host %s: IO error for image %s", self.host, image_name)
except CommandError:
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_devices/test_ios_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,30 @@ def test_install_os_error(self, mock_wait, mock_reboot, mock_set_boot, mock_imag
mock_raw_version_data.return_value = DEVICE_FACTS
self.assertRaises(ios_module.OSInstallError, self.device.install_os, BOOT_IMAGE)

@mock.patch.object(IOSDevice, "os_version", new_callable=mock.PropertyMock)
@mock.patch.object(IOSDevice, "_image_booted", side_effect=[False, True])
@mock.patch.object(IOSDevice, "set_boot_options")
@mock.patch.object(IOSDevice, "show")
@mock.patch.object(IOSDevice, "reboot")
@mock.patch.object(IOSDevice, "_wait_for_device_reboot")
@mock.patch.object(IOSDevice, "_raw_version_data")
def test_install_os_not_enough_space(
self,
mock_raw_version_data,
mock_wait,
mock_reboot,
mock_show,
mock_set_boot,
mock_image_booted,
mock_os_version,
):
mock_raw_version_data.return_value = DEVICE_FACTS
mock_os_version.return_value = "17.4.3"
mock_show.return_value = "FAILED: There is not enough free disk available to perform this operation on switch 1. At least 1276287 KB of free disk is required"
self.assertRaises(ios_module.OSInstallError, self.device.install_os, image_name=BOOT_IMAGE, install_mode=True)
mock_wait.assert_not_called()
mock_reboot.assert_not_called()


if __name__ == "__main__":
unittest.main()
Expand Down Expand Up @@ -1262,6 +1286,7 @@ def test_install_os_install_mode_with_retries(
mock_has_reload_happened_recently.side_effect = [False, False, True]
mock_image_booted.side_effect = [False, True]
mock_sleep.return_value = None
mock_show.return_value = "show must go on"
# Call the install os function
actual = ios_device.install_os(image_name, install_mode=True)

Expand Down
Loading