def options(): return LaunchOptions(sbatch="", connection=ConnectionData(hostname="example.com", username="******", password="******", key="key", port=1), proxyjumps=[ ConnectionData(hostname="proxy", username="******", password="******") ])
def proxy_connection() -> ConnectionData: return ConnectionData( hostname="proxy1-host", username="******", password="******", keyfile="~/proxy1-keyfile" )
def connection_data(): return ConnectionData( hostname="example.com", username="******", port=22, keyfile="~/.ssh/file", password="******")
def main_connection() -> ConnectionData: return ConnectionData( hostname="example.com", username="******", password="******", key="PRIVATE", keyfile="my_private_keyfile", )
def proxy_connection_data(proxy_index=1): return ConnectionData( hostname=f"proxy-host-{proxy_index}", username=f"proxy-user-{proxy_index}", password=f"proxy-pass-{proxy_index}", keyfile=f"proxy-keyfile-{proxy_index}", port=proxy_index )
def test__given_sshfilesystem__when_creating_new_instance_with_private_key__should_create_sshfs_with_connection_data( sshfs_type_mock): connection = ConnectionData(hostname="host", username="******", key="privatekey") sut = SSHFilesystem(connection) assert_sshfs_connected_with_private_key_from_connection_data( sshfs_type_mock, connection)
def test__when_ssh_connection_fails__should_raise_ssh_error(sshfs_type_mock): from fs.errors import CreateFailed sshfs_type_mock.side_effect = CreateFailed("Connection failed") connection = ConnectionData(hostname="host", username="******", keyfile="~/path/to/keyfile") with pytest.raises(SSHError): SSHFilesystem(connection)
def connect(self, hostname, port=None, username=None, password=None, pkey=None, key_filename=None, *args, **kwargs): self.recorded_connection_path.append( ConnectionData(hostname, username, password, key_filename, pkey, port)) self._recorded_channels.append(kwargs.get("sock"))
def test__given_config_with_only_password__when_running__should_login_to_sshfs_with_correct_credentials( sshfs_type_mock): valid_options = LaunchOptions(connection=ConnectionData( hostname="example.com", username="******", password="******"), sbatch="test.job", poll_interval=0) sut = make_sut(valid_options) sut.run(valid_options) assert_sshfs_connected_with_password_from_connection_data( sshfs_type_mock, valid_options.connection)
def test__given_config_with_only_private_keyfile__when_running__should_login_to_sshfs_with_correct_credentials( sshfs_type_mock, input_keyfile, expected_keyfile): os.environ['HOME'] = HOME_DIR valid_options = LaunchOptions(connection=ConnectionData( hostname="example.com", username="******", keyfile=input_keyfile), sbatch="test.job", poll_interval=0) sut = make_sut(valid_options) sut.run(valid_options) connection_with_resolved_keyfile = replace(valid_options.connection, keyfile=expected_keyfile) assert_sshfs_connected_with_keyfile_from_connection_data( sshfs_type_mock, connection_with_resolved_keyfile)
def _connection_data_from_dict(config: Dict[str, str]) -> ConnectionData: return ConnectionData(hostname=cast(str, expand_or_none(config["host"])), username=cast(str, expand_or_none(config["user"])), keyfile=expand_or_none( config.get("private_keyfile")), password=expand_or_none(str(config.get("password"))))
REMOTE_RESULT_FILEPATH = "remote_result.txt" ENV = { "HOME": HOME, "REMOTE_USER": REMOTE_USER, "REMOTE_HOST": REMOTE_HOST, "PROXY1_KEYFILE": PROXY1_KEYFILE, "PROXY3_PASSWORD": PROXY3_PASSWORD, "LOCAL_SLURM_SCRIPT_PATH": LOCAL_SLURM_SCRIPT_PATH, "REMOTE_SLURM_SCRIPT_PATH": REMOTE_SLURM_SCRIPT_PATH, "REMOTE_RESULT_FILEPATH": REMOTE_RESULT_FILEPATH, } CONNECTION_DATA = ConnectionData( hostname=REMOTE_HOST, username=REMOTE_USER, password="******", keyfile="/home/user/.ssh/keyfile", ) PROXYJUMPS = [ ConnectionData( hostname="proxy1.example.com", username="******", password="******", keyfile=PROXY1_KEYFILE, ), ConnectionData( hostname="proxy2.example.com", username="******", password="******", keyfile="/home/user/.ssh/proxy2_keyfile",