question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

send_command expect string and delay_factor

See original GitHub issue

Hi,

Context I’m having a hard time figuring out how expect_string and delay_factor work together. I need to script a cisco 2960X stack upgrade which include the painful step of sending “archive download-sw flash:tarfile”. This step is high CPU consuming on the switch part and it takes forever (more than an hour and a half). Using ANSIBLE, i’haven’t found a effective way of checking when this step is ending, that is why i’m turning to Nornir + Netmiko. However I’ve been POCing this with a “write mem” command which can take a while as well depending on the load size of the stack.

Setup I’m running the following against a single switch for test purposes:

start_time = time.time()
nr = InitNornir()

result = nr.run(
    task=netmiko_send_command,
    command_string="write mem",
    expect_string="OK",
    delay_factor=50,
)

print_result(result)
print(f"{time.time() - start_time} seconds")

Ouput PS C:\Users\WWW\production\nornir> python .\nornir_writemem.py netmiko_send_command************************************************************

  • labnxp ** changed : False ****************************************************vvvv netmiko_send_command ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO Building configuration… [OK] ^^^^ END netmiko_send_command ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24.849318027496338 seconds

Expected output I’m expecting the run to stop as soon as OK appears in the output. I’ve set delay to 50 just to adjust timeout to 50 seconds in case it doesn’t find it.

I expected it to finish in 5 seconds.

Is my understanding of the send_command options wrong ? When does it check the output content ? Can we control it ?

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Oct 12, 2021

@MichalObs97 You have a couple of options:

  1. Use the Netmiko develop branch (which is Netmiko 4.X code). This entire delay_factor/fast_cli/max_loops has been reworked and largely replaced with a much simpler timeout.
  2. Set fast_cli=False as a ConnectHandler argument and then you should be back in the 100 seconds for send_command() timing mode. Given that you are doing a long running operation (several minutes), you will want to have fast_cli=False if you are using the Netmiko 3.4.0 code.
0reactions
MichalObs97commented, Oct 12, 2021

@ktbyers Hi. I’ve looked into what was detailed here and also other posts. My problem is that I used fast_cli=true, and that seems to have completely changed the timing of 100 seconds. I am uploading new image to a WLC which is a process that takes around 5-7 minutes and according to the 100 seconds calculations delay around 5 should be plenty. Currently with fast_cli on true I have to have delay_factor on 99999 for it to surely work. Do you know how does timing change with fast_cli? Or you recommend to just turn it off? (I would profit from it being on). Thank you for your time and help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Netmiko4 read_timeout - Python for Network Engineers
This problem is delay factor and global delay factor. ... As expected 'send_command()' fails in ten seconds and it raises an exception (in ......
Read more >
Netmiko timesout inspite of delay_factor=4 - OSError
Hence, to avoid unwanted timeouts, I included the 'delay_factor = 5' argument for netmiko.ConnectHandler.send_command().
Read more >
Handling Prompts from sent commands - Patrick Denis
Next step is to create a condition to shrink that code : using ':' as the expected string. but its not working yet...
Read more >
netmiko API documentation - GitHub Pages
:param delay_factor_compat: Set send_command and send_command_timing back to using Netmiko 3.x behavior for delay_factor/global_delay_factor/max_loops.
Read more >
SendCommand - AWS Systems Manager
Type: String ... key-value pairs to identify the managed nodes to send commands to, you can a send command to tens, hundreds, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found