本文整理匯總了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)