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.

Redispatch failing due to no data being present

See original GitHub issue

Hello,

This used to work before I upgrade from version 3.4.0 to version 4.1.1

Not sure why it is failing on the juniper device:

#Use the redispatch method (to switch the Netmiko class to a Juniper)
    redispatch(net_connect, device_type='juniper_junos')
    
    net_connect.send_command('cli', expect_string=r'>')
    
    output = net_connect.send_command('show configuration | display set')
    
    if f'vcsr-{domain}' in output:
        print(f'Found vcsr-{domain}')
        print(f'>>> Deleting vcsr-{domain} instance')
        net_connect.send_config_set(f'delete virtual-machines instance vcsr-{domain}',\
             exit_config_mode = False)
        output = net_connect.commit(and_quit=True)
        
        if 'commit complete' in output:
            print(output)
            print(Fore.LIGHTGREEN_EX + 'Success!')
        else:
            print(Fore.RED + f'Could not delete vcsr-{domain} instance')
            net_connect.disconnect()
            quit()
    else:
        print(f'No vcsr-{domain} instance running')
    
    net_connect.send_command('exit', expect_string=r'#')

Output:

Checking if any vnf are running: vcsr-a Traceback (most recent call last): File “./CSR1000V_License_Stage.py”, line 1467, in <module> check_vnf_running() File “./CSR1000V_License_Stage.py”, line 275, in check_vnf_running redispatch(net_connect, device_type=‘juniper_junos’) File “/usr/local/lib/python3.8/site-packages/netmiko/ssh_dispatcher.py”, line 449, in redispatch obj._try_session_preparation() File “/usr/local/lib/python3.8/site-packages/netmiko/base_connection.py”, line 879, in _try_session_preparation self.session_preparation() File “/usr/local/lib/python3.8/site-packages/netmiko/juniper/juniper.py”, line 20, in session_preparation self._test_channel_read(pattern=pattern) File “/usr/local/lib/python3.8/site-packages/netmiko/base_connection.py”, line 1119, in _test_channel_read return self.read_until_pattern(pattern=pattern, read_timeout=20) File “/usr/local/lib/python3.8/site-packages/netmiko/base_connection.py”, line 651, in read_until_pattern raise ReadTimeout(msg) netmiko.exceptions.ReadTimeout:

Pattern not detected: ‘[%>$#]’ in output.

Things you might try to fix this:

  1. Adjust the regex pattern to better identify the terminating string. Note, in many situations the pattern is automatically based on the network device’s prompt.
  2. Increase the read_timeout to a larger value.

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

Log file shows this:

DEBUG:netmiko:read_channel: root@ptr53-jdm:~# DEBUG:netmiko:Pattern found: ([$#]) Last login: Tue Jul 19 00:36:24 2022 from fd:192:168:53::250 root@ptr53-jdm:~# DEBUG:netmiko:read_channel: DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: root@ptr53-jdm:~# DEBUG:netmiko:Pattern found: ([$#]) root@ptr53-jdm:~# DEBUG:netmiko:read_channel: DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is root@ptr53-jdm:~# DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’\n’ DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: root@ptr53-jdm:~# DEBUG:netmiko:Pattern found: ([$#]) root@ptr53-jdm:~# DEBUG:netmiko:read_channel: DEBUG:netmiko:Clear buffer detects data in the channel DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is root@ptr53-jdm:~# DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: … … … …

I also tried commenting this line, but same issue: #net_connect.send_command('cli', expect_string=r'>')

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
assadniangcommented, Jul 27, 2022

@ktbyers

Finally got it working…

Thank you!!!

The reason I had it set to linux initially, is I wanted to run some linux command at the shell when I am not doing junos config changes

Output:

>>> Connecting to uCPE: ptr53-jdm
root@ptr53-jdm>
Successfully connected to uCPE

>>> Checking if any vnf are running: vcsr-a
set virtual-machines instance vcsr-a descriptor-file-name /var/third-party/vcsr_a.xml

Found vcsr-a
>>> Deleting vcsr-a instance
commit and-quit 
commit complete
Exiting configuration mode

{master:0}
root@ptr53-jdm> 
Success!


>>> Deleting QCOW2 files in /images_a folder
cd /var/third-party/images_a
root@ptr53-jdm:/var/third-party/images_a# rm csr1000v*
root@ptr53-jdm:/var/third-party/images_a# 

>>> Creating xml file: vcsr_a.xml
Verifying vcsr_a.xml file is created
Success!
root@ptr53-jdm:/var/third-party# 
Successfully created vcsr_a.xml

Code:

############# MTLAB-AUTO SSH Parameters
ssh_juniper_ucpe = {
    'device_type': 'juniper_junos',
    'host': target_host,
    'username': 'root',
    'password': 'juniper123',
}

#Use the redispatch method (to switch the Netmiko class to a Juniper)
    #redispatch(net_connect, device_type='juniper_junos')
    
    #net_connect.send_command('cli', expect_string=r'>')    
    
    output = net_connect.send_command('show configuration | display set | match vcsr')
    print(output)

    if f'vcsr-{domain}' in output:
        print(f'Found vcsr-{domain}')
        print(f'>>> Deleting vcsr-{domain} instance')
        net_connect.send_config_set(f'delete virtual-machines instance vcsr-{domain}',\
             exit_config_mode = False)
        output = net_connect.commit(and_quit=True)
        
        if 'commit complete' in output:
            print(output)
            print(Fore.LIGHTGREEN_EX + 'Success!')
        else:
            print(Fore.RED + f'Could not delete vcsr-{domain} instance')
            net_connect.disconnect()
            quit()
    else:
        print(f'No vcsr-{domain} instance running')
0reactions
ktbyerscommented, Jul 27, 2022

@assadniang Okay, I merged that pull-request into the Netmiko develop branch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hands-On Tutorial: Repartition a Non-partitioned Dataset
Redispatch partitioning is a powerful feature that allows you to deal with datasets that have not been designed in a way that makes...
Read more >
How to clone or re-dispatch DOM events? - Stack Overflow
There's a DOM exception stating that the event is currently being dispatched - obviously. I'd like to avoid manually creating new events with...
Read more >
Reliability: Disaster planning | BigQuery - Google Cloud
There are two types of failures, soft failures and hard failures. Soft failure is an operational deficiency where hardware is not destroyed. Examples...
Read more >
Natural wind variability triggered drop in German redispatch ...
Offshore wind parks are not georeferenced in the input data and they ... Since the German electricity grid is currently being expanded in ......
Read more >
Proactive Generation Redispatch to Enhance Power System ...
Impacts of load and renewable energy variations, future potential failures, event attack time, and enhancement implementation time have not been ...
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