當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。