Skip to content

Commit

Permalink
fix(cli): fix setting cpu request in renku.ini for renku session start (
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Dec 7, 2022
1 parent 7a718ab commit f367cc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion renku/core/errors.py
Expand Up @@ -627,7 +627,11 @@ def __init__(self, reason: str):
super().__init__(f"Docker failed: {reason}")


class RenkulabSessionError(RenkuException):
class SessionStartError(RenkuException):
"""Raised when an error occurs trying to start sessions."""


class RenkulabSessionError(SessionStartError):
"""Raised when an error occurs trying to start sessions with the notebook service."""


Expand Down
7 changes: 7 additions & 0 deletions renku/core/session/session.py
Expand Up @@ -103,6 +103,13 @@ def session_start(

# set resource settings
cpu_limit = cpu_request or get_value("interactive", "cpu_request")

if cpu_limit is not None:
try:
cpu_limit = float(cpu_limit)
except ValueError:
raise errors.SessionStartError(f"Invalid value for cpu_request (must be float): {cpu_limit}")

disk_limit = disk_request or get_value("interactive", "disk_request")
mem_limit = mem_request or get_value("interactive", "mem_request")
gpu = gpu_request or get_value("interactive", "gpu_request")
Expand Down
18 changes: 18 additions & 0 deletions tests/cli/test_session.py
Expand Up @@ -63,3 +63,21 @@ def test_session_up_down(runner, project, dummy_session_provider, monkeypatch):
result = runner.invoke(cli, ["session", "ls", "-p", "dummy"])
assert 0 == result.exit_code, format_result_exception(result)
assert 2 == len(result.output.splitlines())


def test_session_start_config_requests(runner, project, dummy_session_provider, monkeypatch):
"""Test session with configuration in the renku config."""
import docker

result = runner.invoke(cli, ["config", "set", "interactive.cpu_request", "0.5"])
assert 0 == result.exit_code, format_result_exception(result)
result = runner.invoke(cli, ["config", "set", "interactive.disk_request", "100mb"])
assert 0 == result.exit_code, format_result_exception(result)
result = runner.invoke(cli, ["config", "set", "interactive.mem_request", "100mb"])
assert 0 == result.exit_code, format_result_exception(result)

with monkeypatch.context() as monkey:
monkey.setattr(docker, "from_env", MagicMock())
result = runner.invoke(cli, ["session", "start", "-p", "docker"])
assert 0 == result.exit_code, format_result_exception(result)
assert "successfully started" in result.output

0 comments on commit f367cc7

Please sign in to comment.