本文整理汇总了Python中st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient.run方法的典型用法代码示例。如果您正苦于以下问题:Python ParamikoSSHClient.run方法的具体用法?Python ParamikoSSHClient.run怎么用?Python ParamikoSSHClient.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient
的用法示例。
在下文中一共展示了ParamikoSSHClient.run方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sftp_connection_is_only_established_if_required
# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import run [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)