I try to install new software on Cisco IOSXE switch. When using the expected_string, the output did not come out as expected and the script terminated. Here is the script.
from netmiko import ConnectHandler, file_transfer, redispatch
class IOSAPPLY:
def ios_apply(self, device, ipadd):
net_connect = ConnectHandler(**device)
output = net_connect.send_command(
command_string='install add file flash:cat9k_iosxe.17.06.03.SPA.bin activate commit',
expect_string=r"re-enter the command",
strip_prompt=False,
strip_command=False
)
output += net_connect.send_command(
command_string="n",
# expect_string=r"PACKAGE",
strip_prompt=False,
strip_command=False
)
net_connect.disconnect()
print(output)
if __name__ == '__main__':
device = {
"device_type": "cisco_xe",
"ip": "****",
"username": "***",
"password": "****",
"port": '22'
}
IOSAPPLY().ios_apply(device,"ipadd")
This is the output if I manually type in command
sw1#$ file flash:cat9k_iosxe.17.06.03.SPA.bin activate commit
install_add_activate_commit: START Tue Aug 29 04:05:05 UTC 2023
System configuration has been modified.
Press Yes(y) to save the configuration and proceed.
Press No(n) for proceeding without saving the configuration.
Press Quit(q) to exit, you may save configuration and re-enter the command. [y/n/q]n
install_add_activate_commit: Adding PACKAGE
install_add_activate_commit: Checking whether new add is allowed ....
--- Starting Add ---
Performing Add on Active/Standby
[1] Add package(s) on R0
[1] Add succeed on R0 with reason:"Same Image File-No Change"
[1] Finished Add on R0
Checking status of Add on [R0]
Add: Passed on [R0]
Finished Add
SUCCESS: install_add_activate_commit Tue Aug 29 04:06:54 UTC 2023
This is the output from script
install add file flash:cat9k_iosxe.17.06.03.SPA.bin activate commit
install_add_activate_commit: START Tue Aug 29 04:25:13 UTC 2023
System configuration has been modified.
Press Yes(y) to save the configuration and proceed.
Press No(n) for proceeding without saving the configuration.
Press Quit(q) to exit, you may save configuration and re-enter the command. [y/n/q]
[y/n/q]n/q]n^J
I suspect this issue is at [y/n/q]n/q]n^J, but I do not know how did I trigger it.