cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
227
Views
0
Helpful
3
Replies

Using PyATS/Unicon execute / dialog API

dbillon
Level 1
Level 1

Hi Guys,

I have to write a Python function to launch a file copy using ftp on IOSXE (no PyATS API available for this ... with vrf option).

So I discovered Unicon, the execute API, the reply/dialog option to validate expected questions from the CLI and the error_pattern option to detect errors returned by the IOS.

I find myself trying to guess the expected errors that could from a "copy ftp://..." command.

I simulated several errors and so far I wrote the following error_pattern:

out = device.execute(cmd,reply=dialog, timeout=timeout, error_pattern=['^%Error', '^% Unable', '% Invalid'])

Anyway I'm not sure I have listed all error patterns that could come up from such a command.

Are you aware of some "standard" error_pattern that would gather all kind of errors generated by the CLI of the IOSXE ?

BR, Damien.

 

3 Replies 3

@dbillon is this the execute command mentioned here in your other thread? https://community.cisco.com/t5/tools/pyats-api-to-scp-from-the-pyats-client-to-a-device/td-p/5325825/jump-to/first-unread-message

I see the problem you mentioned, from what i recall the reasons a single standards errors pattern does not exist is that different XE commands, and even different versions of XE, can produce a wide variety of fun (sometime confusing) error messages in your logs. Yuo have already build something great here to catch the common errors, there is few more to add, timeout, fail, refused etc.. I would use raw strings for best pratice when bulding something like this. If you wanted to get a lot more you could add %.*?% - but, this might be an informational or warning message that doesn't indicate a problem/failure. 

Logging is tricky, getting the balance of helpful and where there is a problem, versus false flags and making lots of noise with verbose logging ... 

Hope this helps.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Yes, I'm investing the same question with a different approach:

  • I'm not supposed to modify the IOS configurations that are tested in the lab ... and scp server is not activated in those configurations
  • Furthermore I've tested the throughput and SCP is way slower than FTP (5 times slower on a C8200L) ... I read that some IOS parameters could be modified to improve this throughput but once more I don't want to modify IOS configuration
  • So this time I'm investigating transfering the files using FTP from the IOS

Actually I read that several "Dialog patterns" have been collected in Unicon doc ... so I thought I would have found some generic error pattern too. But nothing so far.

One thing puzzles me : when I read for example the function "copy_file_with_scp" from Genie API (on Github), I don't see how they catch any error since they are not using error_pattern:

out = device.execute(cmd,reply=dialog, timeout=timeout)

BR, Damien.

Ok did not want to cross post or think your other issue you asked about, we resolved. 

 

It is a good question about this and so from what i recall (please check, my brain is on 50% function for this stuff these days) When you do not see an explicit error pattern in a pyats execute command, i understnad the reason is the underlying unicon library provides a  multi layered approach to error handling. Instead of relying on a single argument, this  has a built in set of predefined, generic error patterns (like %Error or % Invalid input) for each operating system.
 
So is an command's output matches one of these, it automatically raises the exception. Also, the timeout argument acts as a first line of defense and if a command doesn't return a prompt within the allotted time, it's considered a failure. For interactive commands, the dialog object is key, as it allows you to define specific statement objects, each with its own pattern to handle expected prompts and potential command specific errors.
 
Therefore, a function like copying via scp doesn't need to specify an explicit error pattern because it relies on the, low level unicon logic to catch common errors and timeouts. I might be wrong and think this was changed in https://developer.cisco.com/docs/pyats/21-3/ this why unicon has a built in, default set of error patterns. 
 
Happy to be corrected here.
Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io