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

Close transport / transport & channel, if an exception occurs during creation. #36

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions netconf_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,18 @@ def connect_ssh(
transport = paramiko.transport.Transport(sock)
pkey = _try_load_pkey(key_filename) if key_filename else None
hostkey = _try_load_hostkey_b64(hostkey_b64) if hostkey_b64 else None
transport.connect(hostkey=hostkey, username=username, password=password, pkey=pkey)
channel = transport.open_session(timeout=general_timeout)
channel.invoke_subsystem("netconf")
transport.connect(username=username, password=password, pkey=pkey)
try:
channel = transport.open_session()
except Exception:
transport.close()
raise
try:
channel.invoke_subsystem("netconf")
except Exception:
channel.close()
transport.close()
raise
bundle = SshSessionSock(sock, transport, channel)
return Session(bundle)

Expand Down