def test__when_calling_sbatch__should_return_job_id(sbatch_sshclient_fake): executor = SSHExecutor(main_connection()) executor.connect() sut = SlurmController(executor) actual = sut.submit("myjob.job") assert actual.jobid == DEFAULT_JOB_ID
def test__given_connection_data__when_connecting__should_connect_client(sshclient_class): sshclient_instance = sshclient_class.return_value sut = SSHExecutor(connection_data()) sut.connect() assert_connected_with_data(sshclient_instance, connection_data())
def test__when_connection_fails__should_raise_ssherror(sshclient_class): sshclient_instance = sshclient_class.return_value sshclient_instance.connect.side_effect = paramiko.AuthenticationException sut = SSHExecutor(connection_data()) with pytest.raises(SSHError): sut.connect()
def test__given_proxyjump__when_connecting__should_connect_to_destination_through_proxy(sshclient_class): mock = ProxyJumpVerifyingSSHClient(connection_data(), [proxy_connection_data()]) sshclient_class.return_value = mock sut = SSHExecutor(connection_data(), proxyjumps=[proxy_connection_data()]) sut.connect() mock.verify()
def test__given_two_proxyjumps__when_connecting__should_connect_to_proxies_then_destination(sshclient_class): jumps = [proxy_connection_data(1), proxy_connection_data(2)] mock = ProxyJumpVerifyingSSHClient(connection_data(), jumps) sshclient_class.return_value = mock sut = SSHExecutor(connection_data(), proxyjumps=jumps) sut.connect() mock.verify()
def test__when_polling_job__should_return_slurm_job_with_matching_data( sshclient_poll_running_job_fake): executor = SSHExecutor(main_connection()) executor.connect() sut = SlurmController(executor) sut.submit("myjob.job") actual = sut.poll_status(DEFAULT_JOB_ID) assert actual == running_slurm_job()
def test__given_proxyjump__when_connection_to_proxy_fails__should_raise_ssherror(sshclient_class): proxy_mock, _ = proxy_mock_with_transport() proxy_mock.connect.side_effect = paramiko.AuthenticationException sshclient_class.return_value = proxy_mock sut = SSHExecutor(connection_data(), proxyjumps=[proxy_connection_data()]) with pytest.raises(SSHError): sut.connect()
def test__given_connected_client__when_executing_command__should_return_remote_command(sshclient_class): sshclient_instance = sshclient_class.return_value sshclient_instance.exec_command.return_value = (Mock(), Mock(), Mock()) sut = SSHExecutor(connection_data()) sut.connect() actual = sut.exec_command("dummycmd") assert isinstance(actual, RemoteCommand)
def main() -> None: cli_args = parse_cli_args(sys.argv[1:]) with RichUI() as ui: executor = SSHExecutor(cli_args.connection, cli_args.proxyjumps) filesystem_factory = PyFilesystemFactory(cli_args) app = Application(executor, filesystem_factory, ui) def on_cancel(*args: Any, **kwargs: Any) -> None: sys.exit(app.cancel()) signal.signal(signal.SIGINT, on_cancel) sys.exit(app.run(cli_args))
def test__given_connected_client__when_executing_command__should_execute_command(sshclient_class): sshclient_instance = sshclient_class.return_value sshclient_instance.exec_command.return_value = (Mock(), Mock(), Mock()) sut = SSHExecutor(connection_data()) sut.connect() sut.exec_command("dummycmd") sshclient_instance.exec_command.assert_called_with("dummycmd")
def test__given_connected_client__when_disconnecting__should_disconnect(sshclient_class): sshclient_instance = sshclient_class.return_value sut = SSHExecutor(connection_data()) sut.connect() sut.close() sshclient_instance.close.assert_called() assert not sut.is_connected
def make_sut(options, ui=None): executor = SSHExecutor(options.connection, options.proxyjumps) return Application(executor, DummyFilesystemFactory(), ui or Mock())
def test__given_connected_client__is_connected__should_be_true(sshclient_class): sut = SSHExecutor(connection_data()) sut.connect() assert sut.is_connected
def test__given_new_client__is_connected__should_be_false(sshclient_class): sut = SSHExecutor(connection_data()) assert not sut.is_connected