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

underlying scrapli connection is not open. error #53

Open
nielsvanhooy opened this issue Mar 22, 2024 · 4 comments
Open

underlying scrapli connection is not open. error #53

nielsvanhooy opened this issue Mar 22, 2024 · 4 comments

Comments

@nielsvanhooy
Copy link

nielsvanhooy commented Mar 22, 2024

Hi there. i was working again on a side project i started a while back. But im running into a problem (of what im sure used to work before).

Before, i could make a connection to a device and pass it on to scrapli-cfg. but now it seems only to be working when i pass the option dedicated_connection. (i was hoping to get it to work without starting another connection).

The testcode setup.

async def test():
    device = {
        "host": "10.1.1.156",
        "auth_username": "lagen008",
        "auth_password": "lagen008",
        "auth_strict_key": False,
        "transport": "asyncssh",
        "ssh_config_file": "/Users/nielsvanhooij/git/new_bifrost_repos/phantom_communicator/phantom_communicator/config",
    }
    conn = AsyncIOSXEDriver(**device)
    cfg_conn = AsyncScrapliCfgIOSXE(conn=conn, dedicated_connection=True)
    await cfg_conn.prepare()
    version_result = await cfg_conn.get_version()
    print(version_result.result)

##### the above code works (but needs dedicated_connection=True).


    session = AsyncIOSXEDriver(**device)
    await session.open()
    cfg_conn = AsyncScrapliCfgIOSXE(conn=session)
    await cfg_conn.prepare()
    version_result = await cfg_conn.get_version()
    print(version_result.result)


### Above code doenst work and results in error (see below). but im very sure this used to work a while back.

asyncio.run(test())

Error below

    await cfg_conn.prepare()
  File "/Users/nielsvanhooij/Library/Caches/pypoetry/virtualenvs/phantom-communicator-EZUl1H7x-py3.12/lib/python3.12/site-packages/scrapli_cfg/platform/base/async_platform.py", line 158, in prepare
    await self._open()
  File "/Users/nielsvanhooij/Library/Caches/pypoetry/virtualenvs/phantom-communicator-EZUl1H7x-py3.12/lib/python3.12/site-packages/scrapli_cfg/platform/base/async_platform.py", line 119, in _open
    raise ScrapliCfgException(
scrapli_cfg.exceptions.ScrapliCfgException: underlying scrapli connection is not open and `dedicated_connection` is False, cannot continue!

please let me know your thoughts on this.

kind regards.
Niels

@carlmontanari
Copy link
Contributor

what does session.conn.isalive() return? thats all it checks for. if thats foobar that is probably upstream scrapli issue. does a sync transport work?

@nielsvanhooy
Copy link
Author

Hi there. so it seems that both variant in async give conn.isalive() is False.
in the sync variants it works. and shows nicely conn.isalive() is True


def test_sync():
    device = {
        "host": "10.1.1.156",
        "auth_username": "lagen008",
        "auth_password": "lagen008",
        "auth_strict_key": False,
        "ssh_config_file": "/Users/nielsvanhooij/git/new_bifrost_repos/phantom_communicator/phantom_communicator/config",
    }

    conn = IOSXEDriver(**device)
    cfg_conn = ScrapliCfgIOSXE(conn=conn)
    conn.open()
    alive = conn.isalive(). <--------------------------- True (no dedicated connection needed)
    cfg_conn.prepare()
    version_result = cfg_conn.get_version()
    print(version_result.result)

test_sync()


the async variant:


async def test():
    device = {
        "host": "10.1.1.156",
        "auth_username": "lagen008",
        "auth_password": "lagen008",
        "auth_strict_key": False,
        "transport": "asyncssh",
        "ssh_config_file": "/Users/nielsvanhooij/git/new_bifrost_repos/phantom_communicator/phantom_communicator/config",
    }
    conn = AsyncIOSXEDriver(**device)
    cfg_conn = AsyncScrapliCfgIOSXE(conn=conn, dedicated_connection=True)
    await conn.open()
    alive = conn.isalive(). <---------------------------------- gives False
    await cfg_conn.prepare()
    version_result = await cfg_conn.get_version()
    print(version_result.result)

    session = AsyncIOSXEDriver(**device)
    await session.open()
    alive_two = session.isalive(). <---------------------------------- gives False
    cfg_conn = AsyncScrapliCfgIOSXE(conn=session)
    await cfg_conn.prepare()
    version_result = await cfg_conn.get_version()
    print(version_result.result)

asyncio.run(test())

@carlmontanari
Copy link
Contributor

copy, thanks for reporting back! will check this more hopefully this weekend. if you have time to look in upstream scrapli to see what's what that would be great too!

@carlmontanari
Copy link
Contributor

hey again @nielsvanhooy

could ya drop some prints like this after you open an async connection?

    print(f"isalive?                       -> {conn.isalive()} ")
    print(f"conn session                   -> {conn.transport.session is not None}")
    print(f"conn auth                      -> {conn.transport.session._auth_complete}")
    print(f"conn session transport         -> {conn.transport.session._transport is not None}")
    print(f"conn session transport closing -> {conn.transport.session._transport.is_closing()}")

these are all the things that are evaluated for asyncssh transport "isalive" check -- this check seems to work ok for me so just wondering which of these is not happy for your device/platform. everything "should" say True minus the last one which should be False.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants