Add ssh opening functions and test.

This commit is contained in:
Pablo Martin 2023-01-23 18:38:12 +01:00
parent dd07cd7959
commit 8c66a843b9
2 changed files with 106 additions and 1 deletions

View file

@ -1,7 +1,12 @@
import pathlib
from lolafect.lolaconfig import build_lolaconfig
from lolafect.connections import connect_to_trino, close_trino_connection, _temp_secret_file_from_s3
from lolafect.connections import (
connect_to_trino,
close_trino_connection,
_temp_secret_file_from_s3,
open_ssh_tunnel_with_s3_pkey,
)
# __ __ _____ _ _ _____ _ _ _____ _
# \ \ / /\ | __ \| \ | |_ _| \ | |/ ____| |
@ -72,3 +77,18 @@ def test_temporal_download_of_secret_file_works_properly_even_with_exception():
temp_file_found_when_in_context_manager
and temp_file_missing_when_outside_context_manager
)
def test_opening_and_closing_ssh_tunnel_works_properly():
tunnel = open_ssh_tunnel_with_s3_pkey.run(
s3_bucket_name=TEST_LOLACONFIG.S3_BUCKET_NAME,
ssh_tunnel_credentials=TEST_LOLACONFIG.SSH_TUNNEL_CREDENTIALS,
remote_target_host=TEST_LOLACONFIG.DW_CREDENTIALS["host"],
remote_target_port=TEST_LOLACONFIG.DW_CREDENTIALS["port"],
)
tunnel_was_active = tunnel.is_active
tunnel.close()
tunnel_is_no_longer_active = not tunnel.is_active
assert tunnel_was_active and tunnel_is_no_longer_active