当前位置: 首页>>代码示例>>Python>>正文


Python SSHHook.create_tunnel方法代码示例

本文整理汇总了Python中airflow.contrib.hooks.ssh_hook.SSHHook.create_tunnel方法的典型用法代码示例。如果您正苦于以下问题:Python SSHHook.create_tunnel方法的具体用法?Python SSHHook.create_tunnel怎么用?Python SSHHook.create_tunnel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在airflow.contrib.hooks.ssh_hook.SSHHook的用法示例。


在下文中一共展示了SSHHook.create_tunnel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SSHHookTest

# 需要导入模块: from airflow.contrib.hooks.ssh_hook import SSHHook [as 别名]
# 或者: from airflow.contrib.hooks.ssh_hook.SSHHook import create_tunnel [as 别名]
class SSHHookTest(unittest.TestCase):
    def setUp(self):
        configuration.load_test_config()
        from airflow.contrib.hooks.ssh_hook import SSHHook
        self.hook = SSHHook(ssh_conn_id='ssh_default', keepalive_interval=10)
        self.hook.no_host_key_check = True

    def test_ssh_connection(self):
        ssh_hook = self.hook.get_conn()
        self.assertIsNotNone(ssh_hook)

    def test_tunnel(self):
        print("Setting up remote listener")
        import subprocess
        import socket

        self.server_handle = subprocess.Popen(["python", "-c", HELLO_SERVER_CMD],
                                              stdout=subprocess.PIPE)
        print("Setting up tunnel")
        with self.hook.create_tunnel(2135, 2134):
            print("Tunnel up")
            server_output = self.server_handle.stdout.read(5)
            self.assertEqual(server_output, b"ready")
            print("Connecting to server via tunnel")
            s = socket.socket()
            s.connect(("localhost", 2135))
            print("Receiving...", )
            response = s.recv(5)
            self.assertEqual(response, b"hello")
            print("Closing connection")
            s.close()
            print("Waiting for listener...")
            output, _ = self.server_handle.communicate()
            self.assertEqual(self.server_handle.returncode, 0)
            print("Closing tunnel")
开发者ID:7digital,项目名称:incubator-airflow,代码行数:37,代码来源:test_ssh_hook.py

示例2: test_tunnel

# 需要导入模块: from airflow.contrib.hooks.ssh_hook import SSHHook [as 别名]
# 或者: from airflow.contrib.hooks.ssh_hook.SSHHook import create_tunnel [as 别名]
    def test_tunnel(self):
        hook = SSHHook(ssh_conn_id='ssh_default')

        import subprocess
        import socket

        server_handle = subprocess.Popen(["python", "-c", HELLO_SERVER_CMD],
                                         stdout=subprocess.PIPE)
        with hook.create_tunnel(2135, 2134):
            server_output = server_handle.stdout.read(5)
            self.assertEqual(server_output, b"ready")
            s = socket.socket()
            s.connect(("localhost", 2135))
            response = s.recv(5)
            self.assertEqual(response, b"hello")
            s.close()
            output, _ = server_handle.communicate()
            self.assertEqual(server_handle.returncode, 0)
开发者ID:Fokko,项目名称:incubator-airflow,代码行数:20,代码来源:test_ssh_hook.py


注:本文中的airflow.contrib.hooks.ssh_hook.SSHHook.create_tunnel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。