Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netmiko error trying to install Cisco ios xe firmware #3470

Open
bkyarnell opened this issue Aug 3, 2024 · 6 comments
Open

netmiko error trying to install Cisco ios xe firmware #3470

bkyarnell opened this issue Aug 3, 2024 · 6 comments

Comments

@bkyarnell
Copy link

bkyarnell commented Aug 3, 2024

Description of Issue/Question

I haven't been able to clear this error and looking for advise. The line the traceback is coming from :

net_scp_connect.send_command('y', 
       strip_prompt=False,
       strip_command=False,
       read_timeout=10
)

I've tried adding an expect state to the above, expect_string=r'#', but it also throws the same traceback. The code runs with the firmware being installed, but trying to clean this up. I'm sure it's an issue with me trying to scrape the output correctly. Any advise?

From the session log, netmiko-log.txt:

  Host1#install add file flash:csr1000v-universalk9.17.03.08a.SPA.bin activate commit
  install_add_activate_commit: START Sat Aug  3 14:32:00 UTC 2024
  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] Finished Add on R0
  Checking status of Add on [R0]
  Add: Passed on [R0]
  Finished Add
  
  Image added. Version: 17.03.08a.0.6
  install_add_activate_commit: Activating PACKAGE
  Following packages shall be activated:
  /bootflash/csr1000v-rpboot.17.03.08a.SPA.pkg
  /bootflash/csr1000v-mono-universalk9.17.03.08a.SPA.pkg
  
  This operation may require a reload of the system. Do you want to proceed? [y/n]
   [y/n]^J
   [y/n]y^J
  --- Starting Activate ---
  Performing Activate on Active/Standby
  
  exit

Note: Please check https://guides.github.com/features/mastering-markdown/
to see how to properly format your request.

Setup

Netmiko version

(Paste verbatim output from pip freeze | grep netmiko between quotes below)

netmiko==4.3.0

Netmiko device_type (if relevant to the issue)

(Paste device_type between quotes below)

host = {'device_type':device_type, 
                        'host': switch,
                        'username': Username,
                        'password': Password,
                        'secret': NetworkSecret,
                        'session_log': 'netmiko-log.txt'
                        }

where device_type = 'cisco_xe'.  I've also enabled the session log to write to netmiko-log.txt.

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

Traceback (most recent call last):
  File "/home/byarnell/scripts/Python/IS1_Firmware_Loader/Functions/IS1_Firmware_Loader_Functions.py", line 342, in install_firmware
    net_scp_connect.send_command('y',
  File "/home/byarnell/.local/lib/python3.12/site-packages/netmiko/base_connection.py", line 110, in wrapper_decorator
    return_val = func(self, *args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/byarnell/.local/lib/python3.12/site-packages/netmiko/utilities.py", line 595, in wrapper_decorator
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/byarnell/.local/lib/python3.12/site-packages/netmiko/base_connection.py", line 1824, in send_command
    raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '\\[y/n\\]' in output.

Things you might try to fix this:
1. Explicitly set your pattern using the expect_string argument.
2. Increase the read_timeout to a larger value.

You can also look at the Netmiko session_log or debug log for more information.

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue)
(Paste the code between the quotes below)

cmd1 = 'install add file flash:' + firmware_file_name + ' activate commit'
net_scp_connect.send_command(cmd1, 
       expect_string=r'This operation may require a reload of the system', 
       strip_prompt=False,
       strip_command=False,
       read_timeout=500
)
time.sleep(5)
net_scp_connect.send_command('y', 
       strip_prompt=False,
       strip_command=False,
       read_timeout=10
 )
@ktbyers
Copy link
Owner

ktbyers commented Aug 3, 2024

It looks like the pattern and your code don't match?

Pattern not detected: '\\[y/n\\]' in output.

Here it looks like you are looking for a [y/n] pattern?

@bkyarnell
Copy link
Author

bkyarnell commented Aug 3, 2024

Yes, it does seem that way. These are the lines I'm trying to catch and throw a reply:

install add file flash:csr1000v-universalk9.17.03.07.SPA.bin activate commit
This operation may require a reload of the system. Do you want to proceed? [y/n]y

I was hoping expect_string=r'This operation may require a reload of the system' would capture? I've tried a lot of variation with that without luck.

@ktbyers
Copy link
Owner

ktbyers commented Aug 5, 2024

Can you post the full exception stack that you receive (when you use this code that you posted):

cmd1 = 'install add file flash:' + firmware_file_name + ' activate commit'
net_scp_connect.send_command(cmd1, 
       expect_string=r'This operation may require a reload of the system', 
       strip_prompt=False,
       strip_command=False,
       read_timeout=500
)
time.sleep(5)
net_scp_connect.send_command('y', 
       strip_prompt=False,
       strip_command=False,
       read_timeout=10
 )

The exception stack you posted above does not look like it matches this code (based on the output from the exception).

@bkyarnell
Copy link
Author

Agree, that's odd! But, the code and stack trace is accurate. It doesn't appear to be looking for the expect_string I'm using in the code.
expect_string=r'This operation may require a reload of the system'.
It throws the exception, but the send command 'y' seems to be allowing it to progress.

@ktbyers
Copy link
Owner

ktbyers commented Aug 6, 2024

Add an expect_string onto this second call as well:

net_scp_connect.send_command('y', 
       strip_prompt=False,
       strip_command=False,
       read_timeout=10
 )

Like expect_string=r"#" (or whatever is in the trailing prompt)

@bkyarnell
Copy link
Author

bkyarnell commented Aug 6, 2024

I tried some variation in the code with try/except/finally, but didn't really change anything. Line 398 in the Exception is in the Finally statements. I've also increased the read_timeout for the 'y' reply to 100 - no change. Maybe higher? End result, code completes and the update occurs. But, the Exception is annonying!

cmd1 = 'install add file flash:' + firmware_file_name + ' activate commit'
try:
      net_scp_connect.send_command(cmd1,
             expect_string=r"This operation may require a reload of the system", 
             strip_prompt=False,
             strip_command=False,
             read_timeout=500
      )
except Exception:
      time.sleep(5)
      net_scp_connect.send_command('y',
             expect_string=r"#",                         
             strip_prompt=False,
             strip_command=False,
             read_timeout=10
       )
finally:
       time.sleep(5)
       net_scp_connect.send_command('y', 
              expect_string=r"#",
              strip_prompt=False,
              strip_command=False,
              read_timeout=10
       )

Exception:

`...installing csr1000v-universalk9.17.03.08a.SPA.bin on switch 10.2.0.251
Traceback (most recent call last):
  File "/home/byarnell/scripts/Python/IS1_Firmware_Loader/Functions/IS1_Firmware_Loader_Functions.py", line 398, in install_firmware
    net_scp_connect.send_command('y',
  File "/home/byarnell/.local/lib/python3.12/site-packages/netmiko/base_connection.py", line 110, in wrapper_decorator
    return_val = func(self, *args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/byarnell/.local/lib/python3.12/site-packages/netmiko/utilities.py", line 595, in wrapper_decorator
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/byarnell/.local/lib/python3.12/site-packages/netmiko/base_connection.py", line 1824, in send_command
    raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: '#' in output.

Things you might try to fix this:
1. Explicitly set your pattern using the expect_string argument.
2. Increase the read_timeout to a larger value.`

Session log:

Host1#install add file flash:csr1000v-universalk9.17.03.08a.SPA.bin activate commit
install_add_activate_commit: START Tue Aug  6 02:51:59 UTC 2024
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] Finished Add on R0
Checking status of Add on [R0]
Add: Passed on [R0]
Finished Add

Image added. Version: 17.03.08a.0.6
install_add_activate_commit: Activating PACKAGE
Following packages shall be activated:
/bootflash/csr1000v-rpboot.17.03.08a.SPA.pkg
/bootflash/csr1000v-mono-universalk9.17.03.08a.SPA.pkg

This operation may require a reload of the system. Do you want to proceed? [y/n]
 [y/n]y^J
--- Starting Activate ---
Performing Activate on Active/Standby

exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants