示例#1
0
async def echo(stdin, stdout, stderr=None):
    """Echo data from stdin back to stdout and stderr (if open)"""

    try:
        while not stdin.at_eof():
            data = await stdin.read(65536)

            if data:
                stdout.write(data)

                if stderr:
                    stderr.write(data)

        await stdout.drain()

        if stderr:
            await stderr.drain()

        stdout.write_eof()
    except SignalReceived as exc:
        if exc.signal == 'ABRT':
            raise ConnectionLost('Abort')
        else:
            stdin.channel.exit_with_signal(exc.signal)
    except OSError:
        pass

    stdout.close()
示例#2
0
文件: test_ssh.py 项目: sunzz679/ceph
    def test_offline(self, check_execute_command, execute_command,
                     cephadm_module):
        check_execute_command.return_value = ''
        execute_command.return_value = '', '', 0

        if not AsyncMock:
            # can't run this test if we could not import AsyncMock
            return
        mock_connect = AsyncMock(return_value='')
        with mock.patch("asyncssh.connect",
                        new=mock_connect) as asyncssh_connect:
            with with_host(cephadm_module, 'test'):
                asyncssh_connect.side_effect = ConnectionLost('reason')
                code, out, err = cephadm_module.check_host('test')
                assert out == ''
                assert "Host 'test' not found" in err

                out = wait(cephadm_module,
                           cephadm_module.get_hosts())[0].to_json()
                assert out == HostSpec('test', '1::4',
                                       status='Offline').to_json()

                asyncssh_connect.return_value = mock.MagicMock()
                asyncssh_connect.side_effect = None
                assert CephadmServe(cephadm_module)._check_host('test') is None
                out = wait(cephadm_module,
                           cephadm_module.get_hosts())[0].to_json()
                assert out == HostSpec('test', '1::4').to_json()