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

Get full RPC response in cli function #1315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dkaplan1
Copy link

junos-eznc's execute function only returns the first child element, described in

# skip the <rpc-reply> element and pass the caller first child element
# generally speaking this is what they really want. If they want to
# uplevel they can always call the getparent() method on it.
try:
ret_rpc_rsp = rpc_rsp_e[0]

Normally this isn't an issue, since commands return the full payload in one <output> as part of a <rpc-reply> i.e.

<rpc-reply message-id="xxx"><output>
Slot 0   Online       xxx
  PIC 0  Online       xxx
  PIC 1  Online       xxx
Slot 1   Online       xxx
  PIC 0  Online       xxx
  PIC 1  Online       xxx
</output></rpc-reply>

However, for some commands, like show system core-dumps, the <rpc-reply> contains multiple <output>s.

<rpc-reply message-id="urn:uuid:xxx"><output>
/var/crash/*core*: No such file or directory
</output><output>
/var/tmp/*core*: No such file or directory
</output><output>
/var/tmp/pics/*core*: No such file or directory
</output><output>
/var/crash/kernel.*: No such file or directory
</output><output>
/var/jails/rest-api/tmp/*core*: No such file or directory
</output><output>
/tftpboot/corefiles/*core*: No such file or directory
</output></rpc-reply>

In these cases, only selecting the first element means that we only select

<output>
/var/crash/*core*: No such file or directory
</output>

and cli returns just

/var/crash/*core*: No such file or directory

instead of the full output.

To fix this I'm proposing to get the parent of output message (if one exists) so that the full output of the command is returned.

@chidanandpujar chidanandpujar self-requested a review July 26, 2024 03:16
@chidanandpujar
Copy link
Collaborator

chidanandpujar commented Jul 31, 2024

Hi @dkaplan1
Thanks for the pull request.
Please find the review comments.

we are seeing one warning for following line of code.
if rsp.tag in "output" and rsp.getparent():

can be changed to
if rsp.tag in "output" and rsp.getparent() is not None:

Please check if it can be fixed, otherwise the cli response has the full response.

/root/pyez_release_272/venv/lib/python3.12/site-packages/junos_eznc-2.7.1+9.ga64698b2-py3.12.egg/jnpr/junos/device.py:738: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
  if rsp.tag in "output" and rsp.getparent():

/var/crash/*core*: No such file or directory

/var/tmp/*core*: No such file or directory

/var/tmp/pics/*core*: No such file or directory

/var/crash/kernel.*: No such file or directory

/var/jails/rest-api/tmp/*core*: No such file or directory

/tftpboot/corefiles/*core*: No such file or directory



 python cli_test.py 


                     Temp  CPU Utilization (%)   CPU Utilization (%)  Memory    Utilization (%)
Slot State            (C)  Total  Interrupt      1min   5min   15min  DRAM (MB) Heap     Buffer
  0  Online           Testing   4         0        3      3      3    511        34          0
  1  Empty           
  2  Empty           
  3  Empty           
  4  Empty           
  5  Empty           
  6  Empty           
  7  Empty           
  8  Empty           
  9  Empty           
 10  Empty           
 11  Empty           


python cli_test.py 
/root/pyez_release_272/venv/lib/python3.12/site-packages/paramiko/pkey.py:100: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "cipher": algorithms.TripleDES,
/root/pyez_release_272/venv/lib/python3.12/site-packages/paramiko/transport.py:271: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "class": algorithms.TripleDES,

/var/crash/*core*: No such file or directory

/var/tmp/*core*: No such file or directory

/var/tmp/pics/*core*: No such file or directory

/var/crash/kernel.*: No such file or directory

/var/jails/rest-api/tmp/*core*: No such file or directory

/tftpboot/corefiles/*core*: No such file or directory

Thanks
Chidanand

Copy link
Collaborator

@chidanandpujar chidanandpujar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if we can change the following line from
if rsp.tag == "output" and rsp.getparent():

to
if rsp.tag in "output" and rsp.getparent() is not None:

@dkaplan1
Copy link
Author

Thanks for the review @chidanandpujar, updated.

@chidanandpujar
Copy link
Collaborator

Hi @dkaplan1
Thanks for taking care of review comments.
Fix looks to be working fine .

 python cli_test.py 
/root/pyez_release_272/venv/lib/python3.12/site-packages/paramiko/pkey.py:100: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "cipher": algorithms.TripleDES,
/root/pyez_release_272/venv/lib/python3.12/site-packages/paramiko/transport.py:271: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "class": algorithms.TripleDES,

/var/crash/*core*: No such file or directory

/var/tmp/*core*: No such file or directory

/var/tmp/pics/*core*: No such file or directory

/var/crash/kernel.*: No such file or directory

/var/jails/rest-api/tmp/*core*: No such file or directory

/tftpboot/corefiles/*core*: No such file or directory


                     Temp  CPU Utilization (%)   CPU Utilization (%)  Memory    Utilization (%)
Slot State            (C)  Total  Interrupt      1min   5min   15min  DRAM (MB) Heap     Buffer
  0  Online           Testing   3         0        3      3      3    511        34          0
  1  Empty           
  2  Empty           
  3  Empty           
  4  Empty           
  5  Empty           
  6  Empty           
  7  Empty           
  8  Empty           
  9  Empty           
 10  Empty           
 11  Empty           

Thanks
Chidanand

Copy link
Collaborator

@chidanandpujar chidanandpujar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

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

Successfully merging this pull request may close these issues.

2 participants