scrapli/scrapli_community

prompts for huawei HA setup

alsigna opened this issue · 1 comments

Describe the bug
Timed out while connecting to device.

To Reproduce
Steps to reproduce the behavior:

  1. Your script
from scrapli import Scrapli
device = {
    "host": "192.168.255.1",
    "auth_username": "admin",
    "auth_password": "admin",
    "auth_strict_key": False,
    "ssh_config_file": "./config/ssh_config",
    "platform": "huawei_vrp",
}
ssh = Scrapli(**device)
ssh.open()
  1. What you're connecting to (vendor, platform, version)
    • Vendor: Huawei
    • Platform: USG6500E
    • Version: V600R007C20SPC100

Expected behaviour
Prompt detect successfully, connection can be opened.

Stack Trace

DEBUG:scrapli.channel:read: b'(admin@192.168.255.1) Password: '
DEBUG:scrapli.channel:write: REDACTED
DEBUG:scrapli.channel:write: '\n'
DEBUG:scrapli.channel:read: b'\nHRP_M<hostname1>'
CRITICAL:scrapli.channel:operation timed out, closing connection
DEBUG:scrapli.transport:closing transport connection to '192.168.255.1' on port '22'
CRITICAL:scrapli.transport:encountered EOF reading from transport; typically means the device closed the connection
DEBUG:scrapli.transport:transport connection to '192.168.255.1' on port '22' closed successfully
---------------------------------------------------------------------------
ScrapliTimeout                            Traceback (most recent call last)
Cell In [4], line 1
----> 1 ssh.open()

File ~/.../venv/lib/python3.10/site-packages/scrapli/driver/base/sync_driver.py:88, in Driver.open(self)
     85 self.channel.open()
     87 if self.transport_name in ("system",) and not self.auth_bypass:
---> 88     self.channel.channel_authenticate_ssh(
     89         auth_password=self.auth_password,
     90         auth_private_key_passphrase=self.auth_private_key_passphrase,
     91     )
     92 if (
     93     self.transport_name
     94     in (
   (...)
     98     and not self.auth_bypass
     99 ):
    100     self.channel.channel_authenticate_telnet(
    101         auth_username=self.auth_username, auth_password=self.auth_password
    102     )

File ~/.../venv/lib/python3.10/site-packages/scrapli/decorators.py:216, in timeout_wrapper.<locals>.decorate(*args, **kwargs)
    209 cls_name = transport.__class__.__name__
    211 if (
    212     cls_name in ("SystemTransport", "TelnetTransport")
    213     or _IS_WINDOWS
    214     or threading.current_thread() is not threading.main_thread()
    215 ):
--> 216     return _multiprocessing_timeout(
    217         transport=transport,
    218         logger=logger,
    219         timeout=timeout,
    220         wrapped_func=wrapped_func,
    221         args=args,
    222         kwargs=kwargs,
    223     )
    225 callback = partial(
    226     _signal_raise_exception,
    227     transport=transport,
    228     logger=logger,
    229     message=_get_timeout_message(wrapped_func.__name__),
    230 )
    232 old = signal.signal(signal.SIGALRM, callback)

File ~/.../venv/lib/python3.10/site-packages/scrapli/decorators.py:108, in _multiprocessing_timeout(transport, logger, timeout, wrapped_func, args, kwargs)
    106 wait([future], timeout=timeout)
    107 if not future.done():
--> 108     return _handle_timeout(
    109         transport=transport,
    110         logger=logger,
    111         message=_get_timeout_message(func_name=wrapped_func.__name__),
    112     )
    113 return future.result()

File ~/.../venv/lib/python3.10/site-packages/scrapli/decorators.py:134, in _handle_timeout(transport, logger, message)
    132 logger.critical("operation timed out, closing connection")
    133 transport.close()
--> 134 raise ScrapliTimeout(message)

ScrapliTimeout: timed out during in channel ssh authentication

OS (please complete the following information):

  • OS: MacOS 12.6
  • scrapli version: 2022.7.30.post1
  • scrapli_community version: 2022.7.30

Additional context
Prefix HRP_[M|S] is added to the device prompt in HA setup, like this:

# master node
HRP_M<hostname1>
HRP_M<hostname1>system-view 
Enter system view, return user view with Ctrl+Z.
HRP_M[hostname1]quit

# standby node
HRP_S<hostname2>
HRP_S<hostname2>system-view 
Enter system view, return user view with Ctrl+Z.
HRP_S[hostname2]quit

So current patters of huawei_vrp does not math with it. Locally we are using below modification of standard patterns (added (?:hrp_[m|s])?):

DEFAULT_PRIVILEGE_LEVELS = {
    "privilege_exec": (
        PrivilegeLevel(
            pattern=r"^(?:hrp_[m|s])?<[a-z0-9.\-_@()/:]{1,48}>\s*$",
...
    "configuration": (
        PrivilegeLevel(
            pattern=r"^(?!\[V\d{3}R\d{3}C\d{2,3}.*\])(?=(?:hrp_[m|s])?\[\~{0,1}\*{0,1}[a-z0-9.\-_@/:]{1,64}\]$).*$"
...

Could you please consider to modify patterns of huawei_vrp for matching prompts of HA setups.

Hi @alsigna

Feel free to open a PR - as long as you've got tests to cover the new patterns and things are looking reasonable I'll get it merged.

Carl