def test_ticks_without_messages(self, printer: StreamPrinter,
                                 capfd: Any) -> None:
     printer.tick()
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == f".{linesep}"
 def test_two_messages(self, printer: StreamPrinter, capfd: Any) -> None:
     printer.print("message1")
     printer.print("message2")
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == f"message1{linesep}message2{linesep}"
 def test_ticks_spam_control(self, printer: StreamPrinter, capfd: Any,
                             monkeypatch: Any) -> None:
     monkeypatch.setattr("neuromation.cli.printer.TICK_TIMEOUT", 1000)
     printer.tick()
     printer.tick()
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == f".{linesep}"
Exemplo n.º 4
0
class StreamExecStopProgress(ExecStopProgress):
    def __init__(self) -> None:
        super().__init__()
        self._printer = StreamPrinter()
        self._printer.print("Wait for stopping")

    def tick(self, running: bool) -> None:
        self._printer.tick()

    def timeout(self) -> None:
        print()
        print("Warning !!!")
        print("The attached session was disconnected "
              "but the exec process is still alive.")
Exemplo n.º 5
0
class StreamJobStartProgress(JobStartProgress):
    def __init__(self) -> None:
        self._printer = StreamPrinter()
        self._prev = ""

    def begin(self, job: JobDescription) -> None:
        self._printer.print(f"Job ID: {job.id}")
        if job.name:
            self._printer.print(f"Name: {job.name}")

    def step(self, job: JobDescription) -> None:
        msg = f"Status: {job.status}"
        reason = self._get_status_reason_message(job)
        if reason:
            msg += " " + reason
        description = self._get_status_description_message(job)
        if description:
            msg += " " + description

        if job.status != JobStatus.PENDING:
            msg += "\n"

        if msg != self._prev:
            self._printer.print(msg)
            self._prev = msg
        else:
            self._printer.tick()

    def end(self, job: JobDescription) -> None:
        pass
 def test_ticks_with_messages(self, printer: StreamPrinter, capfd: Any,
                              monkeypatch: Any) -> None:
     monkeypatch.setattr("neuromation.cli.printer.TICK_TIMEOUT", 0)
     printer.tick()
     printer.print("message")
     printer.tick()
     printer.tick()
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == f".{linesep}message..{linesep}"
Exemplo n.º 7
0
class StreamJobStartProgress(JobStartProgress):
    def __init__(self) -> None:
        self._printer = StreamPrinter()
        self._prev = ""

    def __call__(self, job: JobDescription) -> None:
        msg = f"Status: {job.status}"
        reason = self._get_status_reason_message(job)
        if reason:
            msg += " " + reason
        description = self._get_status_description_message(job)
        if description:
            msg += " " + description

        if msg != self._prev:
            self._printer.print(msg)
            self._prev = msg
        else:
            self._printer.tick()
Exemplo n.º 8
0
class StreamDockerImageProgress(DockerImageProgress):
    def __init__(self) -> None:
        self._printer = StreamPrinter()

    def push(self, data: ImageProgressPush) -> None:
        self._printer.print(f"Using local image '{data.src}'")
        self._printer.print(f"Using remote image '{data.dst}'")
        self._printer.print("Pushing image...")

    def pull(self, data: ImageProgressPull) -> None:
        self._printer.print(f"Using remote image '{data.src}'")
        self._printer.print(f"Using local image '{data.dst}'")
        self._printer.print("Pulling image...")

    def step(self, data: ImageProgressStep) -> None:
        if data.layer_id:
            self._printer.tick()
        else:
            self._printer.print(data.message)

    def save(self, data: ImageProgressSave) -> None:
        self._printer.print(
            f"Saving job '{data.job}' to image '{data.dst}'...")

    def commit_started(self, data: ImageCommitStarted) -> None:
        self._printer.print(f"Using remote image '{data.target_image}'")
        self._printer.print(f"Creating image from the job container...")

    def commit_finished(self, data: ImageCommitFinished) -> None:
        self._printer.print("Image created")

    def close(self) -> None:
        self._printer.close()
Exemplo n.º 9
0
 def __init__(self) -> None:
     super().__init__()
     self._printer = StreamPrinter()
     self._printer.print("Wait for stopping")
Exemplo n.º 10
0
class StreamJobStopProgress(JobStopProgress):
    def __init__(self) -> None:
        super().__init__()
        self._printer = StreamPrinter()
        self._printer.print("Wait for stopping")

    def detach(self, job: JobDescription) -> None:
        pass

    def kill(self, job: JobDescription) -> None:
        self._printer.print("Job was killed")

    def tick(self, job: JobDescription) -> None:
        self._printer.tick()

    def timeout(self, job: JobDescription) -> None:
        self._printer.print("")
        self._printer.print("Warning !!!")
        self._printer.print(
            "The attached session was disconnected but the job is still alive."
        )
Exemplo n.º 11
0
 def test_one_message(self, printer: StreamPrinter, capfd: Any) -> None:
     printer.print("message")
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == f"message{linesep}"
Exemplo n.º 12
0
 def test_no_messages(self, printer: StreamPrinter, capfd: Any) -> None:
     printer.close()
     out, err = capfd.readouterr()
     assert err == ""
     assert out == ""
Exemplo n.º 13
0
 def printer(self) -> StreamPrinter:
     return StreamPrinter()