jedcunningham commented on a change in pull request #17236:
URL: https://github.com/apache/airflow/pull/17236#discussion_r685322736
##########
File path: tests/providers/ssh/hooks/test_ssh.py
##########
@@ -475,6 +504,122 @@ def
test_ssh_connection_with_no_host_key_where_no_host_key_check_is_false(self,
assert ssh_client.return_value.connect.called is True
assert
ssh_client.return_value.get_host_keys.return_value.add.called is False
+ @mock.patch('airflow.providers.ssh.hooks.ssh.paramiko.SSHClient')
+ def test_ssh_connection_with_conn_timeout(self, ssh_mock):
+ hook = SSHHook(
+ remote_host='remote_host',
+ port='port',
+ username='username',
+ password='password',
+ conn_timeout=20,
+ key_file='fake.file',
+ )
+
+ with hook.get_conn():
+ ssh_mock.return_value.connect.assert_called_once_with(
+ hostname='remote_host',
+ username='username',
+ password='password',
+ key_filename='fake.file',
+ timeout=20,
+ compress=True,
+ port='port',
+ sock=None,
+ look_for_keys=True,
+ )
+
+ @mock.patch('airflow.providers.ssh.hooks.ssh.paramiko.SSHClient')
+ def test_ssh_connection_with_conn_timeout_and_timeout(self, ssh_mock):
+ hook = SSHHook(
+ remote_host='remote_host',
+ port='port',
+ username='username',
+ password='password',
+ timeout=10,
+ conn_timeout=20,
+ key_file='fake.file',
+ )
+
+ with hook.get_conn():
+ ssh_mock.return_value.connect.assert_called_once_with(
+ hostname='remote_host',
+ username='username',
+ password='password',
+ key_filename='fake.file',
+ timeout=20,
+ compress=True,
+ port='port',
+ sock=None,
+ look_for_keys=True,
+ )
+
+ @mock.patch('airflow.providers.ssh.hooks.ssh.paramiko.SSHClient')
+ def test_ssh_connection_with_timeout_extra(self, ssh_mock):
+ hook = SSHHook(
+ ssh_conn_id=self.CONN_SSH_WITH_TIMEOUT_EXTRA,
+ remote_host='remote_host',
+ port='port',
+ username='username',
+ timeout=10,
+ )
+
+ with hook.get_conn():
+ ssh_mock.return_value.connect.assert_called_once_with(
+ hostname='remote_host',
+ username='username',
+ timeout=20,
+ compress=True,
+ port='port',
+ sock=None,
+ look_for_keys=True,
+ )
+
+ @mock.patch('airflow.providers.ssh.hooks.ssh.paramiko.SSHClient')
+ def test_ssh_connection_with_conn_timeout_extra(self, ssh_mock):
+ hook = SSHHook(
+ ssh_conn_id=self.CONN_SSH_WITH_CONN_TIMEOUT_EXTRA,
+ remote_host='remote_host',
+ port='port',
+ username='username',
+ timeout=10,
+ conn_timeout=15,
+ )
+
+ # conn_timeout parameter wins over extra options
+ with hook.get_conn():
+ ssh_mock.return_value.connect.assert_called_once_with(
+ hostname='remote_host',
+ username='username',
+ timeout=15,
+ compress=True,
+ port='port',
+ sock=None,
+ look_for_keys=True,
+ )
+
+ @mock.patch('airflow.providers.ssh.hooks.ssh.paramiko.SSHClient')
+ def test_ssh_connection_with_timeout_extra_and_conn_timeout_extra(self,
ssh_mock):
+ hook = SSHHook(
+ ssh_conn_id=self.CONN_SSH_WITH_TIMEOUT_AND_CONN_TIMEOUT_EXTRA,
+ remote_host='remote_host',
+ port='port',
+ username='username',
+ timeout=10,
+ conn_timeout=15,
+ )
+
+ # conn_timeout parameter wins over extra options
+ with hook.get_conn():
+ ssh_mock.return_value.connect.assert_called_once_with(
+ hostname='remote_host',
+ username='username',
+ timeout=15,
+ compress=True,
+ port='port',
+ sock=None,
+ look_for_keys=True,
+ )
Review comment:
Cool, sounds good 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]