cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
515
Views
0
Helpful
1
Replies

PyATS: Need halp with Dialog conversation

assadniang
Level 1
Level 1

Hello,

I need help to recover the cli prompt> after a Dialog conversation:

Since PyATS Junos does not have support for linux shell# access, I am using the Dialog conversation to accomplish sending commands in shell mode

1- From cli> enter shell with 'exit' , then the prompt becomes 'root@ga-u250-s2-137-jdm:~ # '

2- Execute the command 'vhclient cp file_A file_B'

3- Reenter CLI> and execute the command 'show virtual-network-functions'

 

 

from pyats.topology import loader
from unicon.eal.dialogs import Statement, Dialog

testbed = loader.load('/opt/labs-scripts/python/pytest/nfv/suites/cisco/sdwan/tests_common_testbed/testbed_vars/devices.yaml')

device = testbed.devices['ga-u250-s2-137-jdm']

config_dialog = Dialog([
    Statement(pattern=r"root@ga-u250-s2-137-jdm:~ # ",
            action=None,
            loop_continue=False,
            continue_timer=False)])

device.connect()
assert device.connected, 'Failed to reconnect to device'
print(f"Successfully connected to {device}\n")


device.execute('exit', reply=config_dialog)
device.execute('vhclient cp /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org1', reply=config_dialog)
device.execute('show virtual-network-functions', timeout=60)

device.disconnect()

print('**********************')

 

 

This is the sequence I am trying to achieve:

 

 

root@ga-u250-s2-137-jdm> 

root@ga-u250-s2-137-jdm> exit 

root@ga-u250-s2-137-jdm:~ # vhclient cp /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org1
root@ga-u250-s2-137-jdm:~ # 
root@ga-u250-s2-137-jdm:~ # cli
root@ga-u250-s2-137-jdm> show virtual-network-functions 
ID       Name                                              State      Liveliness
--------------------------------------------------------------------------------
16       u250-s2-137-csdwan                                Running    down
1        vjunos0                                           Running    alive
6        u250-s2-137-aruba                                 Running    Not Available

root@ga-u250-s2-137-jdm> 

 

 

The last command ('show virtual-network-functions') should be executed at the cli> prompt, but it tries to execute it at the shell# prompt, and I get a 'command not found' error

Output:

 

root@ga-u250-s2-137-jdm> 
Successfully connected to Device ga-u250-s2-137-jdm, type router


2024-02-09 00:42:08,674: %UNICON-INFO: +++ ga-u250-s2-137-jdm with via 'cli': executing command 'exit' +++
exit 

root@ga-u250-s2-137-jdm:~ # 

2024-02-09 00:42:08,765: %UNICON-INFO: +++ ga-u250-s2-137-jdm with via 'cli': executing command 'vhclient cp /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org1' +++
vhclient cp /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org1
root@ga-u250-s2-137-jdm:~ # 

2024-02-09 00:42:12,798: %UNICON-INFO: +++ ga-u250-s2-137-jdm with via 'cli': executing command 'show virtual-network-functions' +++
show virtual-network-functions
show: Command not found.
root@ga-u250-s2-137-jdm:~ # 
**********************
(.venv) [an144a@DEVAUTOS02 suites]$ 

 

 

1 Reply 1

Hi,

maybe you have to use a different Dialog when prompt change?

from pyats.topology import loader
from unicon.eal.dialogs import Statement, Dialog

testbed = loader.load('/opt/labs-scripts/python/pytest/nfv/suites/cisco/sdwan/tests_common_testbed/testbed_vars/devices.yaml')

device = testbed.devices['ga-u250-s2-137-jdm']

config_dialog = Dialog([
    Statement(pattern=r"root@ga-u250-s2-137-jdm:~ # ",
            action=None,
            loop_continue=False,
            continue_timer=False)])

config_dialog_change_prompt = Dialog([
    Statement(pattern=r"root@ga-u250-s2-137-jdm>",
            action=None,
            loop_continue=False,
            continue_timer=False)])
device.connect()
assert device.connected, 'Failed to reconnect to device'
print(f"Successfully connected to {device}\n")


device.execute('exit', reply=config_dialog)
device.execute('vhclient cp /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org /var/public/c8000v-sdwan-img.17.12.01a.qcow2.org1', reply=config_dialog)
device.execute('cli', reply=config_dialog_change_prompt)

device.execute('show virtual-network-functions', timeout=60, reply=config_dialog_change_prompt)

device.disconnect()

print('**********************')