本文整理汇总了Python中bladerunner.Bladerunner.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Bladerunner.connect方法的具体用法?Python Bladerunner.connect怎么用?Python Bladerunner.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bladerunner.Bladerunner
的用法示例。
在下文中一共展示了Bladerunner.connect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connect_from_jb_denied
# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import connect [as 别名]
def test_connect_from_jb_denied():
"""Ensure we look through the before text for 'Permission denied's."""
runner = Bladerunner({"jump_host": "mocked"})
runner.sshc = Mock()
runner.sshc.before.find = Mock(return_value=1)
with patch.object(base, "can_resolve", return_value=True):
with patch.object(runner, "send_interrupt") as p_interrupt:
ret = runner.connect("home", "self", "hunter22", 443)
if sys.version_info > (3,):
expected_call = bytes("Permission denied", "utf-8")
else:
expected_call = "Permission denied"
runner.sshc.before.find.assert_called_once_with(expected_call)
runner.sshc.sendline.assert_called_once_with("ssh -p 443 -t [email protected]")
runner.sshc.expect.assert_called_once_with(
runner.options["passwd_prompts"] +
runner.options["shell_prompts"] +
runner.options["extra_prompts"],
runner.options["timeout"],
)
p_interrupt.assert_called_once_with(runner.sshc)
assert ret == (None, -4)
示例2: test_connect_exception_guess
# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import connect [as 别名]
def test_connect_exception_guess(pexpect_exceptions):
"""If the pexpect object is alive on connect timeout, guess the prompt."""
runner = Bladerunner({"timeout": "fake"})
sshr = Mock()
sshr.expect = Mock(side_effect=pexpect_exceptions("not real"))
sshr.before = Mock(return_value="what")
sshr.isalive = Mock(return_value=True)
with patch.object(base, "can_resolve", return_value=True):
with patch.object(base.pexpect, "spawn", return_value=sshr) as p_spawn:
with patch.object(runner, "_try_for_unmatched_prompt") as p_guess:
runner.connect("fence", "tim", "hunter1", 4)
p_spawn.assert_called_once_with("ssh -p 4 -t [email protected]", timeout="fake")
p_guess.assert_called_once_with(sshr, sshr.before, "ssh -p 4 -t [email protected]",
_from_login=True)
示例3: test_connect_from_jumpbox
# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import connect [as 别名]
def test_connect_from_jumpbox():
"""Test the calls through connect for a succesful login from a jumpbox."""
runner = Bladerunner({"jump_host": "faked"})
runner.sshc = Mock()
runner.sshc.before.find = Mock(return_value=-1) # permission not denied
runner.sshc.expect = Mock(return_value="fake")
with patch.object(base, "can_resolve", return_value=True):
with patch.object(runner, "_multipass") as p_multipass:
runner.connect("where", "johnny", "hunter13", 43)
runner.sshc.sendline.assert_called_once_with("ssh -p 43 -t [email protected]")
runner.sshc.expect.assert_called_once_with(
runner.options["passwd_prompts"] +
runner.options["shell_prompts"] +
runner.options["extra_prompts"],
runner.options["timeout"],
)
p_multipass.assert_called_once_with(runner.sshc, "hunter13", "fake")
示例4: test_connect_new_connection
# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import connect [as 别名]
def test_connect_new_connection():
"""Ensure Bladerunner creates the initial pexpect object correctly."""
runner = Bladerunner({"debug": 2, "jump_host": "nowhere", "timeout": 14})
sshr = Mock()
sshr.expect = Mock(return_value="faked")
with patch.object(base, "can_resolve", return_value=True):
with patch.object(base.pexpect, "spawn", return_value=sshr) as p_spawn:
with patch.object(runner, "_multipass") as p_multipass:
runner.connect("nowhere", "bobby", "hunter44", 15)
p_spawn.assert_called_once_with("ssh -p 15 -t -vv [email protected]",
timeout=14)
p_multipass.assert_called_once_with(sshr, "hunter44", "faked")
sshr.expect.assert_called_once_with(
runner.options["passwd_prompts"] +
runner.options["shell_prompts"] +
runner.options["extra_prompts"],
runner.options["timeout"],
)
assert runner.sshc == sshr # could be used as a jumpbox in future connects
assert sshr.logfile_read == FakeStdOut # debug is set, logging to stdout
示例5: test_connect_from_jb_failures
# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import connect [as 别名]
def test_connect_from_jb_failures(pexpect_exceptions):
"""Test the pexpect excpetions are caught from inside a jumpbox."""
runner = Bladerunner({"jump_host": "notreal"})
runner.sshc = Mock()
runner.sshc.expect = Mock(side_effect=pexpect_exceptions("fake error"))
runner.sshc.before = Mock(return_value="things")
with patch.object(base, "can_resolve", return_value=True):
with patch.object(runner, "send_interrupt") as p_interrupt:
ret = runner.connect("place", "frank", "hunter63", 101)
runner.sshc.sendline.assert_called_once_with("ssh -p 101 -t [email protected]")
p_interrupt.assert_called_once_with(runner.sshc)
assert ret == (None, -1)
示例6: test_connect_new_exceptions
# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import connect [as 别名]
def test_connect_new_exceptions(pexpect_exceptions):
"""If TIMEOUT or EOF exceptions are raised, connect returns (None, -7)."""
runner = Bladerunner({"debug": 2, "jump_host": "nowhere"})
sshr = Mock()
sshr.expect = Mock(side_effect=pexpect_exceptions("faked"))
sshr.isalive = Mock(return_value=False)
with patch.object(base, "can_resolve", return_value=True):
with patch.object(base.pexpect, "spawn", return_value=sshr) as p_spawn:
res = runner.connect("nowhere", "noone", "hunter29", 99)
p_spawn.assert_called_once_with("ssh -p 99 -t -vv [email protected]",
timeout=20) # default timeout
assert res == (None, -7)
示例7: test_connect_no_resolve
# 需要导入模块: from bladerunner import Bladerunner [as 别名]
# 或者: from bladerunner.Bladerunner import connect [as 别名]
def test_connect_no_resolve():
"""If we can't resolve the host connect should return immediately."""
runner = Bladerunner()
with patch.object(base, "can_resolve", return_value=False):
assert runner.connect("nowhere", "bob", "hunter2", 22) == (None, -3)