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


Python PlayContext.password方法代码示例

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


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

示例1: test_plugins_connection_ssh__run

# 需要导入模块: from ansible.playbook.play_context import PlayContext [as 别名]
# 或者: from ansible.playbook.play_context.PlayContext import password [as 别名]
    def test_plugins_connection_ssh__run(self, mock_Popen, mock_openpty, mock_osclose, mock_oswrite, mock_fcntl, mock_select):
        pc = PlayContext()
        new_stdin = StringIO()

        conn = ssh.Connection(pc, new_stdin)
        conn._send_initial_data = MagicMock()
        conn._examine_output = MagicMock()
        conn._terminate_process = MagicMock()
        conn.sshpass_pipe = [MagicMock(), MagicMock()]

        mock_popen_res = MagicMock()
        mock_popen_res.poll   = MagicMock()
        mock_popen_res.wait   = MagicMock()
        mock_popen_res.stdin  = MagicMock()
        mock_popen_res.stdin.fileno.return_value = 1000
        mock_popen_res.stdout = MagicMock()
        mock_popen_res.stdout.fileno.return_value = 1001
        mock_popen_res.stderr = MagicMock()
        mock_popen_res.stderr.fileno.return_value = 1002
        mock_popen_res.return_code = 0
        mock_Popen.return_value = mock_popen_res

        def _mock_select(rlist, wlist, elist, timeout=None):
            rvals = []
            if mock_popen_res.stdin in rlist:
                rvals.append(mock_popen_res.stdin)
            if mock_popen_res.stderr in rlist:
                rvals.append(mock_popen_res.stderr)
            return (rvals, [], [])

        mock_select.side_effect = _mock_select

        mock_popen_res.stdout.read.side_effect = [b"some data", b""]
        mock_popen_res.stderr.read.side_effect = [b""]
        conn._run("ssh", "this is input data")

        # test with a password set to trigger the sshpass write
        pc.password = '12345'
        mock_popen_res.stdout.read.side_effect = [b"some data", b"", b""]
        mock_popen_res.stderr.read.side_effect = [b""]
        conn._run(["ssh", "is", "a", "cmd"], "this is more data")

        # test with password prompting enabled
        pc.password = None
        pc.prompt = True
        mock_popen_res.stdout.read.side_effect = [b"some data", b"", b""]
        mock_popen_res.stderr.read.side_effect = [b""]
        conn._run("ssh", "this is input data")

        # test with some become settings
        pc.prompt = False
        pc.become = True
        pc.success_key = 'BECOME-SUCCESS-abcdefg'
        mock_popen_res.stdout.read.side_effect = [b"some data", b"", b""]
        mock_popen_res.stderr.read.side_effect = [b""]
        conn._run("ssh", "this is input data")

        # simulate no data input
        mock_openpty.return_value = (98, 99)
        mock_popen_res.stdout.read.side_effect = [b"some data", b"", b""]
        mock_popen_res.stderr.read.side_effect = [b""]
        conn._run("ssh", "")

        # simulate no data input but Popen using new pty's fails
        mock_Popen.return_value = None
        mock_Popen.side_effect = [OSError(), mock_popen_res]
        mock_popen_res.stdout.read.side_effect = [b"some data", b"", b""]
        mock_popen_res.stderr.read.side_effect = [b""]
        conn._run("ssh", "")
开发者ID:2ndQuadrant,项目名称:ansible,代码行数:71,代码来源:test_ssh.py


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