CiscoTestAutomation / pyats

Cisco DevNet pyATS Test Framework Bug Tracker
Apache License 2.0
149 stars 31 forks source link

unable to connect via ssh to iosxe device with banner ending with # #151

Closed petertavenier closed 2 years ago

petertavenier commented 2 years ago

Hi, I'm using PyATS, but I was unable to connect to an IOSXE device ASR920 with the 'os: iosxe'. It took me a while to figure out, but this was caused by a banner, ssh and os combination.

I try to retrieve a 'show version', via genie parse "show version" --testbed-file testbed.yaml --device asr -v but this happened:

(venv) user@host:~/pyats$ cat /tmp/ASR920-cli-20220217T173113658.log

2022-02-17 17:31:13,659: %UNICON-INFO: +++ ASR920 logfile /tmp/ASR920-cli-20220217T173113658.log +++

2022-02-17 17:31:13,659: %UNICON-INFO: +++ Unicon plugin iosxe +++
C
**********#
* banner  #
**********#

2022-02-17 17:31:14,516: %UNICON-INFO: +++ connection to spawn: ssh -l cisco <IP>, id: 140097693951760 +++

2022-02-17 17:31:14,517: %UNICON-INFO: connection to ASR920

2022-02-17 17:31:14,590: %UNICON-WARNING: Invalid hostname detected: found **********, expected ASR920

2022-02-17 17:31:14,591: %UNICON-INFO: +++ initializing handle +++

Password:
(venv) user@host:~/pyats$

This message is the issue; 2022-02-17 17:31:14,590: %UNICON-WARNING: Invalid hostname detected: found ****, expected ASR920**

The testbed file looks like;

  ASR920:
    alias: asr
    type: ASR920
    os: iosxe
    credentials:
      default:
        username: "%ENV{PYATS_USERNAME}"
        password: "%ENV{PYATS_PASSWORD}"
      enable:
        password: "%ENV{PYATS_ENABLE}"
    connections:
      vty:
        protocol: ssh
        ip: "%ENV{IP_ASR}"

Three options gives a workaround for this connection issue;

  1. Changing the testbed file protocol: telnet and it works without any problems!
  2. Changing the testbed file os: ios and it works without any problems even with protocol: ssh!
  3. Changing the banner on the Cisco ASR920 device that is it not ending with a #

Old banner, iosxe + ssh not working!

banner login ^C
**********#
* banner  #
**********#
^C

Old banner, iosxe + ssh working fine!

banner login ^C
**********#
* banner  #
***********
^C
LukasMcClelland commented 2 years ago

Hello @petertavenier,

Thanks for letting us know about this issue and also my apologies for the delay in response. Thank you for putting together such an informative error report as well, always nice to see 👍

The behavior you've described does makes sense as Unicon connection is expecting to see a prompt pattern ending with a #, so it matches **********# and think it's the hostname of the device. You can set up your own Dialog to match the above banner and then ignore it so that it doesn't affect device connection.

Is a banner like this a common thing for you to see? Is it unique to your situation or a common IOSXE behavior? I only ask because I haven't seen this exact issue before

LukasMcClelland commented 2 years ago

Closing issue, but please reopen and reply if this issue is still giving you trouble. Thanks again for reaching out