Esempio n. 1
0
    def open(self) -> None:
        self._pre_open_closing_log(closing=False)

        self.session = PtyProcess.spawn(
            self.open_cmd,
            rows=self._base_transport_args.transport_options.get("ptyprocess", {}).get("rows", 24),
            cols=self._base_transport_args.transport_options.get("ptyprocess", {}).get("cols", 80),
        )

        self._post_open_closing_log(closing=False)
Esempio n. 2
0
def test_isalive(fs, system_transport):
    # lie and pretend the session is already assigned
    # giving ptyprocess a "real" (but not like... real real) fd seemed like a good idea... dunno
    # if its really necessary, but it *does* need a fd of some sort so whatever; also give it a
    # forked pid so that the isalive method works... obviously this is sorta cheating to force it
    # to work but we really only care that scrapli does the right thing... we have faith that
    # ptyprocess will be doing the right thing "below" scrapli
    dummy_pid, fd = pty.fork()
    fs.create_file("dummy")
    dummy_file = open("dummy")
    system_transport.session = PtyProcess(pid=dummy_pid, fd=dummy_file.fileno())
    assert system_transport.isalive() is True
Esempio n. 3
0
def test_close(fs, monkeypatch, system_transport):
    def _close(cls):
        pass

    monkeypatch.setattr(
        "scrapli.transport.plugins.system.ptyprocess.PtyProcess.close",
        _close,
    )

    # giving ptyprocess a "real" (but not like... real real) fd seemed like a good idea... dunno
    # if its really necessary, but it *does* need a fd of some sort so whatever
    fs.create_file("dummy")
    dummy_file = open("dummy")
    system_transport.session = PtyProcess(pid=0, fd=dummy_file.fileno())
    system_transport.close()

    assert system_transport.session is None
Esempio n. 4
0
    def open(self) -> None:
        self._pre_open_closing_log(closing=False)

        if not self.open_cmd:
            self._build_open_cmd()

        self.session = PtyProcess.spawn(
            self.open_cmd,
            echo=self._base_transport_args.transport_options.get(
                "ptyprocess", {}).get("echo", True),
            rows=self._base_transport_args.transport_options.get(
                "ptyprocess", {}).get("rows", 80),
            cols=self._base_transport_args.transport_options.get(
                "ptyprocess", {}).get("cols", 256),
        )

        self._post_open_closing_log(closing=False)
Esempio n. 5
0
def test_read_exception_eof(fs, monkeypatch, system_transport):
    def _read(cls, _):
        raise EOFError

    monkeypatch.setattr(
        "scrapli.transport.plugins.system.ptyprocess.PtyProcess.read",
        _read,
    )

    # lie and pretend the session is already assigned
    # giving ptyprocess a "real" (but not like... real real) fd seemed like a good idea... dunno
    # if its really necessary, but it *does* need a fd of some sort so whatever
    fs.create_file("dummy")
    dummy_file = open("dummy")
    system_transport.session = PtyProcess(pid=0, fd=dummy_file.fileno())

    with pytest.raises(ScrapliConnectionError):
        system_transport.read()
Esempio n. 6
0
def test_read(fs, monkeypatch, system_transport):
    def _read(cls, _):
        return b"somebytes"

    monkeypatch.setattr(
        "scrapli.transport.plugins.system.ptyprocess.PtyProcess.read",
        _read,
    )

    # lie and pretend the session is already assigned
    # giving ptyprocess a "real" (but not like... real real) fd seemed like a good idea... dunno
    # if its really necessary, but it *does* need a fd of some sort so whatever
    dummy_pid, fd = pty.fork()
    fs.create_file("dummy")
    dummy_file = open("dummy")
    system_transport.session = PtyProcess(pid=dummy_pid, fd=dummy_file.fileno())

    assert system_transport.read() == b"somebytes"