當前位置: 首頁>>代碼示例>>Python>>正文


Python ParamikoSSHClient.close方法代碼示例

本文整理匯總了Python中st2common.runners.paramiko_ssh.ParamikoSSHClient.close方法的典型用法代碼示例。如果您正苦於以下問題:Python ParamikoSSHClient.close方法的具體用法?Python ParamikoSSHClient.close怎麽用?Python ParamikoSSHClient.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在st2common.runners.paramiko_ssh.ParamikoSSHClient的用法示例。


在下文中一共展示了ParamikoSSHClient.close方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_sftp_connection_is_only_established_if_required

# 需要導入模塊: from st2common.runners.paramiko_ssh import ParamikoSSHClient [as 別名]
# 或者: from st2common.runners.paramiko_ssh.ParamikoSSHClient import close [as 別名]
    def test_sftp_connection_is_only_established_if_required(self):
        # Verify that SFTP connection is lazily established only if and when needed.
        conn_params = {'hostname': 'dummy.host.org',
                       'username': 'ubuntu'}

        # Verify sftp connection and client hasn't been established yet
        client = ParamikoSSHClient(**conn_params)
        client.connect()

        self.assertTrue(client.sftp_client is None)

        # run method doesn't require sftp access so it shouldn't establish connection
        client = ParamikoSSHClient(**conn_params)
        client.connect()
        client.run(cmd='whoami')

        self.assertTrue(client.sftp_client is None)

        # Methods bellow require SFTP access so they should cause SFTP connection to be established
        # put
        client = ParamikoSSHClient(**conn_params)
        client.connect()
        path = '/root/random_script.sh'
        client.put(path, path, mirror_local_mode=False)

        self.assertTrue(client.sftp_client is not None)

        # exists
        client = ParamikoSSHClient(**conn_params)
        client.connect()
        client.exists('/root/somepath.txt')

        self.assertTrue(client.sftp_client is not None)

        # mkdir
        client = ParamikoSSHClient(**conn_params)
        client.connect()
        client.mkdir('/root/somedirfoo')

        self.assertTrue(client.sftp_client is not None)

        # Verify close doesn't throw if SFTP connection is not established
        client = ParamikoSSHClient(**conn_params)
        client.connect()

        self.assertTrue(client.sftp_client is None)
        client.close()

        # Verify SFTP connection is closed if it's opened
        client = ParamikoSSHClient(**conn_params)
        client.connect()
        client.mkdir('/root/somedirfoo')

        self.assertTrue(client.sftp_client is not None)
        client.close()

        self.assertEqual(client.sftp_client.close.call_count, 1)
開發者ID:LindsayHill,項目名稱:st2,代碼行數:59,代碼來源:test_paramiko_ssh.py


注:本文中的st2common.runners.paramiko_ssh.ParamikoSSHClient.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。